line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
15393
|
use 5.008; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
198
|
|
2
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
140
|
|
3
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
182
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Role::Commons; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
18
|
use Carp qw[ carp croak ]; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
459
|
|
8
|
5
|
|
|
5
|
|
2678
|
use Module::Runtime qw[ use_package_optimistically ]; |
|
5
|
|
|
|
|
7484
|
|
|
5
|
|
|
|
|
24
|
|
9
|
5
|
|
|
5
|
|
2694
|
use Moo::Role qw[]; |
|
5
|
|
|
|
|
79280
|
|
|
5
|
|
|
|
|
161
|
|
10
|
5
|
|
|
5
|
|
2230
|
use Types::TypeTiny qw[ HashLike ArrayLike ]; |
|
5
|
|
|
|
|
12282
|
|
|
5
|
|
|
|
|
15
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
5
|
|
|
5
|
|
17029
|
$Role::Commons::AUTHORITY = 'cpan:TOBYINK'; |
14
|
5
|
|
|
|
|
1473
|
$Role::Commons::VERSION = '0.104'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @ALL = qw( |
18
|
|
|
|
|
|
|
Authority |
19
|
|
|
|
|
|
|
ObjectID |
20
|
|
|
|
|
|
|
Tap |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse_arguments |
24
|
|
|
|
|
|
|
{ |
25
|
7
|
|
|
7
|
1
|
9
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Translate "-all". |
28
|
7
|
|
|
|
|
7
|
my $all = 0; |
29
|
7
|
100
|
|
|
|
11
|
my @args = grep { /^\-all$/i ? do { $all++; 0 } : 1 } @_; |
|
17
|
|
|
|
|
63
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
30
|
7
|
100
|
|
|
|
52
|
unshift @args, @ALL if $all; |
31
|
|
|
|
|
|
|
|
32
|
7
|
|
|
|
|
6
|
my %roles; |
33
|
|
|
|
|
|
|
my %options; |
34
|
7
|
|
|
|
|
18
|
while (my $name = shift @args) |
35
|
|
|
|
|
|
|
{ |
36
|
14
|
|
|
|
|
12
|
my $details; |
37
|
14
|
100
|
66
|
|
|
65
|
if ($name =~ /^-/ or ref $args[0]) |
38
|
5
|
|
|
|
|
7
|
{ $details = shift @args } |
39
|
|
|
|
|
|
|
|
40
|
14
|
100
|
|
|
|
30
|
if ($name =~ /^\-(.+)$/i) |
41
|
5
|
|
|
|
|
24
|
{ $options{ lc $1 } = $details } |
42
|
|
|
|
|
|
|
else |
43
|
9
|
|
|
|
|
33
|
{ $roles{ $name } = $details } |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
7
|
50
|
66
|
|
|
34
|
carp "Role::Commons - no roles specified" |
47
|
|
|
|
|
|
|
if keys %options && !keys %roles; |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
22
|
return(\%roles, \%options); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub import |
53
|
|
|
|
|
|
|
{ |
54
|
4
|
|
|
4
|
|
12
|
my $class = shift; |
55
|
4
|
|
|
|
|
12
|
my ($roles, $options) = $class->parse_arguments(@_); |
56
|
4
|
100
|
|
|
|
14
|
$options->{into} = caller unless exists $options->{into}; |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
13
|
foreach my $role (sort keys %$roles) |
59
|
|
|
|
|
|
|
{ |
60
|
6
|
|
|
|
|
42
|
use_package_optimistically( join q[::], $class, $role ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
'Moo::Role'->apply_roles_to_package( |
64
|
6
|
|
|
|
|
35
|
$options->{into}, |
65
|
4
|
|
|
|
|
184
|
map { join q[::], $class, $_ } sort keys %$roles, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
2824
|
foreach my $role (sort keys %$roles) |
69
|
|
|
|
|
|
|
{ |
70
|
6
|
|
|
|
|
18
|
my $role_pkg = join q[::], $class, $role; |
71
|
6
|
|
|
|
|
13
|
my $details = $roles->{$role}; |
72
|
6
|
50
|
|
|
|
7
|
my $setup_method = do { |
73
|
5
|
|
|
5
|
|
33
|
no strict 'refs'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
1147
|
|
74
|
6
|
|
|
|
|
7
|
${"$role_pkg\::setup_for_class"}; |
|
6
|
|
|
|
|
49
|
|
75
|
|
|
|
|
|
|
} or next; |
76
|
6
|
50
|
|
|
|
26
|
$role_pkg->$setup_method( |
|
|
50
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$options->{into}, |
78
|
|
|
|
|
|
|
HashLike->check($details) |
79
|
|
|
|
|
|
|
? %$details |
80
|
|
|
|
|
|
|
: ( ArrayLike->check($details) ? @$details : (option => $details) ), |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub apply_roles_to_object |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
0
|
|
0
|
1
|
|
my $class = shift unless blessed($_[0]); |
88
|
0
|
|
|
|
|
|
my $object = shift; |
89
|
0
|
|
|
|
|
|
my ($roles, $options) = $class->parse_arguments(@_); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
foreach my $role (sort keys %$roles) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
|
use_package_optimistically( join q[::], $class, $role ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
'Moo::Role'->apply_roles_to_object( |
97
|
0
|
|
|
|
|
|
$object, |
98
|
0
|
|
|
|
|
|
map { join q[::], $class, $_ } sort keys %$roles, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
foreach my $role (sort keys %$roles) |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
|
|
|
my $role_pkg = join q[::], $class, $role; |
104
|
0
|
|
|
|
|
|
my $details = $roles->{$role}; |
105
|
|
|
|
|
|
|
my $setup_method = do { |
106
|
5
|
|
|
5
|
|
27
|
no strict 'refs'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
419
|
|
107
|
|
|
|
|
|
|
${"$role_pkg\::setup_for_class"}; |
108
|
0
|
|
0
|
0
|
|
|
} || sub { 0 }; |
|
0
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
$role_pkg->$setup_method( |
|
|
0
|
|
|
|
|
|
110
|
|
|
|
|
|
|
ref($object), |
111
|
|
|
|
|
|
|
HashLike->check($details) |
112
|
|
|
|
|
|
|
? %$details |
113
|
|
|
|
|
|
|
: ( ArrayLike->check($details) ? @$details : (option => $details) ), |
114
|
|
|
|
|
|
|
); |
115
|
0
|
0
|
|
|
|
|
$setup_method = do { |
116
|
5
|
|
|
5
|
|
25
|
no strict 'refs'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
517
|
|
117
|
0
|
|
|
|
|
|
${"$role_pkg\::setup_for_object"}; |
|
0
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} or next; |
119
|
0
|
0
|
|
|
|
|
$role_pkg->$setup_method( |
|
|
0
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$object, |
121
|
|
|
|
|
|
|
HashLike->check($details) |
122
|
|
|
|
|
|
|
? %$details |
123
|
|
|
|
|
|
|
: ( ArrayLike->check($details) ? @$details : (option => $details) ), |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |