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

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

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
December 5, 2010 17:13
Subject:
Re: Make $obj->$method honours "&{}" overloading on $method
Message ID:
26F24527-5F75-44D7-B8D9-523D3F1D84E8@cpan.org
Vincent Pit wrote:
> The attached patch makes "Package->$method" and "$obj->$method" call
> "&{}" overloading on $method whenever present.
> In that case, it is equivalent to "Package->$ret" and "$obj->$ret",
> where $ret is the value returned from the overloading callback ; except
> when $ret is a scalar reference, in which case $$ret is used as the
> method name.

Why the special case for scalar references?

I would expect ‘$bar = \$_; $foo->$bar’ to do this (which it does currently):
Can't call method "SCALAR(0x826d70)" on an undefined value at -e line 1.

If $_ is blessed into a class, then string overloading will kick in:

$ perl5.10.1 -e 'bless \$_; use overload q\""\=>sub{"aaaa"};$bar = \$_; $foo->$bar'
Can't call method "aaaa" on an undefined value at -e line 1.

The &{} overloading sounds fine to me, as it’s a bug fix as far as I’m concerned.


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