$Foo::foo->() calls the subroutine reference in $Foo::foo. (i.e, $foo in the Foo package). Assuming $Foo::foo is undefined and you're not running under strict, that would probably refer to the subroutine "" in the calling package (I'm guessing here, since I tend not to run strict-less)
If you want to call Foo::foo() as a class method of Foo, do:
Foo->foo();
| [reply] [d/l] [select] |
sub AUTOLOAD {"AUTOLOAD"}
*{""} = sub {"empty"};
print $nosuch->();
confirms your suspicion. | [reply] [d/l] |
Does $Foo::foo->() not mean locate the sub in the package Foo?
No. $Foo::foo is a symbol living in the symbol table Foo, that's granted; but its contents must not neccessarily refer to package Foo. So the normal method lookup rules apply. Which means that AUTOLOAD in the package main is found first.
update: If the content of $Foo::foo is a sub reference in the Foo namespace, the Foo AUTOLOAD is found, eg
$Foo::foo = \&Foo::bar;
print $Foo::foo->(); # Foo
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |
package Foo;
sub AUTOLOAD { __PACKAGE__ }
print $foo->();
package main;
sub AUTOLOAD { __PACKAGE__ }
__END__
main
I just can't find the documentation for this behaviour.
-- Frank | [reply] [d/l] [select] |
| [reply] |
How do you take the address of a sub that needs to be
AUTOLOADed before it is AUTOLOADed? Hmmm?
Be well,
rir
| [reply] |
*shrug* I just do. It's a magic called autovivification :-P
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] |