/usr/local/lib/perl5/site_perl/5.44.0/Moo/_Utils.pm

filter: Statementstmt 65.4% 104 / 159 Branchbran 33.8% 23 / 68 Conditioncond 23.2% 10 / 43 MC/DCmcdc 4.7% 1 / 21 Subroutinesub 78.7% 26 / 33 Podpod n/a totaltotal 50.6% 164 / 324 CC 53 SCAR 30.4
CC
53
Cov
51%
_install_modifier
56.0
BEGIN
45.5
_load_module
45.5
CRAP 20.9
« /usr/local/lib/perl5/site_perl/5.44.0/JSON/MaybeXS.pm ↑ Summary /usr/local/lib/perl5/5.44.0/parent.pm »
1 package Moo::_Utils;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 {
6 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1376 ▶ sub _getglob { \*{$_[0]} }
Subroutine _getglob: called CC=1 SCAR=0.0
9 159 ▶ sub _getstash { \%{"$_[0]::"} }
Subroutine _getstash: called CC=1 SCAR=0.0
10 }
11  
12 7 ▶BEGIN {
Subroutine BEGIN: called CC=14 SCAR=38.2
13 7 my ($su, $sn);
14 $su = $INC{'Sub/Util.pm'} && defined &Sub::Util::set_subname
15 or $sn = $INC{'Sub/Name.pm'}
16 7 or $su = eval { require Sub::Util; } && defined &Sub::Util::set_subname
17 0 ▶ or $sn = eval { require Sub::Name; };
Branch: 1 branch
BranchTrueFalseTotal
$su = $INC{"Sub/Util.pm"} && defined &Sub::Util::set_subname or $sn = $INC{"Sub/Name.pm"} or $su = eval { do { require Sub::Util } } && defined &Sub::Util::set_subname or $sn = eval { do { require Sub::Name } } 7 0 7
Condition33%4/12
$su = $INC{"Sub/Util.pm"} && defined &Sub::Util::set_subname or $sn = $INC{"Sub/Name.pm"} or $su = eval { do { require Sub::Util } } && defined &Sub::Util::set_subname
l!l&&r!l&&!r
070
$su = $INC{"Sub/Util.pm"} && defined &Sub::Util::set_subname or $sn = $INC{"Sub/Name.pm"}
l!l&&r!l&&!r
007
$INC{'Sub/Util.pm'} && defined &Sub::Util::set_subname
!ll&&!rl&&r
700
eval { do { require Sub::Util } } && defined &Sub::Util::set_subname
!ll&&!rl&&r
007
MC/DC0%0/5
$su = $INC{"Sub/Util.pm"} && defined &Sub::Util::set_subname or $sn = $INC{"Sub/Name.pm"} or $su = eval { do { require Sub::Util } } && defined &Sub::Util::set_subname
$INC{'Sub/Util.pm'} defined &Sub::Util::set_subname $sn = $INC{"Sub/Name.pm"} eval { do { require Sub::Util } } defined &Sub::Util::set_subname
Truth table11%1/9
A && B or C or D && E
A= $INC{'Sub/Util.pm'}B= defined &Sub::Util::set_subnameC= $sn = $INC{"Sub/Name.pm"}D= eval { do { require Sub::Util } }E= defined &Sub::Util::set_subname
ABCDEresult
11XXX1
0X1XX1
101XX1
0X0111
100111
0X00X0
0X0100
1000X0
100100
18  
19 *_subname = $su ? \&Sub::Util::set_subname
20 : $sn ? \&Sub::Name::subname
21 0 ▶ : sub { $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=2.6
Branch: 2 branches
BranchTrueFalseTotal
$su ? : 7 0 7
$sn ? : 0 0 0
22 7 ▶ *_CAN_SUBNAME = ($su || $sn) ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
$su || $sn ? : 7 0 7
Condition33%1/3
$su or $sn
l!l&&r!l&&!r
700
MC/DC0%0/2
$su or $sn
$su $sn
Truth table33%1/3
A or B
A= $suB= $sn
ABresult
1X1
011
000
23  
24 7 ▶ *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.009 ? : 0 7 7
25 *_WORK_AROUND_HINT_LEAKAGE
26 = "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
27 7 ▶ ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001) ? : 0 7 7
Condition16%1/6
"$]" < "5.011" and not "$]" >= "5.009004" && "$]" < "5.010001"
!ll&&!rl&&r
700
"$]" >= 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
28  
29 7 my $module_name_rx = qr/\A(?!\d)\w+(?:::\w+)*\z/;
30 0 ▶ *_module_name_rx = sub(){$module_name_rx};
Subroutine __ANON__: not called CC=1 SCAR=1.2
31 }
32  
33 7 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 7 ▶BEGIN { *import = \&Exporter::import }
Subroutine BEGIN: called CC=1 SCAR=0.0
35 7 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 7 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 # this should be empty, but some CPAN modules expect these
40 7 our @EXPORT = qw(
41 _install_coderef
42 _load_module
43 );
44  
45 7 our @EXPORT_OK = qw(
46 _check_tracked
47 _getglob
48 _getstash
49 _install_coderef
50 _install_modifier
51 _install_tracked
52 _load_module
53 _maybe_load_module
54 _module_name_rx
55 _name_coderef
56 _set_loaded
57 _unimport_coderefs
58 _linear_isa
59 _in_global_destruction
60 _in_global_destruction_code
61 );
62  
63 7 my %EXPORTS;
64  
65 0 ▶sub _install_modifier {
Subroutine _install_modifier: not called CC=7 SCAR=40.3
66 0 my $target = $_[0];
67 0 my $type = $_[1];
68 0 my $code = $_[-1];
69 0 my @names = @_[2 .. $#_ - 1];
70  
71 0 ▶ @names = @{ $names[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ref $names[0] eq "ARRAY" 0 0 0
72 if ref($names[0]) eq 'ARRAY';
73  
74 0 my @tracked = _check_tracked($target, \@names);
75  
76 0 ▶ if ($INC{'Sub/Defer.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Sub/Defer.pm"}) 0 0 0
77 0 for my $name (@names) {
78 # CMM will throw for us if it doesn't exist
79 0 ▶ if (my $to_modify = $target->can($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to_modify = $target->can($name)) 0 0 0
80 0 Sub::Defer::undefer_sub($to_modify);
81 }
82 }
83 }
84  
85 0 require Class::Method::Modifiers;
86 0 Class::Method::Modifiers::install_modifier(@_);
87  
88 0 ▶ if (@tracked) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tracked) 0 0 0
89 0 my $exports = $EXPORTS{$target};
90 weaken($exports->{$_} = $target->can($_))
91 0 for @tracked;
92 }
93  
94 0 return;
95 }
96  
97 882 ▶sub _install_tracked {
Subroutine _install_tracked: called CC=1 SCAR=0.0
98 882 my ($target, $name, $code) = @_;
99 882 my $from = caller;
100 882 weaken($EXPORTS{$target}{$name} = $code);
101 882 _install_coderef("${target}::${name}", "${from}::${name}", $code);
102 }
103  
104 0 ▶sub Moo::_Util::__GUARD__::DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
105 0 ▶ delete $INC{$_[0]->[0]} if @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if @{$_[0];} 0 0 0
106 }
107  
108 24 ▶sub _require {
Subroutine _require: called CC=3 SCAR=13.2
109 24 my ($file) = @_;
110 24 my $guard = _WORK_AROUND_BROKEN_MODULE_STATE
111 && bless([ $file ], 'Moo::_Util::__GUARD__');
112 24 local %^H if _WORK_AROUND_HINT_LEAKAGE;
113 24 ▶ if (!eval { require $file; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require $file; 1 } }) 0 24 24
114 0 ▶ my $e = $@ || "Can't locate $file";
Condition0%0/2
$@ || "Can't locate $file"
l!l
00
MC/DC0%0/1
$@ || "Can't locate $file"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
115 0 my $me = __FILE__;
116 0 $e =~ s{ at \Q$me\E line \d+\.\n\z}{};
117 0 return $e;
118 }
119 24 pop @$guard if _WORK_AROUND_BROKEN_MODULE_STATE;
120 24 return undef;
121 }
122  
123 111 ▶sub _load_module {
Subroutine _load_module: called CC=11 SCAR=38.2
124 111 my ($module) = @_;
125 111 ▶ croak qq{"$module" is not a module name!}
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /\A(?!\d)\w+(?:::\w+)*\z/ 0 111 111
126 unless $module =~ _module_name_rx;
127 111 (my $file = "$module.pm") =~ s{::}{/}g;
128 return 1
129 111 ▶ if $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$file} 94 17 111
130  
131 17 my $e = _require $file;
132 17 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 17 0 17
133 if !defined $e;
134  
135 0 ▶ croak $e
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\ACan't locate \Q$file\E / 0 0 0
136 if $e !~ /\ACan't locate \Q$file\E /;
137  
138 # can't just ->can('can') because a sub-package Foo::Bar::Baz
139 # creates a 'Baz::' key in Foo::Bar's symbol table
140 0 ▶ my $stash = _getstash($module)||{};
Condition0%0/2
_getstash($module) || {}
l!l
00
MC/DC0%0/1
_getstash($module) || {}
_getstash($module)
Truth table0%0/2
A
A= _getstash($module)
Aresult
11
00
141 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 0 ▶ return 1 if grep +exists &{"${module}::$_"}, grep !/::\z/, keys %$stash;
Branch: 1 branch
BranchTrueFalseTotal
if grep exists(&{"${module}::$_";}), grep((!/::\z/), keys %$stash) 0 0 0
143 return 1
144 0 ▶ if $INC{"Moose.pm"} && Class::MOP::class_of($module)
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Moose.pm"} and Class::MOP::class_of($module) or "Mouse::Util"->can("find_meta") and Mouse::Util::find_meta($module) 0 0 0
Condition0%0/9
$INC{"Moose.pm"} and Class::MOP::class_of($module) or "Mouse::Util"->can("find_meta") and Mouse::Util::find_meta($module)
l!l&&r!l&&!r
000
$INC{"Moose.pm"} and Class::MOP::class_of($module)
!ll&&!rl&&r
000
"Mouse::Util"->can("find_meta") and Mouse::Util::find_meta($module)
!ll&&!rl&&r
000
MC/DC0%0/4
$INC{"Moose.pm"} and Class::MOP::class_of($module) or "Mouse::Util"->can("find_meta") and Mouse::Util::find_meta($module)
$INC{"Moose.pm"} Class::MOP::class_of($module) "Mouse::Util"->can("find_meta") Mouse::Util::find_meta($module)
Truth table0%0/7
A and B or C and D
A= $INC{"Moose.pm"}B= Class::MOP::class_of($module)C= "Mouse::Util"->can("find_meta")D= Mouse::Util::find_meta($module)
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
145 or Mouse::Util->can('find_meta') && Mouse::Util::find_meta($module);
146  
147 0 croak $e;
148 }
149  
150 7 our %MAYBE_LOADED;
151 7 ▶sub _maybe_load_module {
Subroutine _maybe_load_module: called CC=4 SCAR=16.6
152 7 my $module = $_[0];
153 return $MAYBE_LOADED{$module}
154 7 ▶ if exists $MAYBE_LOADED{$module};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Moo::_Utils::MAYBE_LOADED{$module} 0 7 7
155 7 (my $file = "$module.pm") =~ s{::}{/}g;
156  
157 7 my $e = _require $file;
158 7 ▶ if (!defined $e) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $e) { } 7 0 7
elsif (not $e =~ /\ACan't locate \Q$file\E /) { } 0 0 0
159 7 return $MAYBE_LOADED{$module} = 1;
160 }
161 elsif ($e !~ /\ACan't locate \Q$file\E /) {
162 0 warn "$module exists but failed to load with error: $e";
163 }
164 0 return $MAYBE_LOADED{$module} = 0;
165 }
166  
167 7 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=25.7
168 # optimize for newer perls
169 require mro
170 7 ▶ if "$]" >= 5.009_005;
Branch: 1 branch
BranchTrueFalseTotal
if "$]" >= "5.009005" 7 0 7
171  
172 7 ▶ if (defined &mro::get_linear_isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &mro::get_linear_isa) { } 7 0 7
173 7 *_linear_isa = \&mro::get_linear_isa;
174 }
175 else {
176 0 my $e;
177 {
178 0 local $@;
179 0 ▶ eval <<'END_CODE' or $e = $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _linear_isa(\$;\$) {\n my \$class = shift;\n my \$type = shift || exists \$Class::C3::MRO{\$class} ? 'c3' : 'dfs';\n\n if (\$type eq 'c3') {\n require Class::C3;\n return [Class::C3::calculateMRO(\$class)];\n }\n\n my \@check = (\$class);\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
180 sub _linear_isa($;$) {
181 my $class = shift;
182 my $type = shift || exists $Class::C3::MRO{$class} ? 'c3' : 'dfs';
183  
184 if ($type eq 'c3') {
185 require Class::C3;
186 return [Class::C3::calculateMRO($class)];
187 }
188  
189 my @check = ($class);
190 my @lin;
191  
192 my %found;
193 while (defined(my $check = shift @check)) {
194 push @lin, $check;
195 no strict 'refs';
196 unshift @check, grep !$found{$_}++, @{"$check\::ISA"};
197 }
198  
199 return \@lin;
200 }
201  
202 1;
203 END_CODE
204 }
205 0 ▶ die $e if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
206 }
207 }
208  
209 7 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=18.9
210 7 ▶ my $gd_code
Branch: 2 branches
BranchTrueFalseTotal
"$]" >= 5.014 ? : 7 0 7
_maybe_load_module('Devel::GlobalDestruction::XS') ? : 0 0 0
211 = "$]" >= 5.014
212 ? q[${^GLOBAL_PHASE} eq 'DESTRUCT']
213 : _maybe_load_module('Devel::GlobalDestruction::XS')
214 ? 'Devel::GlobalDestruction::XS::in_global_destruction()'
215 : 'do { use B (); ${B::main_cv()} == 0 }';
216 0 ▶ *_in_global_destruction_code = sub () { $gd_code };
Subroutine __ANON__: not called CC=1 SCAR=1.2
217 0 ▶ eval "sub _in_global_destruction () { $gd_code }; 1"
Subroutine _in_global_destruction: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
eval "sub _in_global_destruction () { $gd_code }; 1" or die $@ 7 0 7
218 or die $@;
219 }
220  
221 147 ▶sub _set_loaded {
Subroutine _set_loaded: called CC=2 SCAR=8.1
222 147 (my $file = "$_[0].pm") =~ s{::}{/}g;
223 147 ▶ $INC{$file} ||= $_[1];
Condition33%1/3
$INC{$file} ||= $_[1]
l!l&&r!l&&!r
14700
MC/DC0%0/2
$INC{$file} ||= $_[1]
$INC{$file} $_[1]
Truth table33%1/3
A ||= B
A= $INC{$file}B= $_[1]
ABresult
1X1
011
000
224 }
225  
226 927 ▶sub _install_coderef {
Subroutine _install_coderef: called CC=2 SCAR=7.1
227 927 my ($glob, $code) = (_getglob($_[0]), _name_coderef(@_));
228 7 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
229 927 ▶ if (*{$glob}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*{$glob;}{'CODE'}) { } 0 927 927
230 0 *{$glob} = $code;
231 }
232 # perl will sometimes warn about mismatched prototypes coming from the
233 # inheritance cache, so disable them if we aren't redefining a sub
234 else {
235 7 ▶ no warnings 'prototype';
Subroutine BEGIN: called CC=1 SCAR=0.0
236 927 *{$glob} = $code;
237 }
238 }
239  
240 942 ▶sub _name_coderef {
Subroutine _name_coderef: called CC=2 SCAR=6.9
241 942 ▶ shift if @_ > 2; # three args is (target, name, sub)
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 882 60 942
242 942 _CAN_SUBNAME ? _subname(@_) : $_[1];
243 }
244  
245 10 ▶sub _check_tracked {
Subroutine _check_tracked: called CC=5 SCAR=16.6
246 10 my ($target, $names) = @_;
247 10 my $stash = _getstash($target);
248 10 ▶ my $exports = $EXPORTS{$target}
Branch: 1 branch
BranchTrueFalseTotal
my $exports = $EXPORTS{$target} or return 5 5 10
249 or return;
250  
251 5 ▶ $names = [keys %$exports]
Branch: 1 branch
BranchTrueFalseTotal
unless $names 0 5 5
252 if !$names;
253 my %rev =
254 map +($exports->{$_} => $_),
255 5 grep defined $exports->{$_},
256 keys %$exports;
257  
258 return
259 grep {
260 5 my $g = $stash->{$_};
261 35 ▶ $g && defined &$g && exists $rev{\&$g};
Condition50%3/6
$g && defined &$g && exists $rev{\&$g}
!ll&&!rl&&r
0530
$g and defined &$g
!ll&&!rl&&r
0035
MC/DC33%1/3
$g && defined &$g && exists $rev{\&$g}
$g defined &$g exists $rev{\&$g}
Truth table50%2/4
A and B && C
A= $gB= defined &$gC= exists $rev{\&$g}
ABCresult
0XX0
10X0
1100
1111
262 }
263 @$names;
264 }
265  
266 0 ▶sub _unimport_coderefs {
Subroutine _unimport_coderefs: not called CC=4 SCAR=25.3
267 0 my ($target) = @_;
268  
269 0 my $stash = _getstash($target);
270 0 my @exports = _check_tracked($target);
271  
272 0 foreach my $name (@exports) {
273 0 my $old = delete $stash->{$name};
274 0 my $full_name = join('::',$target,$name);
275 # Copy everything except the code slot back into place (e.g. $has)
276 0 foreach my $type (qw(SCALAR HASH ARRAY IO)) {
277 0 ▶ next unless defined(*{$old}{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{$old;}{$type} 0 0 0
278 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
279 0 *$full_name = *{$old}{$type};
280 }
281 }
282 }
283  
284 7 ▶if ($Config::Config{useithreads}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"useithreads"}) 0 7 7
285 0 require Moo::HandleMoose::_TypeMap;
286 }
287  
288 7 1;
« /usr/local/lib/perl5/site_perl/5.44.0/JSON/MaybeXS.pm ↑ Summary /usr/local/lib/perl5/5.44.0/parent.pm »