On 17-Jan-07, at 8:36 AM, chromatic wrote:
> Note also that:
>
> 1) can() returns a subroutine reference. Don't break
that.
>
> 2) can() is a method. Methods aren't functions. If
you call a
> method as a
> function, you've introduced unreliability into
everyone's code
> again, and of
> course things will break.
A good implementation of AUTOLOAD where you've implemented
->can()
right might be this (subject to the implementations returned
from -
>can() not changing based on object state):
sub AUTOLOAD {
my $method = $AUTOLOAD;
$method =~ s/.*:://;
my $implementation = $_[0]->can($method)
|| croak "Can't locate method
"$method" via thing $_[0]";
no strict 'refs';
*{$AUTOLOAD} = $implementation;
goto &$AUTOLOAD;
}
Don't forget to do something about DESTROY though. It always
bothered
me that there wasn't an empty UNIVERSAL: ESTROY -
why should an
unimplemented DESTROY drop into AUTOLOAD?
____________________________________________________________
__________
This email has been scanned by the MessageLabs Email
Security System.
For more information please visit http://www.messagela
bs.com/email
____________________________________________________________
__________
|