in reply to Re: Strange code execution with 'AUTOLOAD'
in thread Strange code execution with 'AUTOLOAD'
Another option is to set your autoload like this:
Notice how it returns if this is a call to destroy? AUTOLOAD will never be called if there is a DESTROY method. I imagine sub DESTROY {} is faster, but the logic seems easier to maintain and less people will be asking "Why does my autoload work in this class and not that one?"sub AUTOLOAD { my ($self) = @_; # don't do any work if we are being called for DESTROY next if(substr($AUTOLOAD, -7) eq 'DESTROY'); $AUTOLOAD =~ /.*::get(_\w+)/ or die "No such method: $AUTOLOAD"; exists $self->{$1} or die "No such attribute: $1"; return $self->{$1} }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Strange code execution with 'AUTOLOAD'
by btrott (Parson) on Jul 02, 2001 at 04:38 UTC |
In Section
Seekers of Perl Wisdom