Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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.

-stvn


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-07 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls