in reply to Re: name of executing sub?
in thread name of executing sub?
This is why I think that the best way of implementing AUTOLOAD is something like this:
use Sub::Name; sub AUTOLOAD { my ($name) = (our $AUTOLOAD =~ /(\w+)$/); my $func = subname $name => sub { ...; # this is where the work happens }; no strict 'refs'; *$name = $func; goto $func; }
What this means is that the first time an autoloaded function is called, AUTOLOAD creates the function as a coderef, and then installs that into the symbol table, so that the next time the same named function is called, no AUTOLOAD needs to happen.
And it fixes caller, and stuff that relies on caller like Carp::confess.
|
|---|