MooseX::Role::Parameterized::Extending.3pm

Langue: en

Version: 2010-01-17 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

Sommaire

NAME

MooseX::Role::Parameterized::Extending - extending MooseX::Role::Parameterized roles

DESCRIPTION

There are heaps of useful modules in the MooseX namespace that you can use to make your roles more powerful. However, they do not always work out of the box with MooseX::Role::Parameterized, but it's fairlystraight forward to achieve the functionality you desire.

MooseX::Role::Parameterized was designed to be extensible, and it is now possible to apply custom traits to the generated role, giving them the functionality provided in MooseX modules. In this example, we will look at applying the fake trait 'MooseX::MagicRole' to a parameterized role.

The first we need to do is define a new metaclass for our parameterized role. To get MooseX::Role::Parameterized to apply this metaclass to our roles, we need a little bit of glue first:

     package MyApp::Meta::Role::Parameterizable;
     use Moose;
     extends 'MooseX::Role::Parameterized::Meta::Role::Parameterizable';
     sub parameterized_role_metaclass { 'MyApp::Meta::Role::Parameterized' }
 
 

Now we can take advantage of this by specifying our glue metaclass to MooseX::Role::Parameterized:

     package MyApp::Role;
     use MooseX::Role::Parameterized -metaclass => 'MyApp::Meta::Role::Parameterizable';
 
     role {
     }
 
 

And there you go! MyApp::Role now has the MooseX::MagicRole trait applied.