in reply to Moose Role to include Use statements
I agree with tilly that abusing this approach is likely to end badly. The way I tend to handle these situations is to apply the following rules:
- If the role uses the module as a type (an attribute isa "Foo") then I will load that module in the role. This assures me that the correct Moose type for "Foo" is loaded and the role is using it.
- If the role uses the module, like a dump method using Data::Dumper then I will load the module in the role (although if the method is not going to be called often, I will sometimes load it with require or Class::MOP::load_class)
- And lastly, to continue on tillys theme, if it does not fall into the above rules and is just something I know I will need often, I will sometimes write a MyProject::Util module which imports common stuff as well as exports (sometimes wrapped) version of useful functions from other modules. I have been liking this approach a lot lately because it allows me to (somewhat) painlessly swap implementations if I need too.
-stvn
|
---|
In Section
Seekers of Perl Wisdom