develooper Front page | perl.perl5.porters | Postings from December 2010

Re: Make $obj->$method honours "&{}" overloading on $method

Thread Previous | Thread Next
Zsbán Ambrus
December 8, 2010 01:48
Re: Make $obj->$method honours "&{}" overloading on $method
Message ID:
On Wed, Dec 8, 2010 at 12:59 AM, Vincent Pit <> wrote:
> I'm sure you're already aware that the
>   $obj->$method(@args)
> syntax already has two meanings, depending on whether $method is a code
> reference or something else (which then gets stringified, either through
> stringification overloading or the usual way).

It has three modes in fact: code reference, unqualified method name as
string, and qualified name (which is looked up using inheritence
starting from the package name in the string, with the package of the
object ignored).

perl -we '{ package X; @X::ISA = "Y"; } { package Y; sub japh { print
{ $_[0] } "Judt another Perl hacker\n"; } } $m = "X::japh";

> Also, if you want to define local methods and you can only use method
> names, you have to install your methods into the object's class, because
> methods are subs and subs are global. The code reference calling mode
> allows you to define such local methods but in a lexical way. I still
> think it's a big win.

You can also use the third mode to have local methods, so this does
not alone prove that the code reference is a big win.


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