roles
view release on metacpan or search on metacpan
lib/roles.pm view on Meta::CPAN
our $AUTHORITY = 'cpan:STEVAN';
sub import {
shift;
my $pkg = caller(0);
my $meta = MOP::Util::get_meta( $pkg );
my @roles = map Module::Runtime::use_package_optimistically( $_ ), @_;
$meta->set_roles( @roles );
MOP::Util::defer_until_UNITCHECK(sub {
MOP::Util::compose_roles( MOP::Util::get_meta( $pkg ) )
});
}
sub DOES {
my ($self, $role) = @_;
# get the class ...
my $class = ref $self || $self;
# if we inherit from this, we are good ...
return 1 if $class->isa( $role );
lib/roles.pm view on Meta::CPAN
US::Currency->roles::DOES('Eq'); # true
US::Currency->roles::DOES('Printable'); # true
US::Currency->roles::DOES('Comparable'); # true
=head1 DESCRIPTION
This is a very simple pragma which takes a list of roles as
package names, adds them to the C<@DOES> package variable
and then schedules for role composition to occur during the
next available UNITCHECK phase.
=head2 C<roles::DOES>
Since Perl v5.10 there has been a C<UNIVERSAL::DOES> method
available, however it is unaware of this module so is not
very useful to us. Instead we supply a replacement in the
form of C<roles::DOES> method that can be used like this:
$instance->roles::DOES('SomeRole');
( run in 1.302 second using v1.01-cache-2.11-cpan-748bfb374f4 )