in reply to Re^3: __PACKAGE__ in anonysub
in thread __PACKAGE__ in anonysub

Thank you! That won't work in my real situation, because I won't be calling a class method like that, but you made me realise that instead of __PACKAGE__, I just need to call ref $self, which will inherit properly. D'oh:

my $self = shift; my $factory_class=ref $self; *Foo::bar = sub { return $factory_class->instance; };

I definitely am creating a closure now, but I don't think it will matter: it's only a simple scalar that gets unnaturally prolonged.

Thanks.