develooper Front page | perl.perl6.language | Postings from June 2005

AUTLOAD and $_

Thread Next
Sam Vilain
June 19, 2005 21:21
AUTLOAD and $_
Message ID:
 From S10;

   In any case, there is no longer any magical $AUTOLOAD variable. The
   name being declared or defined can be found in $_ instead. The name
   does not include the package name. You can always get your own package
   name with $?PACKAGENAME.

So, what is the prototype of AUTOLOAD?  It is clearly called from the
relevant (package dispatcher & type & perl5_compat(stash) ) object, but

  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

OK, we could play tricks with localization of variables, but in the face
of continuations and coroutines, localization falls apart.  This is fine
for people writing `ordinary┬┤ code (perhaps), but for a core language
feature it should be resolved IMHO.

Out-of-band arguments seem to have been a hot topic in the past; - Long (50+ posts) thread - suggestion from Damian;

      $foo = sub { print $_ } is given($_);

I actually quite like that syntax, or at least the idea of using a trait
of some kind to specify non-positional arguments.  It keeps them well
out of the way of `safe┬┤ programming conventions :).

In fact, it has to do wierder things than just accept it out of band to
parameters - ideally it would not also interfere with another sub that
uses $CALLER::_.

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.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About