Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: __PACKAGE__ in anonysub

by thpfft (Chaplain)
on Feb 19, 2005 at 21:05 UTC ( [id://432780]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://432780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found