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

Re: AUTLOAD and $_

Thread Previous | Thread Next
From:
Sam Vilain
Date:
June 20, 2005 14:42
Subject:
Re: AUTLOAD and $_
Message ID:
42B7382F.4020501@vilain.net
Juerd wrote:
> 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 ($w) { return our &::($w) := get_subref_for $w }

I like that.  Makes it more consistent with the AUTOSCALAR, etc methods -
returning a reference to the result (variable ref/code ref/sub name) rather
than the actual result (variable value/calling the sub).

After all, presumably the compiler might sometimes call the AUTOLOAD at
compile time; to get its signature.  So, for instance, you could AUTOLOAD
all the methods you optionally export, which are all pulled in at once when
a module imports a function and tries to use it in some code (as the
signature will need to be checked then).  I was going to bring that up
next, but I think this has already answered it.

Sam.

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