http://qs1969.pair.com?node_id=93056


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:
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} }
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?"