/usr/local/lib/perl5/site_perl/5.44.0/Role/Tiny.pm

filter: Statementstmt 48.0% 148 / 308 Branchbran 27.8% 29 / 104 Conditioncond 22.6% 22 / 97 MC/DCmcdc 3.8% 2 / 52 Subroutinesub 54.9% 28 / 51 Podpod 50.0% 6 / 12 totaltotal 37.6% 235 / 624 CC 100 SCAR 28.0
CC
100
Cov
39%
_install_methods
52.2
apply_roles_to_package
39.0
_install_modifiers
38.6
CRAP 16.4
« lib/Skilletor/Report.pm ↑ Summary /usr/local/lib/perl5/5.44.0/CPAN/Meta/Validator.pm »
1 package Role::Tiny;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '2.002005';
6 5 $VERSION =~ tr/_//d;
7  
8 5 our %INFO;
9 5 our %APPLIED_TO;
10 5 our %COMPOSED;
11 5 our %COMPOSITE_INFO;
12 5 our @ON_ROLE_CREATE;
13  
14 # Module state workaround totally stolen from Zefram's Module::Runtime.
15  
16 5 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=27.3
17 5 ▶ *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.009 ? : 0 5 5
18 *_WORK_AROUND_HINT_LEAKAGE
19 = "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
20 5 ▶ ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001) ? : 0 5 5
Condition16%1/6
"$]" < "5.011" and not "$]" >= "5.009004" && "$]" < "5.010001"
!ll&&!rl&&r
500
"$]" >= 5.009004 && "$]" < 5.010001
!ll&&!rl&&r
000
MC/DC0%0/3
"$]" < "5.011" and not "$]" >= "5.009004" && "$]" < "5.010001"
"$]" < "5.011" "$]" >= 5.009004 "$]" < 5.010001
Truth table25%1/4
A and not(B && C)
A= "$]" < "5.011"B= "$]" >= 5.009004C= "$]" < 5.010001
ABCresult
0XX0
1110
10X1
1101
21 5 ▶ *_CONSTANTS_DEFLATE = "$]" >= 5.012 && "$]" < 5.020 ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" >= 5.012 && "$]" < 5.02 ? : 0 5 5
Condition33%1/3
"$]" >= "5.012" and "$]" < "5.02"
!ll&&!rl&&r
050
MC/DC0%0/2
"$]" >= "5.012" and "$]" < "5.02"
"$]" >= "5.012" "$]" < "5.02"
Truth table33%1/3
A and B
A= "$]" >= "5.012"B= "$]" < "5.02"
ABresult
0X0
100
111
22 }
23  
24 5 ▶sub _getglob { no strict 'refs'; \*{$_[0]} }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _getglob: called CC=1 SCAR=0.0
25 5 ▶sub _getstash { no strict 'refs'; \%{"$_[0]::"} }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _getstash: called CC=1 SCAR=0.0
26  
27 0 ▶sub croak {
Subroutine croak: not called CC=1 SCAR=1.2
Pod undocumented
28 0 require Carp;
29 5 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 *croak = \&Carp::croak;
31 0 goto &Carp::croak;
32 }
33  
34 0 ▶sub Role::Tiny::__GUARD__::DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
35 0 ▶ delete $INC{$_[0]->[0]} if @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if @{$_[0];} 0 0 0
36 }
37  
38 0 ▶sub _load_module {
Subroutine _load_module: not called CC=3 SCAR=24.8
39 0 my ($module) = @_;
40 0 (my $file = "$module.pm") =~ s{::}{/}g;
41 return 1
42 0 ▶ if $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$file} 0 0 0
43  
44 # can't just ->can('can') because a sub-package Foo::Bar::Baz
45 # creates a 'Baz::' key in Foo::Bar's symbol table
46 return 1
47 0 ▶ if grep !/::\z/, keys %{_getstash($module)};
Branch: 1 branch
BranchTrueFalseTotal
if grep((!/::\z/), keys %{_getstash($module);}) 0 0 0
48 0 my $guard = _WORK_AROUND_BROKEN_MODULE_STATE
49 && bless([ $file ], 'Role::Tiny::__GUARD__');
50 0 local %^H if _WORK_AROUND_HINT_LEAKAGE;
51 0 require $file;
52 0 pop @$guard if _WORK_AROUND_BROKEN_MODULE_STATE;
53 0 return 1;
54 }
55  
56 0 ▶sub _require_module {
Subroutine _require_module: not called CC=1 SCAR=6.9
57 0 _load_module($_[1]);
58 }
59  
60 35 ▶sub _all_subs {
Subroutine _all_subs: called CC=1 SCAR=0.0
61 35 my ($me, $package) = @_;
62 35 my $stash = _getstash($package);
63 return {
64 map {;
65 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 # this is an ugly hack to populate the scalar slot of any globs, to
67 # prevent perl from converting constants back into scalar refs in the
68 # stash when they are used (perl 5.12 - 5.18). scalar slots on their own
69 # aren't detectable through pure perl, so this seems like an acceptable
70 # compromise.
71 305 ${"${package}::${_}"} = ${"${package}::${_}"}
72 if _CONSTANTS_DEFLATE;
73 305 $_ => \&{"${package}::${_}"}
74 }
75 35 grep exists &{"${package}::${_}"},
76 grep !/::\z/,
77 keys %$stash
78 };
79 }
80  
81 5 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
82 5 my $target = caller;
83 5 my $me = shift;
84 5 strict->import;
85 5 warnings->import;
86 5 $me->init_role($target, @_);
87 }
88  
89 5 ▶sub init_role {
Subroutine init_role: called CC=3 SCAR=11.6
Pod undocumented
90 5 my ($me, $target, @args) = @_;
91  
92 5 my $non_methods = $me->_non_methods($target);
93 5 $me->_install_subs($target, @args);
94 5 $me->make_role($target);
95 5 ▶ $me->_mark_new_non_methods($target, $non_methods)
Branch: 1 branch
BranchTrueFalseTotal
if $non_methods and %$non_methods 0 5 5
Condition33%1/3
$non_methods and %$non_methods
!ll&&!rl&&r
050
MC/DC0%0/2
$non_methods and %$non_methods
$non_methods %$non_methods
Truth table33%1/3
A and B
A= $non_methodsB= %$non_methods
ABresult
0X0
100
111
96 if $non_methods && %$non_methods;
97 5 return;
98 }
99  
100 0 ▶sub _mark_new_non_methods {
Subroutine _mark_new_non_methods: not called CC=4 SCAR=30.0
101 0 my ($me, $target, $old_non_methods) = @_;
102  
103 0 my $non_methods = $INFO{$target}{non_methods};
104  
105 0 my $subs = $me->_all_subs($target);
106 0 for my $sub (keys %$subs) {
107 0 ▶ if ( exists $old_non_methods->{$sub} && $non_methods->{$sub} != $subs->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_non_methods->{$sub} and $non_methods->{$sub} != $subs->{$sub}) 0 0 0
Condition0%0/3
exists $old_non_methods->{$sub} and $non_methods->{$sub} != $subs->{$sub}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $old_non_methods->{$sub} and $non_methods->{$sub} != $subs->{$sub}
exists $old_non_methods->{$sub} $non_methods->{$sub} != $subs->{$sub}
Truth table0%0/3
A and B
A= exists $old_non_methods->{$sub}B= $non_methods->{$sub} != $subs->{$sub}
ABresult
0X0
100
111
108 0 $non_methods->{$sub} = $subs->{$sub};
109 }
110 }
111  
112 0 return;
113 }
114  
115 5 ▶sub make_role {
Subroutine make_role: called CC=3 SCAR=11.0
Pod documented
116 5 my ($me, $target) = @_;
117  
118 5 ▶ return if $me->is_role($target);
Branch: 1 branch
BranchTrueFalseTotal
if $me->is_role($target) 0 5 5
119 5 $INFO{$target}{is_role} = 1;
120  
121 5 my $non_methods = $me->_all_subs($target);
122 5 delete @{$non_methods}{grep /\A\(/, keys %$non_methods};
123 5 $INFO{$target}{non_methods} = $non_methods;
124  
125 # a role does itself
126 5 $APPLIED_TO{$target} = { $target => undef };
127 5 foreach my $hook (@ON_ROLE_CREATE) {
128 5 $hook->($target);
129 }
130 }
131  
132 0 ▶sub _install_subs {
Subroutine _install_subs: not called CC=3 SCAR=24.8
133 0 my ($me, $target) = @_;
134 0 ▶ return if $me->is_role($target);
Branch: 1 branch
BranchTrueFalseTotal
if $me->is_role($target) 0 0 0
135 0 my %install = $me->_gen_subs($target);
136 0 *{_getglob("${target}::${_}")} = $install{$_}
137 0 for sort keys %install;
138 0 return;
139 }
140  
141 0 ▶sub _gen_subs {
Subroutine _gen_subs: not called CC=1 SCAR=6.9
142 0 my ($me, $target) = @_;
143 (
144 (map {;
145 0 my $type = $_;
146 0 ▶ $type => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
147 0 my $code = pop;
148 0 ▶ my @names = ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
149 0 ▶ push @{$INFO{$target}{modifiers}||=[]}, [ $type, @names, $code ];
Condition0%0/2
$Role::Tiny::INFO{$target}{"modifiers"} ||= []
l!l
00
MC/DC0%0/1
$Role::Tiny::INFO{$target}{"modifiers"} ||= []
$Role::Tiny::INFO{$target}{"modifiers"}
Truth table0%0/2
A
A= $Role::Tiny::INFO{$target}{"modifiers"}
Aresult
11
00
150 0 return;
151 0 };
152 } qw(before after around)),
153 0 ▶ requires => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
154 0 ▶ push @{$INFO{$target}{requires}||=[]}, @_;
Condition0%0/2
$Role::Tiny::INFO{$target}{"requires"} ||= []
l!l
00
MC/DC0%0/1
$Role::Tiny::INFO{$target}{"requires"} ||= []
$Role::Tiny::INFO{$target}{"requires"}
Truth table0%0/2
A
A= $Role::Tiny::INFO{$target}{"requires"}
Aresult
11
00
155 0 return;
156 },
157 0 ▶ with => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 0 $me->apply_roles_to_package($target, @_);
159 0 return;
160 },
161 0 );
162 }
163  
164 15 ▶sub role_application_steps {
Subroutine role_application_steps: called CC=1 SCAR=0.0
Pod undocumented
165 15 qw(
166 _install_methods
167 _check_requires
168 _install_modifiers
169 _copy_applied_list
170 );
171 }
172  
173 15 ▶sub _copy_applied_list {
Subroutine _copy_applied_list: called CC=2 SCAR=7.0
174 15 my ($me, $to, $role) = @_;
175 # copy our role list into the target's
176 15 ▶ @{$APPLIED_TO{$to}||={}}{keys %{$APPLIED_TO{$role}}} = ();
Condition50%1/2
$Role::Tiny::APPLIED_TO{$to} ||= {}
l!l
015
MC/DC0%0/1
$Role::Tiny::APPLIED_TO{$to} ||= {}
$Role::Tiny::APPLIED_TO{$to}
Truth table50%1/2
A
A= $Role::Tiny::APPLIED_TO{$to}
Aresult
11
00
177 }
178  
179 0 ▶sub apply_roles_to_object {
Subroutine apply_roles_to_object: not called CC=1 SCAR=6.9
Pod documented
180 0 my ($me, $object, @roles) = @_;
181 0 my $class = ref($object);
182 # on perl < 5.8.9, magic isn't copied to all ref copies. bless the parameter
183 # directly, so at least the variable passed to us will get any magic applied
184 0 bless($_[1], $me->create_class_with_roles($class, @roles));
185 }
186  
187 5 my $role_suffix = 'A000';
188 0 ▶sub _composite_name {
Subroutine _composite_name: not called CC=3 SCAR=24.8
189 0 my ($me, $superclass, @roles) = @_;
190  
191 0 my $new_name = $superclass . '__WITH__' . join '__AND__', @roles;
192  
193 0 ▶ if (length($new_name) > 252) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $new_name > 252) 0 0 0
194 0 ▶ $new_name = $COMPOSED{abbrev}{$new_name} ||= do {
Condition0%0/3
$Role::Tiny::COMPOSED{"abbrev"}{$new_name} ||= do { my $abbrev = substr($new_name, 0, 250 - length($role_suffix)); $abbrev =~ s/(?<!:):$//; $abbrev . '__' . $role_suffix++ }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Role::Tiny::COMPOSED{"abbrev"}{$new_name} ||= do { my $abbrev = substr($new_name, 0, 250 - length($role_suffix)); $abbrev =~ s/(?<!:):$//; $abbrev . '__' . $role_suffix++ }
$Role::Tiny::COMPOSED{"abbrev"}{$new_name} do { my $abbrev = substr($new_name, 0, 250 - length($role_suffix)); $abbrev =~ s/(?<!:):$//; $abbrev . '__' . $role_suffix++ }
Truth table0%0/3
A ||= B
A= $Role::Tiny::COMPOSED{"abbrev"}{$new_name}B= do { my $abbrev = substr($new_name, 0, 250 - length($role_suffix)); $abbrev =~ s/(?<!:):$//; $abbrev . '__' . $role_suffix++ }
ABresult
1X1
011
000
195 0 my $abbrev = substr $new_name, 0, 250 - length $role_suffix;
196 0 $abbrev =~ s/(?<!:):$//;
197 0 $abbrev.'__'.$role_suffix++;
198 };
199 }
200 0 return $new_name;
201 }
202  
203 0 ▶sub create_class_with_roles {
Subroutine create_class_with_roles: not called CC=2 SCAR=17.9
Pod documented
204 0 my ($me, $superclass, @roles) = @_;
205  
206 0 $me->_require_module($superclass);
207 0 $me->_check_roles(@roles);
208  
209 0 my $new_name = $me->_composite_name($superclass, @roles);
210  
211 return $new_name
212 0 ▶ if $COMPOSED{class}{$new_name};
Branch: 1 branch
BranchTrueFalseTotal
if $Role::Tiny::COMPOSED{"class"}{$new_name} 0 0 0
213  
214 0 return $me->_build_class_with_roles($new_name, $superclass, @roles);
215 }
216  
217 0 ▶sub _build_class_with_roles {
Subroutine _build_class_with_roles: not called CC=1 SCAR=6.9
218 0 my ($me, $new_name, $superclass, @roles) = @_;
219  
220 0 $COMPOSED{base}{$new_name} = $superclass;
221 0 @{*{_getglob("${new_name}::ISA")}} = ( $superclass );
222 0 $me->apply_roles_to_package($new_name, @roles);
223 0 $COMPOSED{class}{$new_name} = 1;
224 0 return $new_name;
225 }
226  
227 15 ▶sub _check_roles {
Subroutine _check_roles: called CC=5 SCAR=17.2
228 15 my ($me, @roles) = @_;
229 15 ▶ croak "No roles supplied!" unless @roles;
Branch: 1 branch
BranchTrueFalseTotal
unless @roles 0 15 15
230  
231 15 my %seen;
232 15 ▶ if (my @dupes = grep 1 == $seen{$_}++, @roles) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@dupes) = grep((1 == $seen{$_}++), @roles)) 0 15 15
233 0 croak "Duplicated roles: ".join(', ', @dupes);
234 }
235  
236 15 foreach my $role (@roles) {
237 15 $me->_require_module($role);
238 15 ▶ croak "${role} is not a ${me}" unless $me->is_role($role);
Branch: 1 branch
BranchTrueFalseTotal
unless $me->is_role($role) 0 15 15
239 }
240 }
241  
242 5 our %BACKCOMPAT_HACK;
243 5 $BACKCOMPAT_HACK{+__PACKAGE__} = 0;
244 15 ▶sub _want_backcompat_hack {
Subroutine _want_backcompat_hack: called CC=3 SCAR=11.2
245 15 my $me = shift;
246 return $BACKCOMPAT_HACK{$me}
247 15 ▶ if exists $BACKCOMPAT_HACK{$me};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Role::Tiny::BACKCOMPAT_HACK{$me} 10 5 15
248 5 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
249 5 ▶ $BACKCOMPAT_HACK{$me} =
Condition33%1/3
$me->can('apply_single_role_to_package') != \&Role::Tiny::apply_single_role_to_package && $me->can('role_application_steps') == \&Role::Tiny::role_application_steps
!ll&&!rl&&r
500
MC/DC0%0/2
$me->can('apply_single_role_to_package') != \&Role::Tiny::apply_single_role_to_package && $me->can('role_application_steps') == \&Role::Tiny::role_application_steps
$me->can('apply_single_role_to_package') != \&Role::Tiny::apply_single_role_to_package $me->can('role_application_steps') == \&Role::Tiny::role_application_steps
Truth table33%1/3
A && B
A= $me->can('apply_single_role_to_package') != \&Role::Tiny::apply_single_role_to_packageB= $me->can('role_application_steps') == \&Role::Tiny::role_application_steps
ABresult
0X0
100
111
250 $me->can('apply_single_role_to_package') != \&apply_single_role_to_package
251 && $me->can('role_application_steps') == \&role_application_steps
252 }
253  
254 5 our $IN_APPLY_ROLES;
255 0 ▶sub apply_single_role_to_package {
Subroutine apply_single_role_to_package: not called CC=2 SCAR=17.9
Pod undocumented
256 return
257 0 ▶ if $IN_APPLY_ROLES;
Branch: 1 branch
BranchTrueFalseTotal
if $Role::Tiny::IN_APPLY_ROLES 0 0 0
258 0 local $IN_APPLY_ROLES = 1;
259  
260 0 my ($me, $to, $role) = @_;
261 0 $me->apply_roles_to_package($to, $role);
262 }
263  
264 0 ▶sub apply_role_to_package {
Subroutine apply_role_to_package: not called CC=1 SCAR=6.9
Pod undocumented
265 0 my ($me, $to, $role) = @_;
266 0 $me->apply_roles_to_package($to, $role);
267 }
268  
269 15 ▶sub apply_roles_to_package {
Subroutine apply_roles_to_package: called CC=11 SCAR=36.6
Pod documented
270 15 my ($me, $to, @roles) = @_;
271 15 ▶ croak "Can't apply roles to object with apply_roles_to_package"
Branch: 1 branch
BranchTrueFalseTotal
if ref $to 0 15 15
272 if ref $to;
273  
274 15 $me->_check_roles(@roles);
275  
276 15 my @have_conflicts;
277 my %role_methods;
278  
279 15 ▶ if (@roles > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@roles > 1) 0 15 15
280 0 my %conflicts = %{$me->_composite_info_for(@roles)->{conflicts}};
281 0 @have_conflicts = grep $to->can($_), keys %conflicts;
282 0 delete @conflicts{@have_conflicts};
283  
284 0 ▶ if (keys %conflicts) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %conflicts) 0 0 0
285 0 ▶ my $class = $COMPOSED{base}{$to} || $to;
Condition0%0/3
$Role::Tiny::COMPOSED{'base'}{$to} || $to
l!l&&r!l&&!r
000
MC/DC0%0/2
$Role::Tiny::COMPOSED{'base'}{$to} || $to
$Role::Tiny::COMPOSED{'base'}{$to} $to
Truth table0%0/3
A || B
A= $Role::Tiny::COMPOSED{'base'}{$to}B= $to
ABresult
1X1
011
000
286 my $fail =
287 join "\n",
288 map {
289 0 "Due to a method name conflict between roles "
290 0 .join(' and ', map "'$_'", sort values %{$conflicts{$_}})
291 .", the method '$_' must be implemented by '$class'"
292 } sort keys %conflicts;
293 0 croak $fail;
294 }
295  
296 0 %role_methods = map +($_ => $me->_concrete_methods_of($_)), @roles;
297 }
298  
299 15 ▶ if (!$IN_APPLY_ROLES and _want_backcompat_hack($me)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Role::Tiny::IN_APPLY_ROLES and _want_backcompat_hack($me)) 0 15 15
Condition33%1/3
not $Role::Tiny::IN_APPLY_ROLES and _want_backcompat_hack($me)
!ll&&!rl&&r
0150
MC/DC0%0/2
not $Role::Tiny::IN_APPLY_ROLES and _want_backcompat_hack($me)
not $Role::Tiny::IN_APPLY_ROLES _want_backcompat_hack($me)
Truth table33%1/3
not(A) and B
A= not $Role::Tiny::IN_APPLY_ROLESB= _want_backcompat_hack($me)
ABresult
0X0
100
111
300 0 local $IN_APPLY_ROLES = 1;
301 0 foreach my $role (@roles) {
302 0 $me->apply_single_role_to_package($to, $role);
303 }
304 }
305  
306 15 my $role_methods;
307 15 foreach my $step ($me->role_application_steps) {
308 105 foreach my $role (@roles) {
309 # conflicting methods are supposed to be treated as required by the
310 # composed role. we don't have an actual composed role, but because
311 # we know the target class already provides them, we can instead
312 # pretend that the roles don't do for the duration of application.
313 $role_methods = $role_methods{$role} and (
314 0 (local @{$role_methods}{@have_conflicts}),
315 0 ▶ (delete @{$role_methods}{@have_conflicts}),
Branch: 1 branch
BranchTrueFalseTotal
$role_methods = $role_methods{$role} and local @{$role_methods;}{@have_conflicts}, delete @{$role_methods;}{@have_conflicts} 0 105 105
316 );
317  
318 105 $me->$step($to, $role);
319 }
320 }
321 15 $APPLIED_TO{$to}{join('|',@roles)} = 1;
322 }
323  
324 0 ▶sub _composite_info_for {
Subroutine _composite_info_for: not called CC=5 SCAR=34.0
325 0 my ($me, @roles) = @_;
326 0 ▶ $COMPOSITE_INFO{join('|', sort @roles)} ||= do {
Condition0%0/3
$Role::Tiny::COMPOSITE_INFO{join "|", sort(@roles)} ||= do { my %methods; foreach my $role (@roles) { my $this_methods = $me->_concrete_methods_of($role); $methods{$_}{$this_methods->{$_}} = $role foreach (keys %$this_methods); } ; delete $methods{$_} foreach (grep((keys %{$methods{$_};} == 1), keys %methods)); +{"conflicts", \%methods} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Role::Tiny::COMPOSITE_INFO{join "|", sort(@roles)} ||= do { my %methods; foreach my $role (@roles) { my $this_methods = $me->_concrete_methods_of($role); $methods{$_}{$this_methods->{$_}} = $role foreach (keys %$this_methods); } ; delete $methods{$_} foreach (grep((keys %{$methods{$_};} == 1), keys %methods)); +{"conflicts", \%methods} }
$Role::Tiny::COMPOSITE_INFO{join "|", sort(@roles)} do { my %methods; foreach my $role (@roles) { my $this_methods = $me->_concrete_methods_of($role); $methods{$_}{$this_methods->{$_}} = $role foreach (keys %$this_methods); } ; delete $methods{$_} foreach (grep((keys %{$methods{$_};} == 1), keys %methods)); +{"conflicts", \%methods} }
Truth table0%0/3
A ||= B
A= $Role::Tiny::COMPOSITE_INFO{join "|", sort(@roles)}B= do { my %methods; foreach my $role (@roles) { my $this_methods = $me->_concrete_methods_of($role); $methods{$_}{$this_methods->{$_}} = $role foreach (keys %$this_methods); } ; delete $methods{$_} foreach (grep((keys %{$methods{$_};} == 1), keys %methods)); +{"conflicts", \%methods} }
ABresult
1X1
011
000
327 0 my %methods;
328 0 foreach my $role (@roles) {
329 0 my $this_methods = $me->_concrete_methods_of($role);
330 0 $methods{$_}{$this_methods->{$_}} = $role for keys %$this_methods;
331 }
332 0 delete $methods{$_} for grep keys(%{$methods{$_}}) == 1, keys %methods;
333 0 +{ conflicts => \%methods }
334 };
335 }
336  
337 15 ▶sub _check_requires {
Subroutine _check_requires: called CC=6 SCAR=28.1
338 15 my ($me, $to, $name, $requires) = @_;
339 15 ▶ $requires ||= $INFO{$name}{requires} || [];
Condition40%2/5
$requires ||= $Role::Tiny::INFO{$name}{"requires"} || []
l!l&&r!l&&!r
0150
$Role::Tiny::INFO{$name}{'requires'} || []
l!l
150
MC/DC0%0/2
$requires ||= $Role::Tiny::INFO{$name}{"requires"} || []
$requires $Role::Tiny::INFO{$name}{'requires'}
Truth table33%1/3
A ||= B
A= $requiresB= $Role::Tiny::INFO{$name}{'requires'}
ABresult
1X1
011
000
340 15 ▶ if (my @requires_fail = grep !$to->can($_), @$requires) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@requires_fail) = grep((!$to->can($_)), @$requires)) 0 15 15
341 # role -> role, add to requires, role -> class, error out
342 0 ▶ if (my $to_info = $INFO{$to}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to_info = $Role::Tiny::INFO{$to}) { } 0 0 0
343 0 ▶ push @{$to_info->{requires}||=[]}, @requires_fail;
Condition0%0/2
$to_info->{"requires"} ||= []
l!l
00
MC/DC0%0/1
$to_info->{"requires"} ||= []
$to_info->{"requires"}
Truth table0%0/2
A
A= $to_info->{"requires"}
Aresult
11
00
344 } else {
345 0 croak "Can't apply ${name} to ${to} - missing ".join(', ', @requires_fail);
346 }
347 }
348 }
349  
350 10 ▶sub _non_methods {
Subroutine _non_methods: called CC=7 SCAR=25.1
351 10 my ($me, $role) = @_;
352 10 ▶ my $info = $INFO{$role} or return {};
Branch: 1 branch
BranchTrueFalseTotal
my $info = $Role::Tiny::INFO{$role} or return {} 5 5 10
353  
354 5 ▶ my %non_methods = %{ $info->{non_methods} || {} };
Condition50%1/2
$info->{'non_methods'} || {}
l!l
50
MC/DC0%0/1
$info->{'non_methods'} || {}
$info->{'non_methods'}
Truth table50%1/2
A
A= $info->{'non_methods'}
Aresult
11
00
355  
356 # this is only for backwards compatibility with older Moo, which
357 # reimplements method tracking rather than calling our method
358 5 ▶ my %not_methods = reverse %{ $info->{not_methods} || {} };
Condition50%1/2
$info->{'not_methods'} || {}
l!l
05
MC/DC0%0/1
$info->{'not_methods'} || {}
$info->{'not_methods'}
Truth table50%1/2
A
A= $info->{'not_methods'}
Aresult
11
00
359 5 ▶ return \%non_methods unless keys %not_methods;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %not_methods 5 0 5
360  
361 0 my $subs = $me->_all_subs($role);
362 0 for my $sub (grep !/\A\(/, keys %$subs) {
363 0 my $code = $subs->{$sub};
364 0 ▶ if (exists $not_methods{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $not_methods{$code}) 0 0 0
365 0 $non_methods{$sub} = $code;
366 }
367 }
368  
369 0 return \%non_methods;
370 }
371  
372 15 ▶sub _concrete_methods_of {
Subroutine _concrete_methods_of: called CC=7 SCAR=20.2
373 15 my ($me, $role) = @_;
374 15 my $info = $INFO{$role};
375  
376 return $info->{methods}
377 15 ▶ if $info && $info->{methods};
Branch: 1 branch
BranchTrueFalseTotal
if $info and $info->{"methods"} 10 5 15
Condition66%2/3
$info and $info->{"methods"}
!ll&&!rl&&r
0510
MC/DC50%1/2
$info and $info->{"methods"}
$info $info->{"methods"}
Truth table66%2/3
A and B
A= $infoB= $info->{"methods"}
ABresult
0X0
100
111
378  
379 5 my $non_methods = $me->_non_methods($role);
380  
381 5 my $subs = $me->_all_subs($role);
382 5 for my $sub (keys %$subs) {
383 35 ▶ if ( exists $non_methods->{$sub} && $non_methods->{$sub} == $subs->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $non_methods->{$sub} and $non_methods->{$sub} == $subs->{$sub}) 35 0 35
Condition33%1/3
exists $non_methods->{$sub} and $non_methods->{$sub} == $subs->{$sub}
!ll&&!rl&&r
0035
MC/DC0%0/2
exists $non_methods->{$sub} and $non_methods->{$sub} == $subs->{$sub}
exists $non_methods->{$sub} $non_methods->{$sub} == $subs->{$sub}
Truth table33%1/3
A and B
A= exists $non_methods->{$sub}B= $non_methods->{$sub} == $subs->{$sub}
ABresult
0X0
100
111
384 35 delete $subs->{$sub};
385 }
386 }
387  
388 5 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 5 0 5
389 5 $info->{methods} = $subs;
390 }
391 5 return $subs;
392 }
393  
394 0 ▶sub methods_provided_by {
Subroutine methods_provided_by: not called CC=3 SCAR=24.8
Pod undocumented
395 0 my ($me, $role) = @_;
396 0 $me->_require_module($role);
397 0 ▶ croak "${role} is not a ${me}" unless $me->is_role($role);
Branch: 1 branch
BranchTrueFalseTotal
unless $me->is_role($role) 0 0 0
398 0 ▶ sort (keys %{$me->_concrete_methods_of($role)}, @{$INFO{$role}->{requires}||[]});
Condition0%0/2
$Role::Tiny::INFO{$role}{'requires'} || []
l!l
00
MC/DC0%0/1
$Role::Tiny::INFO{$role}{'requires'} || []
$Role::Tiny::INFO{$role}{'requires'}
Truth table0%0/2
A
A= $Role::Tiny::INFO{$role}{'requires'}
Aresult
11
00
399 }
400  
401 15 ▶sub _install_methods {
Subroutine _install_methods: called CC=10 SCAR=39.5
402 15 my ($me, $to, $role) = @_;
403  
404 15 my $methods = $me->_concrete_methods_of($role);
405  
406 15 my %existing_methods;
407 15 @existing_methods{keys %{ $me->_all_subs($to) }} = ();
408  
409 # _concrete_methods_of caches its result on roles. that cache needs to be
410 # invalidated after applying roles
411 15 ▶ delete $INFO{$to}{methods} if $INFO{$to};
Branch: 1 branch
BranchTrueFalseTotal
if $Role::Tiny::INFO{$to} 0 15 15
412  
413 15 foreach my $i (keys %$methods) {
414 next
415 0 ▶ if exists $existing_methods{$i};
Branch: 1 branch
BranchTrueFalseTotal
if exists $existing_methods{$i} 0 0 0
416  
417 0 my $glob = _getglob "${to}::${i}";
418 0 *$glob = $methods->{$i};
419  
420 # overloads using method names have the method stored in the scalar slot
421 # and &overload::nil in the code slot.
422 next
423 unless $i =~ /^\(/
424 && ((defined &overload::nil && $methods->{$i} == \&overload::nil)
425 0 ▶ || (defined &overload::_nil && $methods->{$i} == \&overload::_nil));
Branch: 1 branch
BranchTrueFalseTotal
unless $i =~ /^\(/ and defined &overload::nil && $methods->{$i} == \&overload::nil || defined &overload::_nil && $methods->{$i} == \&overload::_nil 0 0 0
Condition0%0/12
$i =~ /^\(/ and defined &overload::nil && $methods->{$i} == \&overload::nil || defined &overload::_nil && $methods->{$i} == \&overload::_nil
!ll&&!rl&&r
000
defined &overload::nil and $methods->{$i} == \&overload::nil or defined &overload::_nil and $methods->{$i} == \&overload::_nil
l!l&&r!l&&!r
000
defined &overload::nil and $methods->{$i} == \&overload::nil
!ll&&!rl&&r
000
defined &overload::_nil and $methods->{$i} == \&overload::_nil
!ll&&!rl&&r
000
MC/DC0%0/5
$i =~ /^\(/ and defined &overload::nil && $methods->{$i} == \&overload::nil || defined &overload::_nil && $methods->{$i} == \&overload::_nil
$i =~ /^\(/ defined &overload::nil $methods->{$i} == \&overload::nil defined &overload::_nil $methods->{$i} == \&overload::_nil
Truth table0%0/8
A and B and C or D and E
A= $i =~ /^\(/B= defined &overload::nilC= $methods->{$i} == \&overload::nilD= defined &overload::_nilE= $methods->{$i} == \&overload::_nil
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
426  
427 0 my $overload = ${ _getglob "${role}::${i}" };
428 next
429 0 ▶ unless defined $overload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $overload 0 0 0
430  
431 0 *$glob = \$overload;
432 }
433  
434 15 $me->_install_does($to);
435 }
436  
437 15 ▶sub _install_modifiers {
Subroutine _install_modifiers: called CC=7 SCAR=36.5
438 15 my ($me, $to, $name) = @_;
439 15 ▶ return unless my $modifiers = $INFO{$name}{modifiers};
Branch: 1 branch
BranchTrueFalseTotal
unless my $modifiers = $Role::Tiny::INFO{$name}{"modifiers"} 15 0 15
440 0 my $info = $INFO{$to};
441 0 ▶ my $existing = ($info ? $info->{modifiers} : $COMPOSED{modifiers}{$to}) ||= [];
Branch: 1 branch
BranchTrueFalseTotal
$info ? : 0 0 0
Condition0%0/2
$info ? $info->{"modifiers"} : $Role::Tiny::COMPOSED{"modifiers"}{$to} ||= []
l!l
00
MC/DC0%0/1
$info ? $info->{"modifiers"} : $Role::Tiny::COMPOSED{"modifiers"}{$to} ||= []
$info ? $info->{"modifiers"} : $Role::Tiny::COMPOSED{"modifiers"}{$to}
Truth table0%0/2
A
A= $info ? $info->{"modifiers"} : $Role::Tiny::COMPOSED{"modifiers"}{$to}
Aresult
11
00
442 my @modifiers = grep {
443 0 my $modifier = $_;
444 0 !grep $_ == $modifier, @$existing;
445 0 ▶ } @{$modifiers||[]};
Condition0%0/2
$modifiers || []
l!l
00
MC/DC0%0/1
$modifiers || []
$modifiers
Truth table0%0/2
A
A= $modifiers
Aresult
11
00
446 0 push @$existing, @modifiers;
447  
448 0 ▶ if (!$info) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $info) 0 0 0
449 0 foreach my $modifier (@modifiers) {
450 0 $me->_install_single_modifier($to, @$modifier);
451 }
452 }
453 }
454  
455 5 my $vcheck_error;
456  
457 0 ▶sub _install_single_modifier {
Subroutine _install_single_modifier: not called CC=4 SCAR=30.0
458 0 my ($me, @args) = @_;
459 0 ▶ defined($vcheck_error) or $vcheck_error = do {
Branch: 1 branch
BranchTrueFalseTotal
defined $vcheck_error or $vcheck_error = do { local $@; eval { do { require Class::Method::Modifiers; "Class::Method::Modifiers"->VERSION("1.05"); 1 } } ? 0 : $@ } 0 0 0
460 0 local $@;
461 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Class::Method::Modifiers; 'Class::Method::Modifiers'->VERSION(1.05); 1 } } ? : 0 0 0
462 0 require Class::Method::Modifiers;
463 0 Class::Method::Modifiers->VERSION(1.05);
464 0 1;
465 } ? 0 : $@;
466 };
467 0 ▶ $vcheck_error and die $vcheck_error;
Branch: 1 branch
BranchTrueFalseTotal
$vcheck_error and die $vcheck_error 0 0 0
468 0 Class::Method::Modifiers::install_modifier(@args);
469 }
470  
471 0 ▶my $FALLBACK = sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
472 15 ▶sub _install_does {
Subroutine _install_does: called CC=8 SCAR=27.7
473 15 my ($me, $to) = @_;
474  
475 # only add does() method to classes
476 15 ▶ return if $me->is_role($to);
Branch: 1 branch
BranchTrueFalseTotal
if $me->is_role($to) 0 15 15
477  
478 15 my $does = $me->can('does_role');
479 # add does() only if they don't have one
480 0 ▶ *{_getglob "${to}::does"} = $does unless $to->can('does');
Branch: 1 branch
BranchTrueFalseTotal
unless $to->can("does") 0 15 15
481  
482 return
483 15 ▶ if $to->can('DOES') and $to->can('DOES') != (UNIVERSAL->can('DOES') || 0);
Branch: 1 branch
BranchTrueFalseTotal
if $to->can("DOES") and $to->can("DOES") != ("UNIVERSAL"->can("DOES") || 0) 0 15 15
Condition40%2/5
$to->can("DOES") and $to->can("DOES") != ("UNIVERSAL"->can("DOES") || 0)
!ll&&!rl&&r
0150
'UNIVERSAL'->can('DOES') || 0
l!l
150
MC/DC0%0/2
$to->can("DOES") and $to->can("DOES") != ("UNIVERSAL"->can("DOES") || 0)
$to->can("DOES") $to->can("DOES") != ("UNIVERSAL"->can("DOES") || 0)
MC/DC0%0/1
'UNIVERSAL'->can('DOES') || 0
'UNIVERSAL'->can('DOES')
Truth table33%1/3
A and B
A= $to->can("DOES")B= $to->can("DOES") != ("UNIVERSAL"->can("DOES") || 0)
ABresult
0X0
100
111
Truth table50%1/2
A
A= 'UNIVERSAL'->can('DOES')
Aresult
11
00
484  
485 15 ▶ my $existing = $to->can('DOES') || $to->can('isa') || $FALLBACK;
Condition33%2/6
$to->can('DOES') || $to->can('isa') || $FALLBACK
l!l&&r!l&&!r
1500
$to->can("DOES") or $to->can("isa")
l!l&&r!l&&!r
1500
MC/DC0%0/3
$to->can('DOES') || $to->can('isa') || $FALLBACK
$to->can("DOES") $to->can("isa") $FALLBACK
Truth table25%1/4
A or B || C
A= $to->can("DOES")B= $to->can("isa")C= $FALLBACK
ABCresult
1XX1
01X1
0011
0000
486 0 ▶ my $new_sub = sub {
Subroutine DOES: not called CC=2 SCAR=17.9
Subroutine __ANON__: not called CC=2 SCAR=17.9
487 0 my ($proto, $role) = @_;
488 0 ▶ $proto->$does($role) or $proto->$existing($role);
Branch: 2 branches
BranchTrueFalseTotal
$proto->$does($role) or $proto->$existing($role) 0 0 0
$proto->$does($role) or $proto->$existing($role) 0 0 0
489 15 };
490 5 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
491 15 return *{_getglob "${to}::DOES"} = $new_sub;
492 }
493  
494 # optimize for newer perls
495 require mro
496 5 ▶ if "$]" >= 5.009_005;
Branch: 1 branch
BranchTrueFalseTotal
if "$]" >= "5.009005" 5 0 5
497  
498 sub _linear_isa($;$);
499  
500 5 ▶if (defined &mro::get_linear_isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &mro::get_linear_isa) { } 5 0 5
501 5 ▶ no warnings 'prototype';
Subroutine BEGIN: called CC=1 SCAR=0.0
502 5 *_linear_isa = \&mro::get_linear_isa;
503 }
504 else {
505 0 my $e;
506 {
507 0 local $@;
508 # this routine is simplified and not fully compatible with mro::get_linear_isa
509 # but for our use the order doesn't matter, so we don't need to care
510 0 ▶ eval <<'END_CODE' or $e = $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _linear_isa(\$;\$) {\n if (defined &mro::get_linear_isa) {\n no warnings 'redefine', 'prototype';\n *_linear_isa = \\&mro::get_linear_isa;\n goto &mro::get_linear_isa;\n }\n\n my \@check = shift;\n my \@lin;\n\n my %found;\n while (defined(my \$check = shift \@check)) {\n push \@lin, \$check;\n no strict 'refs';\n unshift \@check, grep !\$found{\$_}++, \@{\"\$check\\::ISA\"};\n }\n\n return \\\@lin;\n}\n\n1;\n" or $e = $@ 0 0 0
511 sub _linear_isa($;$) {
512 if (defined &mro::get_linear_isa) {
513 no warnings 'redefine', 'prototype';
514 *_linear_isa = \&mro::get_linear_isa;
515 goto &mro::get_linear_isa;
516 }
517  
518 my @check = shift;
519 my @lin;
520  
521 my %found;
522 while (defined(my $check = shift @check)) {
523 push @lin, $check;
524 no strict 'refs';
525 unshift @check, grep !$found{$_}++, @{"$check\::ISA"};
526 }
527  
528 return \@lin;
529 }
530  
531 1;
532 END_CODE
533 }
534 0 ▶ die $e if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
535 }
536  
537 0 ▶sub does_role {
Subroutine does_role: not called CC=4 SCAR=30.0
Pod documented
538 0 my ($proto, $role) = @_;
539 0 ▶ foreach my $class (@{_linear_isa(ref($proto)||$proto)}) {
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
540 0 ▶ return 1 if exists $APPLIED_TO{$class}{$role};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Role::Tiny::APPLIED_TO{$class}{$role} 0 0 0
541 }
542 0 return 0;
543 }
544  
545 194 ▶sub is_role {
Subroutine is_role: called CC=5 SCAR=20.9
Pod documented
546 194 my ($me, $role) = @_;
547 return !!($INFO{$role} && (
548 $INFO{$role}{is_role}
549 # these are for backward compatibility with older Moo that overrode some
550 # methods without calling the originals, thus not getting is_role set
551 || $INFO{$role}{requires}
552 || $INFO{$role}{not_methods}
553 || $INFO{$role}{non_methods}
554 194 ▶ ));
Condition41%5/12
$Role::Tiny::INFO{$role} && ($Role::Tiny::INFO{$role}{'is_role'} || $Role::Tiny::INFO{$role}{'requires'} || $Role::Tiny::INFO{$role}{'not_methods'} || $Role::Tiny::INFO{$role}{'non_methods'})
!ll&&!rl&&r
164030
$Role::Tiny::INFO{$role}{"is_role"} or $Role::Tiny::INFO{$role}{"requires"} or $Role::Tiny::INFO{$role}{"not_methods"} or $Role::Tiny::INFO{$role}{"non_methods"}
l!l&&r!l&&!r
3000
$Role::Tiny::INFO{$role}{"is_role"} or $Role::Tiny::INFO{$role}{"requires"} or $Role::Tiny::INFO{$role}{"not_methods"}
l!l&&r!l&&!r
3000
$Role::Tiny::INFO{$role}{"is_role"} or $Role::Tiny::INFO{$role}{"requires"}
l!l&&r!l&&!r
3000
MC/DC20%1/5
$Role::Tiny::INFO{$role} && ($Role::Tiny::INFO{$role}{'is_role'} || $Role::Tiny::INFO{$role}{'requires'} || $Role::Tiny::INFO{$role}{'not_methods'} || $Role::Tiny::INFO{$role}{'non_methods'})
$Role::Tiny::INFO{$role} $Role::Tiny::INFO{$role}{"is_role"} $Role::Tiny::INFO{$role}{"requires"} $Role::Tiny::INFO{$role}{"not_methods"} $Role::Tiny::INFO{$role}{"non_methods"}
Truth table33%2/6
A && B or C or D or E
A= $Role::Tiny::INFO{$role}B= $Role::Tiny::INFO{$role}{"is_role"}C= $Role::Tiny::INFO{$role}{"requires"}D= $Role::Tiny::INFO{$role}{"not_methods"}E= $Role::Tiny::INFO{$role}{"non_methods"}
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
555 }
556  
557 5 1;
558 __END__
« lib/Skilletor/Report.pm ↑ Summary /usr/local/lib/perl5/5.44.0/CPAN/Meta/Validator.pm »