This is generally true, but there is an example in
Conway's book where he uses AUTOLOAD for accessor methods, but creates a new method on the fly, so that AUTOLOAD is only called the first time that a particular method is used.
The code looks like this (note use of no strict to allow symbolic references in a strictly (no pun intended) controlled manner.)
Should probably point out that this isn't actually Damien Conway's code, but a slightly changed version that I hacked up.
sub AUTOLOAD {
no strict 'refs';
my ($self, $val) = @_;
my ($name) = $AUTOLOAD =~ m/.*::(\w*)/;
*{$AUTOLOAD} = sub { return @_ > 1 ?
$_[0]->{$name} = $_[1] :
$_[0]->{$name}};
return defined $val ? $self->{$name} = $val : $self->{$name};
}
--
<http://www.dave.org.uk>
European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/> |