There's another strange case: doing an indirect method call with the
method name being a glob.

It appears that in this case perl uses the qualified name of the glob
and handles it like a string, that is, searching the method in the
superclasses starting from the package part of the string. (That is,
the glob is just stringified, and the splat character is ignored just
like it would be with normal strings.)

This doesn't seem right to me, I think it would be better if perl
dereferenced the glob as a code reference. This would especially be
approperiate if perl was changed so that it allows an object with
overloaded &{} to be used as a method name: a glob has as good a
working &{} as any object. In addition, a glob reference should be
accepted as well: that is currently stringified as well, which almost
surely fails.

Here are some code examples demonstrating the current behaviour.
These work in either 5.13.7 and 5.12.1.

$ perl5.13.7 -E 'use Symbol; $g = gensym(); *$g = sub { say "hello" };
(bless [])->$$g;'
Can't locate object method "GEN0" via package "Symbol" at -e line 1.
$ perl5.13.7 -E 'use Symbol; $g = gensym(); *$g = sub { say "hello" };
(bless [])->${\\&$g};'
$ perl5.13.7 -E '$g = \*X::foo; @X::ISA = Y::; sub Y::foo { say
"hello" }; (bless [])->$$g;'
$ perl5.13.7 -E '$g = \*X::foo; @X::ISA = Y::; sub Y::foo { say
"hello" }; (bless [])->${\\&$g};'
Undefined subroutine &X::foo called at -e line 1.


Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupperl5-porters @
postedDec 11, '10 at 8:45p
activeDec 11, '10 at 8:45p

1 user in discussion

Zsbán Ambrus: 1 post



site design / logo © 2022 Grokbase