Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Random Logic (2427)

Random Logic
  (email not shown publicly)
http://www.brabbel.net/

Journal of Random Logic (2427)

Tuesday July 15, 2008
05:26 PM

Thoughts on parametrized roles for Moose

[ #36920 ]
Moose might allow roles a little bit more freedom on how the are used by allowing parameters to be passed to roles. So the role can use those during initialization to act accordingly. This will allow to e.g. set a method prefix for a role's methods, or set some defaults, initialize some other stuff... Here's how it could look like:

use Moose;
with role 'My::Role'; ### no magic here same as: with 'My::Role';
with role 'MooseX::Log::Log4perl' => ':easy'; ### pass a param
with role 'MooseX::Log::Log4perl', prefix => 'mylog_'; ### pass the param hash/pair to a role

For more on that read this post...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • So we already have a mechanism in place whereby extra parameters can be passed into a role during composition, see Recipie 11 [cpan.org] for an example of the features that utilize this. Basically anything that is not another string passed after the roles gets turned into params (rjbs++ for Data::OptList which basically does all that work for me). So your examples would basically turn into this:

    with 'My::Role'; ### no need to change this

    with 'MooseX::Log::Log4perl' => [ ':easy' ]; ### this might not exactly work