|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re: any way to fill calling namespace with a "use Module"?by tobyink (Prior) |
| on Feb 23, 2013 at 20:32 UTC ( #1020341=note: print w/ replies, xml ) | Need Help?? |
|
TIMTOWTDI, but I'd say the "official antlered" way to do it would perhaps be along these lines...
Of course, you can just use bless $object => $class to rebless an existing object into a different class. The Top class could do that somewhere in its constructor. (Though the Moose style is to not write constructors, but write BUILD/BUILDARGS methods instead!) However, the rebless_instance method is somewhat smarter - it allows you to pass in additional constructor parameters (in case the subordinate classes defined additional attributes), and checks that the class you're reblessing into is a subclass of the original class.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||