good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Passing an import list to Moose extendsby choroba (Cardinal) |
on May 03, 2018 at 21:23 UTC ( [id://1214027]=note: print w/replies, xml ) | Need Help?? |
I still struggle to find an imaginable use case. strict isn't an object class. Also, how would you specify the import arguments for a non-Moose class inherited via parent or base? Here's what I've played with: My/Parent.pm
Plus a test to show how it works:
Inheriting via parent is possible, just note that the import method would be inherited, but you can override it and call the SUPER class's method: My/SimpleChild.pm
And it works:
In fact, you can use the same trick in Moose. I just added MooseX::NonMoose that handles inheriting from non-Moose classes correctly, and defined the a and b as proper attributes. For it to work, I needed to specify FOREIGNBUILDARGS so I can call the constructor without a hash reference: My/MooseChild.pm
And again, it works.
I'm not sure I'd go that way, though. I remember some monks preferred delegation over inheritance, and we can use it here, too: My/DelegChild.pm
It can all get very fragile and weird, because the import method changes the global state (and imagine what would happen if the parent's import method used state $name instead of my). It might be impossible to have two classes, each using different import parameters of the base class.
In Section
Seekers of Perl Wisdom
|
|