in reply to RE: autoload and selfload
in thread autoload and selfload
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}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: autoload and selfload
by perlmonkey (Hermit) on Jul 11, 2000 at 23:20 UTC |