With::Roles - Create role/class/object with composed roles
use With::Roles; # create class inheriting from My::Class, with My::Role applied my $class = My::Class->with::roles('My::Role'); # create a role with My::Role, then Another::Role applied my $role = My::Role->with::roles('Another::Role'); # generated role can be applied my $obj = My::Class->with::roles($role)->new; # apply role to object $obj->with::roles('Yet::Another::Role'); # applies the role My::Class::Role::My::Role my $another_class = My::Class->with::roles('+My::Role');
This module provides an easy to use global function that can be used on any package to create a new package with a set of roles applied.
When used on classes, generates a subclass with the given roles applied.
When used on roles, generates a new role with the base and given roles applied.
When used on objects, applies the roles to the object and returns the object. Unlike with roles and classes, this modifies the invocant.
The generated packages will have names based on the original classes and roles to aid with debugging. The exact form of the generated names should not be relied on.
A shorthand of
+RoleName can be used for roles named like
MyClass::Role::RoleName. Additional roles applied will continue to base the name on the original class. The package can also provide a method
ROLE_BASE to return a prefix to use other than
ROLE_BASE support is experimental, and may be removed or changed in a future version.
haarg - Graham Knop (cpan:HAARG) <email@example.com>
None so far.
This library is free software and may be distributed under the same terms as perl itself. See https://dev.perl.org/licenses/.