exact::role - Simple role interface extension for exact
version 1.11
package Claw; use exact -role; package Cat; use exact -class; with 'Claw';
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:
noautoclean
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.
requires qw(foo bar);
Declares a list of methods that must be defined to compose role.
with 'Some::Role1'; with 'Some::Role1', 'Some::Role2';
Composes another role into the current role (or class via exact::class's with).
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 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 foo => sub { ... };
See "around method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
after foo => sub { ... };
See "after method(s) => sub { ... }" in Class::Method::Modifiers for full documentation.
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...
does
$foo->does('Some::Role');
...will work for classes but to test a role, one must use does_role directly.
does_role
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.
any
exact::role->apply_roles_to_package( 'Some::Package', 'Some::Role', 'Some::Other::Role' );
Composes role with package. See also exact::class's with.
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.
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.
exact::role->is_role('Some::Role1');
Returns true if the given package is a role.
You can look for additional information at:
GitHub
MetaCPAN
GitHub Actions
Codecov
CPANTS
CPAN Testers
Gryphon Shafer <gryphon@cpan.org>
This software is Copyright (c) 2019-2021 by Gryphon Shafer.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install exact::class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm exact::class
CPAN shell
perl -MCPAN -e shell install exact::class
For more information on module installation, please visit the detailed CPAN module installation guide.