line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package roles; |
2
|
|
|
|
|
|
|
# ABSTRACT: A simple pragma for composing roles. |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
57773
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
338
|
use MOP (); |
|
1
|
|
|
|
|
36449
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
6
|
use Module::Runtime (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
170
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
2
|
|
|
2
|
|
418
|
shift; |
15
|
2
|
|
|
|
|
4
|
my $pkg = caller(0); |
16
|
2
|
|
|
|
|
3
|
my $meta = MOP::Util::get_meta( $pkg ); |
17
|
2
|
|
|
|
|
231
|
my @roles = map Module::Runtime::use_package_optimistically( $_ ), @_; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
875
|
$meta->set_roles( @roles ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
MOP::Util::defer_until_UNITCHECK(sub { |
22
|
2
|
|
|
2
|
|
1759
|
MOP::Util::compose_roles( MOP::Util::get_meta( $pkg ) ) |
23
|
2
|
|
|
|
|
59
|
}); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub DOES { |
27
|
7
|
|
|
7
|
1
|
5498
|
my ($self, $role) = @_; |
28
|
|
|
|
|
|
|
# get the class ... |
29
|
7
|
|
66
|
|
|
23
|
my $class = ref $self || $self; |
30
|
|
|
|
|
|
|
# if we inherit from this, we are good ... |
31
|
7
|
50
|
|
|
|
30
|
return 1 if $class->isa( $role ); |
32
|
|
|
|
|
|
|
# next check the roles ... |
33
|
7
|
|
|
|
|
16
|
my $meta = MOP::Util::get_meta( $class ); |
34
|
|
|
|
|
|
|
# test just the local (and composed) roles first ... |
35
|
7
|
50
|
|
|
|
810
|
return 1 if $meta->does_role( $role ); |
36
|
|
|
|
|
|
|
# then check the inheritance hierarchy next ... |
37
|
0
|
0
|
|
|
|
|
return 1 if scalar grep { MOP::Util::get_meta( $_ )->does_role( $role ) } @{ $meta->mro }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |