Re: AUTLOAD and $_
by Juerd other posts by this author
Jun 20 2005 3:12AM messages near this date
AUTLOAD and $_
|
Re: AUTLOAD and $_
Sam Vilain skribis 2005-06-20 12:54 (+1200):
> sub AUTOLOAD($_ = $CALLER::$_, *@_) {
> In a way, $_ forms part of the prototype definition, but is "out of band"
> to the regular arguments on @_; it can't interfere with positional
> characteristics, or you have to "shift" it off before you goto the right
> sub.
(...)
> Perhaps to avoid that mess, the AUTOLOAD function is simply expected to
> call &func.goto if it wants all the effects of the presence of the
> AUTOLOAD sub to go away. Assuming that the prototype is re-checked on a
> goto, to ensure that type guarantees specified in the function signature
> are honoured, then the necessary side effects should just happen.
I think there exists an even simpler way to avoid any mess involved.
Instead of letting AUTOLOAD receive and pass on arguments, and instead
of letting AUTOLOAD call the loaded sub, why not have AUTOLOAD do its
thing, and then have *perl* call the sub?
sub AUTOLOAD ($whatever) { # but no *@_
my $s = get_subref_for $whatever;
our &::($whatever) := $s;
return $s; # non-subref indicates failure
}
If you want to load it again each time, remove the := line.
The line can be shortened to
sub AUTOLOAD ($w) { return our &::($w) = get_subref_for $w }
or just
sub AUTOLOAD { our &::($^a) = get_subref_for $^a }
Re arguments: I think a single positional argument makes more sense than
requiring that its name be $_.
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
Thread:
Sam Vilain
Juerd
Sam Vilain
Maxim Sloyko
Juerd
Adam Kennedy
Juerd
Luke Palmer
Chromatic
Juerd
Chromatic
Juerd
Luke Palmer
John Macdonald
Chromatic
Juerd
Rod Adams
Larry Wall
Rod Adams
Chromatic
Juerd
Sam Vilain
Sam Vilain
Juerd
|