NAME
exact::role - Simple role interface extension for exact
VERSION
version 1.18
SYNOPSIS
package Claw;
use exact -role;
package Cat;
use exact -class;
with 'Claw';
DESCRIPTION
exact::role is a tiny mechanism to create roles for use with exact::class. It relies on Role::Tiny, which is to say, it just integrates Role::Tiny with exact::class and exact.
Note that the noautoclean
option of exact gets automatically switched on when you:
use exact -role;
This is to prevent all sorts of expected behaviors from Role::Tiny. If you want autoclean functionality, it's left up to you to set that up.
IMPORTED FUNCTIONS
requires
requires qw(foo bar);
Declares a list of methods that must be defined to compose role.
with
with 'Some::Role1';
with 'Some::Role1', 'Some::Role2';
Composes another role into the current role (or class via exact::class's with
).
If you have conflicts and want to resolve them in favour of Some::Role1 you can instead write:
with 'Some::Role1';
with 'Some::Role2';
If you have conflicts and want to resolve different conflicts in favour of different roles, please refactor your codebase.
before
before foo => sub { ... };
See "before method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
Note that since you are not required to use method modifiers, Class::Method::Modifiers is lazily loaded and we do not declare it as a dependency. If your exact::role role uses modifiers you must depend on both Class::Method::Modifiers and exact::role.
around
around foo => sub { ... };
See "around method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
Note that since you are not required to use method modifiers, Class::Method::Modifiers is lazily loaded and we do not declare it as a dependency. If your exact::role role uses modifiers you must depend on both Class::Method::Modifiers and exact::role.
after
after foo => sub { ... };
See "after method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
Note that since you are not required to use method modifiers, Class::Method::Modifiers is lazily loaded and we do not declare it as a dependency. If your exact::role role uses modifiers you must depend on both Class::Method::Modifiers and exact::role.
SUBROUTINES
does_role
exact::role::does_role( $foo, 'Some::Role' );
Returns true if class has been composed with role.
This subroutine is also installed as does
on any class a exact::role is composed into unless that class already has an does
method, so...
$foo->does('Some::Role');
...will work for classes but to test a role, one must use does_role
directly.
Additionally, exact::role will override the standard Perl does
method for your class. However, if any
class in your class inheritance hierarchy provides does
, then exact::role will not override it.
METHODS
apply_roles_to_package
exact::role->apply_roles_to_package(
'Some::Package', 'Some::Role', 'Some::Other::Role'
);
Composes role with package. See also exact::class's with
.
apply_roles_to_object
exact::role->apply_roles_to_object( $foo, qw( Some::Role1 Some::Role2 ) );
Composes roles in order into object directly. Object is reblessed into the resulting class. Note that the object's methods get overridden by the role's ones with the same names.
create_class_with_roles
exact::role->create_class_with_roles( 'Some::Base', qw( Some::Role1 Some::Role2 ) );
Creates a new class based on base, with the roles composed into it in order. New class is returned.
is_role
exact::role->is_role('Some::Role1');
Returns true if the given package is a role.
SEE ALSO
You can look for additional information at:
AUTHOR
Gryphon Shafer <gryphon@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2019-2050 by Gryphon Shafer.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)