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

Re: AUTLOAD and $_

Thread Previous | Thread Next
From:
Adam Kennedy
Date:
June 21, 2005 04:13
Subject:
Re: AUTLOAD and $_
Message ID:
20050621021106.26593.qmail@lists.develooper.com
  > 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
>     }

You are of course assuming that every use of AUTOLOAD, for all time, 
will result in

a) Calling another function
b) An error

Wouldn't this lead to hacks where people do things like this just to 
prevent perl thinking it's a failure?

sub AUTOLOAD ($whatever) {  # but no *@_
      my $s = get_subref_for $whatever;
      our &::($whatever) := $s;
      return sub () { 1 };
}

The ability to get complete control over the params and context of the 
function, and maybe run something else AFTER the function call is important.

So I suspect there might be some false economy in this optimisation.

Adam K

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About