MooseX::RoleFor - limit the applicability of a Moose::Role
my ($self) = @_;
This package allows your Moose roles to limit what classes and objects they may be composed with. This is often not a good idea - one of the advantages of roles is that they can be reused in such different contexts.
However, if you search CPAN for "TraitFor" you'll see that it's quite a common desire to indicate that a role should only be applies to certain classes.
role_for $class, $consequence
$class is a string (class name) or arrayref of strings indicating which classes this role may be composed with. Inheritance is respected.
$consequence is either "carp" (the default) or "croak".
Adding use MooseX::RoleFor to your role imports the role_for function to your class, and applies the MooseX::RoleFor::Meta::Role::Trait::RoleFor role to your role's metaclass.
The role_for function is basically:
if defined $_;
MooseX::RoleFor::Meta::Role::Trait::RoleFor hooks onto Moose::Meta::Role's apply method to enforce your restriction.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-RoleFor.
When misapplying a role to an instance (rather than a class), you get not one warning, but two: one for the object, and one for its metaclass.
MooseX::RoleFor::Meta::Role::Trait::RoleFor - internals.
Toby Inkster <firstname.lastname@example.org>.
This software is copyright (c) 2011-2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::RoleFor, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.