Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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.

Comment on Re: Moose Role to include Use statements
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2016-05-01 19:11 GMT
Find Nodes?
    Voting Booth?