It's not quite that simple: I know that bit works - that's why I'm using it - but I wasn't sure that it would work in a subclass. And you're quite right: I should have just tried it. So:
package Drone; sub new { return bless {}, shift; } 1; package Factory; no strict 'refs'; sub fixup { *Drone::bar = sub { return __PACKAGE__ }; } 1; package Subfactory; use base qw( Factory ); 1; package main; Subfactory->fixup; my $foo = Drone->new; print $foo->bar . "\n";
And it looks like the answer is no: this code prints 'Factory' for me, where I want it to say 'Subfactory'. Curses. So how can I get the name of the inheriting package inside the anonymous sub when fixup() is called? I guess I'll have to put in a package_name method and do it literally.
Thanks for putting my mind at rest about the other thing.
In reply to Re^2: __PACKAGE__ in anonysub
by thpfft
in thread __PACKAGE__ in anonysub
by thpfft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |