1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
{
## skip Test::Tabs
package Local::Role1;
our $USES_MITE = q[Mite::Role];
use strict;
use warnings;
sub DOES {
my ( $self, $role ) = @_;
our %DOES;
return $DOES{$role} if exists $DOES{$role};
return 1 if $role eq __PACKAGE__;
return $self->SUPER::DOES( $role );
}
sub does {
shift->DOES( @_ );
}
# Callback which classes consuming this role will call
sub __FINALIZE_APPLICATION__ {
my ( $me, $target, $args ) = @_;
our ( %CONSUMERS, @METHOD_MODIFIERS );
# Ensure a given target only consumes this role once.
if ( exists $CONSUMERS{$target} ) {
return;
}
$CONSUMERS{$target} = 1;
my $type = do { no strict 'refs'; ${"$target\::USES_MITE"} };
if ( $type ne 'Mite::Class' ) {
return;
}
my @roles = ( );
my %nextargs = %{ $args || {} };
( $nextargs{-indirect} ||= 0 )++;
for my $role ( @roles ) {
$role->__FINALIZE_APPLICATION__( $target, { %nextargs } );
}
my $shim = q[Local::Mite];
for my $modifier_rule ( @METHOD_MODIFIERS ) {
my ( $modification, $names, $coderef ) = @$modifier_rule;
$shim->$modification( $target, $names, $coderef );
}
return;
}
1;
}
|