/usr/local/lib/perl5/site_perl/5.44.0/Module/Runtime.pm

filter: Statementstmt 57.3% 39 / 68 Branchbran 19.4% 7 / 36 Conditioncond 13.3% 2 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 66.6% 10 / 15 Podpod 100% 9 / 9 totaltotal 44.0% 67 / 152 CC 25 SCAR 23.9
CC
25
Cov
40%
use_package_optimistically
30.0
compose_module_name
20.0
is_module_spec
12.0
CRAP 10.9
« lib/Skilletor/State.pm ↑ Summary lib/Skilletor/Tar.pm »
1 package Module::Runtime;
2  
3 # Don't "use 5.006" here, because Perl 5.15.6 will load feature.pm if
4 # the version check is done that way.
5 7 ▶BEGIN { require 5.006; }
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # Don't "use warnings" here, to avoid dependencies. Do standardise the
7 # warning status by lexical override; unfortunately the only safe bitset
8 # to build in is the empty set, equivalent to "no warnings".
9 7 ▶BEGIN { ${^WARNING_BITS} = ""; }
Subroutine BEGIN: called CC=1 SCAR=0.0
10 # Don't "use strict" here, to avoid dependencies.
11  
12 7 our $VERSION = '0.018';
13  
14 # Don't use Exporter here, to avoid dependencies.
15 7 our @EXPORT_OK = qw(
16 $module_name_rx is_module_name is_valid_module_name check_module_name
17 module_notional_filename require_module
18 use_module use_package_optimistically
19 $top_module_spec_rx $sub_module_spec_rx
20 is_module_spec is_valid_module_spec check_module_spec
21 compose_module_name
22 );
23 7 my %export_ok = map { ($_ => undef) } @EXPORT_OK;
24 7 ▶sub import {
Subroutine import: called CC=5 SCAR=18.3
25 7 my $me = shift;
26 7 my $callpkg = caller;
27 7 my $errs = "";
28 7 foreach(@_) {
29 7 ▶ if(exists $export_ok{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $export_ok{$_}) { } 7 0 7
30 # We would need to do "no strict 'refs'" here
31 # if we had enabled strict at file scope.
32 7 ▶ if(/\A\$(.*)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\A\$(.*)\z/s) { } 0 7 7
33 0 *{$callpkg."::".$1} = \$$1;
34 } else {
35 7 *{$callpkg."::".$_} = \&$_;
36 }
37 } else {
38 0 $errs .= "\"$_\" is not exported by the $me module\n";
39 }
40 }
41 7 ▶ if($errs ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($errs ne "") 0 7 7
42 0 die sprintf "%sCan't continue after import errors at %s line %u.\n",
43 $errs, (caller)[1,2];
44 }
45 }
46  
47 # Logic duplicated from Params::Classify. Duplicating it here avoids
48 # an extensive and potentially circular dependency graph.
49 14 ▶sub _is_string($) {
Subroutine _is_string: called CC=2 SCAR=8.1
50 14 my($arg) = @_;
51 14 ▶ return defined($arg) && ref(\$arg) eq "SCALAR";
Condition33%1/3
defined $arg && ref \$arg eq 'SCALAR'
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $arg && ref \$arg eq 'SCALAR'
defined $arg ref \$arg eq 'SCALAR'
Truth table33%1/3
A && B
A= defined $argB= ref \$arg eq 'SCALAR'
ABresult
0X0
100
111
52 }
53  
54 7 our $module_name_rx = qr{[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*};
55  
56 7 my $qual_module_spec_rx =
57 qr{(?:/|::)[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*};
58  
59 7 my $unqual_top_module_spec_rx =
60 qr{[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*};
61  
62 7 our $top_module_spec_rx = qr{$qual_module_spec_rx|$unqual_top_module_spec_rx};
63  
64 7 my $unqual_sub_module_spec_rx = qr{[0-9A-Z_a-z]+(?:(?:/|::)[0-9A-Z_a-z]+)*};
65  
66 7 our $sub_module_spec_rx = qr{$qual_module_spec_rx|$unqual_sub_module_spec_rx};
67  
68 14 ▶sub is_module_name($) { _is_string($_[0]) && $_[0] =~ /\A$module_name_rx\z/o }
Subroutine is_module_name: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
&_is_string($_[0]) and $_[0] =~ /\A$module_name_rx\z/o 14 0 14
69  
70 7 *is_valid_module_name = \&is_module_name;
71  
72 14 ▶sub check_module_name($) {
Subroutine check_module_name: called CC=3 SCAR=17.3
Pod documented
73 14 ▶ unless(&is_module_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_module_name) 0 14 14
74 0 ▶ die +(_is_string($_[0]) ? "`$_[0]'" : "argument").
Branch: 1 branch
BranchTrueFalseTotal
&_is_string($_[0]) ? : 0 0 0
75 " is not a module name\n";
76 }
77 }
78  
79 14 ▶sub module_notional_filename($) {
Subroutine module_notional_filename: called CC=1 SCAR=0.0
Pod documented
80 14 &check_module_name;
81 14 my($name) = @_;
82 14 $name =~ s{::}{/}g;
83 14 return $name.".pm";
84 }
85  
86 # Don't "use constant" here, to avoid dependencies.
87 7 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=23.0
88 ## no critic (ValuesAndExpressions::ProhibitMismatchedOperators)
89 *_WORK_AROUND_HINT_LEAKAGE =
90 "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
91 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
92 7 ▶ *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.009 ? : 0 7 7
93 }
94  
95 7 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
96 7 if(_WORK_AROUND_BROKEN_MODULE_STATE) {
97 eval <<'END_CODE' or die $@; ## no critic (BuiltinFunctions::ProhibitStringyEval)
98 sub Module::Runtime::__GUARD__::DESTROY {
99 delete $INC{$_[0]->[0]} if @{$_[0]};
100 }
101 1;
102 END_CODE
103 }
104 }
105  
106 14 ▶sub require_module($) {
Subroutine require_module: called CC=1 SCAR=0.0
Pod documented
107 # Localise %^H to work around [perl #68590], where the bug exists
108 # and this is a satisfactory workaround. The bug consists of
109 # %^H state leaking into each required module, polluting the
110 # module's lexical state.
111 14 local %^H if _WORK_AROUND_HINT_LEAKAGE;
112 14 if(_WORK_AROUND_BROKEN_MODULE_STATE) {
113 my $notional_filename = &module_notional_filename;
114 my $guard = bless([ $notional_filename ],
115 "Module::Runtime::__GUARD__");
116 my $result = CORE::require($notional_filename);
117 pop @$guard;
118 return $result;
119 } else {
120 14 return scalar(CORE::require(&module_notional_filename));
121 }
122 }
123  
124 0 ▶sub use_module($;$) {
Subroutine use_module: not called CC=2 SCAR=17.9
Pod documented
125 0 my($name, $version) = @_;
126 0 require_module($name);
127 0 ▶ $name->VERSION($version) if @_ >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 0 0 0
128 0 return $name;
129 }
130  
131 7 my $FILE = __FILE__;
132 0 ▶sub use_package_optimistically($;$) {
Subroutine use_package_optimistically: not called CC=5 SCAR=34.0
Pod documented
133 0 my($name, $version) = @_;
134 0 my $fn = module_notional_filename($name);
135 eval {
136 0 local $SIG{__DIE__};
137 0 require_module($name);
138 0 1;
139 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__DIE__"}; &require_module($name); 1 } } or do { die $@ if not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s or $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx } 0 0 0
140 0 ▶ die $@ if (
Branch: 1 branch
BranchTrueFalseTotal
if not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s or $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx 0 0 0
Condition0%0/3
not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s or $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx
l!l&&r!l&&!r
000
MC/DC0%0/2
not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s or $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx
not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx
Truth table0%0/3
not(A) or B
A= not $@ =~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/sB= $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/mx
ABresult
1X1
011
000
141 $@ !~ /\ACan't locate \Q$fn\E .+ at \Q$FILE\E line/s ||
142 $@ =~ /^Compilation\ failed\ in\ require\ at\ \Q$FILE\E\ line/xm
143 );
144 };
145 0 ▶ $name->VERSION($version) if @_ >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 0 0 0
146 0 return $name;
147 }
148  
149 0 ▶sub is_module_spec($$) {
Subroutine is_module_spec: not called CC=3 SCAR=24.8
Pod documented
150 0 my($prefix, $spec) = @_;
151 0 ▶ return _is_string($spec) && (
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
Condition0%0/3
&_is_string($spec) && ($prefix ? $spec =~ /\A$sub_module_spec_rx\z/o : $spec =~ /\A$top_module_spec_rx\z/o)
!ll&&!rl&&r
000
MC/DC0%0/2
&_is_string($spec) && ($prefix ? $spec =~ /\A$sub_module_spec_rx\z/o : $spec =~ /\A$top_module_spec_rx\z/o)
&_is_string($spec) ($prefix ? $spec =~ /\A$sub_module_spec_rx\z/o : $spec =~ /\A$top_module_spec_rx\z/o)
Truth table0%0/3
A && B
A= &_is_string($spec)B= ($prefix ? $spec =~ /\A$sub_module_spec_rx\z/o : $spec =~ /\A$top_module_spec_rx\z/o)
ABresult
0X0
100
111
152 $prefix ? $spec =~ /\A$sub_module_spec_rx\z/o
153 : $spec =~ /\A$top_module_spec_rx\z/o
154 );
155 }
156  
157 7 *is_valid_module_spec = \&is_module_spec;
158  
159 0 ▶sub check_module_spec($$) {
Subroutine check_module_spec: not called CC=3 SCAR=24.8
Pod documented
160 0 ▶ unless(&is_module_spec) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_module_spec) 0 0 0
161 0 ▶ die +(_is_string($_[1]) ? "`$_[1]'" : "argument").
Branch: 1 branch
BranchTrueFalseTotal
&_is_string($_[1]) ? : 0 0 0
162 " is not a module specification\n";
163 }
164 }
165  
166 0 ▶sub compose_module_name($$) {
Subroutine compose_module_name: not called CC=4 SCAR=30.0
Pod documented
167 0 my($prefix, $spec) = @_;
168 0 ▶ check_module_name($prefix) if defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prefix 0 0 0
169 0 &check_module_spec;
170 0 ▶ if($spec =~ s{\A(?:/|::)}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ s[\A(?:/|::)][]) { } 0 0 0
171 # OK
172 } else {
173 0 ▶ $spec = $prefix."::".$spec if defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prefix 0 0 0
174 }
175 0 $spec =~ s{/}{::}g;
176 0 return $spec;
177 }
178  
179 7 1;
180  
181 __END__
« lib/Skilletor/State.pm ↑ Summary lib/Skilletor/Tar.pm »