Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Moose Role to include Use statements

by stvn (Monsignor)
on Feb 21, 2011 at 18:13 UTC ( #889442=note: print w/replies, xml ) Need Help??

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://889442]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-04-24 18:41 GMT
Find Nodes?
    Voting Booth?