Roles with composition parameters
Your parameterized role consists of two new things: parameter declarations and
a role block.
Parameters are declared using the "parameter" keyword which very much resembles
"has" in Moose. You can use any option that "has" in Moose accepts. The default
value for the is option is ro as that's a very common case. Use is => 'bare' if
you want no accessor. These parameters will get their values when the consuming
class (or role) uses "with" in Moose. A parameter object will be constructed
with these values, and passed to the role block.
The role block then uses the usual Moose::Role keywords to build up a role. You
can shift off the parameter object to inspect what the consuming class provided
as parameters. You use the parameters to customize your role however you wish.
There are many possible implementations for parameterized roles (hopefully with
a consistent enough API); I believe this to be the easiest and most flexible
design. Coincidentally, Pugs originally had an eerily similar design.
- Devel package for openSUSE:Factory
-
2
derived packages
- Links to openSUSE:Factory / perl-MooseX...ameterized
- Download package
-
Checkout Package
osc -A https://api.opensuse.org checkout devel:languages:perl/perl-MooseX-Role-Parameterized && cd $_
- Create Badge
Source Files
Filename | Size | Changed |
---|---|---|
MooseX-Role-Parameterized-0.26.tar.gz | 0000033737 32.9 KB | |
perl-MooseX-Role-Parameterized-remove_done_testing |
0000000444 444 Bytes | |
perl-MooseX-Role-Parameterized.changes | 0000001371 1.34 KB | |
perl-MooseX-Role-Parameterized.spec | 0000003007 2.94 KB |
Revision 9 (latest revision is 28)
- updated to 0.26 * make tests stop relying on a specific format for anon class/role names (doy) * Move the reinitialization hook from Role to Trait so hardcore hackers (trait janitors) get the benefit too (doy) * Made MXRP more extensible by hooking into the role metaobject reinitialization (doy) * Merry Christmas! * Make MooseX::Role::Parameterized::Extending more instructive. Hopefully. * The test suite now uses Test::Fatal instead of Test::Exception (Karen Etheridge). * Fix Test::More dependency (reported by Father Chrysostomos) [rt.cpan.org #63222] * "package" arg can now tell generate_role to use a specific package (rjbs) * Minor test refactoring to fix blead support [rt.perl.org #78244]
Comments 0