Server : Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.6 System : Windows NT USER-PC 6.1 build 7601 (Windows 7 Professional Edition Service Pack 1) AMD64 User : User ( 0) PHP Version : 7.4.6 Disable Function : NONE Directory : C:/xampp/perl/vendor/lib/MooseX/Role/Parameterized/ |
=pod =head1 NAME MooseX::Role::Parameterized::Extending - extending MooseX::Role::Parameterized roles =head1 DESCRIPTION There are heaps of useful modules in the C<MooseX> namespace that you can use to make your roles more powerful. However, they do not always work out of the box with L<MooseX::Role::Parameterized>, but it's fairly straight-forward to achieve the functionality you desire. L<MooseX::Role::Parameterized> was designed to be as extensible as the rest of L<Moose>, and as such it is possible to apply custom traits to both the parameterizable role or the ordinary roles they generate. In this example, we will look at applying the fake trait C<MooseX::MagicRole> to a parameterizable role. First we need to define a new metaclass for our parameterizable role. package MyApp::Meta::Role::Parameterizable; use Moose; extends 'MooseX::Role::Parameterized::Meta::Role::Parameterizable'; with 'MooseX::MagicRole'; This is a class (observe that it uses L<Moose>, not L<Moose::Role>) which extends the class which governs parameterizable roles. L<MooseX::Role::Parameterized::Meta::Role::Parameterizable> is the metaclass that packages using L<MooseX::Role::Parameterized> receive by default. Note that the class we are extending, L<MooseX::Role::Parameterized::Meta::Role::ParameterizB<I<able>>|MooseX::Role::Parameterized::Meta::Role::Parameterizable>, is entirely distinct from the similarly-named class which governs the ordinary roles that parameterized roles generate. An instance of L<MooseX::Role::Parameterized::Meta::Role::ParameterizB<I<ed>>|MooseX::Role::Parameterized> represents a role with its parameters already bound. Now we can take advantage of our new subclass by specifying that we want to use C<MyApp::Meta::Role::Parameterizable> as our metaclass when importing L<MooseX::Role::Parameterized>: package MyApp::Role; use MooseX::Role::Parameterized -metaclass => 'MyApp::Meta::Role::Parameterizable'; role { ... } And there you go! C<MyApp::Role> now has the C<MooseX::MagicRole> trait applied. =cut