in reply to Re: __PACKAGE__ in anonysub
in thread __PACKAGE__ in anonysub
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: __PACKAGE__ in anonysub
by Tanktalus (Canon) on Feb 19, 2005 at 20:27 UTC | |
by thpfft (Chaplain) on Feb 19, 2005 at 20:52 UTC | |
Re^3: __PACKAGE__ in anonysub
by ikegami (Patriarch) on Feb 19, 2005 at 20:36 UTC | |
by thpfft (Chaplain) on Feb 19, 2005 at 21:05 UTC |