Matt Diephouse wrote:

One common use of anonymous subs in a dynamic language is
for later exporting them into another package (or multiple different
packages). In that case, you really don't want the sub to retain a link
to its defining namespace, you want it to fully adopt the namespace it's
pushed into. [...]

I'm struggling to understand what you're saying here. You noted before
that Perl 5's anonymous subroutines are full dynamic closures. As
such, they don't ever fully adopt the namespace they're pushed into.
Are you thinking of a different language? or am I missing a case?

Indeed that's true. And it's why SUPER is broken for exported methods in Perl 5. An exported method calls a SUPER method on the parent of the class where it was defined, instead of calling a SUPER method on the parent of the class where it was exported to. Giving you weird effects like:

Foo::Child inherits from Foo, but Bar::Child inherits from Bar. When you call a method on Bar::Child that was exported from Foo::Child, it calls Foo's method as the SUPER of Bar::Child when it should call Bar's method.

------
Calling from Foo object:
Foo implementation
------
Calling from Foo::Child object:
Foo::Child implementation (object is a Foo::Child)
SUPER is: Foo implementation
------
Calling from Bar object:
Bar implementation
------
Calling from Bar::Child object:
Foo::Child implementation (object is a Bar::Child)
SUPER is: Foo implementation
------

If Perl 6 doesn't fix this problem, other languages will, so Parrot should support a sane implementation. (And still also support Perl 5's odd way.)

Allison

Reply via email to