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-1.00.tar.gz | 0000034386 33.6 KB | |
_link | 0000000165 165 Bytes | |
perl-MooseX-Role-Parameterized-old_Test_More.patch | 0000001153 1.13 KB | |
perl-MooseX-Role-Parameterized.changes | 0000003004 2.93 KB | |
perl-MooseX-Role-Parameterized.spec | 0000004679 4.57 KB |
Revision 17 (latest revision is 28)
- updated to 1.00 * MooseX::Role::Parameterized now depends on Moose 2.0300 released 2011-09-23 for its several core improvements, hence the major version number bump. * MXRP now uses the new meta_lookup feature added to Moose 2.0300 (specifically for MXRP) to avoid duplicating Moose-0.60-era Moose::Role sugar. This means the error messages you get are better, and there's a lot less ugly code in MXRP. * Remove alias/excludes special case errors. They have long since been replaced in core Moose by -alias and -excludes, and were finally removed in Moose 2.0200. * Expressly forbid using role { } inside role { } (which makes no sense but I suppose you could accidentally trigger it) * Documentation fix from cweyl@alumni.drew.edu https://github.com/sartak/MooseX-Role-Parameterized/pull/5
Comments 0