in reply to Re^3: __PACKAGE__ in anonysub
in thread __PACKAGE__ in anonysub
I'm sorry: I think I was very unclear in the original question, and simplified away the wrong bits. It's the package name of the factory that I want to capture in a method injected into the Drone class, so that the Drone (no idea why I called it that) can call instance() on the right factory class.
The answer turns out to be very simple, and much the same as your neat constructions:
sub post_require { my ($self, $class) = shift; my $factory_class=ref $self; no strict 'refs'; *{"$class::factory"} = sub { return $factory_class->instance; }; }
but it does look like I can't do it without creating some kind of closure, which I was hoping to avoid...
Thanks for your help.
|
|---|