/usr/local/lib/perl5/5.44.0/Exporter/Heavy.pm

filter: Statementstmt 0.0% 0 / 134 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 260 CC 56 SCAR 73.4
CC
56
Cov
0%
heavy_export
2162.0
_push_tags
30.0
_rebuild_cache
20.0
CRAP 1534.2
« /usr/local/lib/perl5/5.44.0/x86_64-linux/re.pm ↑ Summary /usr/local/lib/perl5/5.44.0/File/Path.pm »
1 package Exporter::Heavy;
2  
3 use strict;
4 no strict 'refs';
5  
6 our $VERSION = '5.79';
7  
8 =head1 NAME
9  
10 Exporter::Heavy - Exporter guts
11  
12 =head1 SYNOPSIS
13  
14 (internal use only)
15  
16 =head1 DESCRIPTION
17  
18 No user-serviceable parts inside.
19  
20 =cut
21  
22 #
23 # We go to a lot of trouble not to 'require Carp' at file scope,
24 # because Carp requires Exporter, and something has to give.
25 #
26  
27 sub _rebuild_cache {
28 0 ▶ my ($pkg, $exports, $cache) = @_;
Subroutine _rebuild_cache: not called CC=4 SCAR=30.0
29 0 s/^&// foreach @$exports;
30 0 @{$cache}{@$exports} = (1) x @$exports;
31 0 my $ok = \@{"${pkg}::EXPORT_OK"};
32 0 ▶ if (@$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$ok) 0 0 0
33 0 s/^&// foreach @$ok;
34 0 @{$cache}{@$ok} = (1) x @$ok;
35 }
36 }
37  
38 sub heavy_export {
39  
40 # Save the old __WARN__ handler in case it was defined
41 0 ▶ my $oldwarn = $SIG{__WARN__} || sub { warn $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine heavy_export: not called CC=46 SCAR=76.8
Pod undocumented
Condition0%0/3
$SIG{'__WARN__'} || sub { warn $_[0]; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$SIG{'__WARN__'} || sub { warn $_[0]; }
$SIG{'__WARN__'} sub { warn $_[0]; }
Truth table0%0/3
A || B
A= $SIG{'__WARN__'}B= sub { warn $_[0]; }
ABresult
1X1
011
000
42  
43 # First make import warnings look like they're coming from the "use".
44 local $SIG{__WARN__} = sub {
45 0 ▶ my $text = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
46 0 ▶ if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) { } 0 0 0
47 0 require Carp;
48 0 local $Carp::CarpLevel = 1; # ignore package calling us too.
49 0 $oldwarn->(Carp::shortmess($text));
50 }
51 else {
52 0 $oldwarn->($text);
53 }
54 0 };
55 local $SIG{__DIE__} = sub {
56 0 ▶ require Carp;
Subroutine __ANON__: not called CC=2 SCAR=17.9
57 0 local $Carp::CarpLevel = 1; # ignore package calling us too.
58 0 ▶ Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^Unable to create sub named "(.*?)::"/ 0 0 0
59 if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
60 0 };
61  
62 0 my($pkg, $callpkg, @imports) = @_;
63 0 my($type, $sym, $cache_is_current, $oops);
64 0 ▶ my($exports, $export_cache) = (\@{"${pkg}::EXPORT"},
Condition0%0/2
$Exporter::Cache{$pkg} ||= {}
l!l
00
MC/DC0%0/1
$Exporter::Cache{$pkg} ||= {}
$Exporter::Cache{$pkg}
Truth table0%0/2
A
A= $Exporter::Cache{$pkg}
Aresult
11
00
65 0 $Exporter::Cache{$pkg} ||= {});
66  
67 0 ▶ if (@imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports) { } 0 0 0
68 0 ▶ if (!%$export_cache) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$export_cache) 0 0 0
69 0 _rebuild_cache ($pkg, $exports, $export_cache);
70 0 $cache_is_current = 1;
71 }
72  
73 0 ▶ if (grep m{^[/!:]}, @imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep m[^[/!:]], @imports) 0 0 0
74 0 my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
75 0 my $tagdata;
76 my %imports;
77 0 my($remove, $spec, @names, @allexports);
78 # negated first item implies starting with default set:
79 0 ▶ unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/;
Branch: 1 branch
BranchTrueFalseTotal
if $imports[0] =~ /^!/ 0 0 0
80 0 foreach $spec (@imports){
81 0 $remove = $spec =~ s/^!//;
82  
83 0 ▶ if ($spec =~ s/^://){
Branch: 2 branches
BranchTrueFalseTotal
if ($spec =~ s/^://) { } 0 0 0
elsif ($spec =~ m[^/(.*)/$]) { } 0 0 0
84 0 ▶ if ($spec eq 'DEFAULT'){
Branch: 2 branches
BranchTrueFalseTotal
if ($spec eq 'DEFAULT') { } 0 0 0
elsif ($tagdata = $tagsref->{$spec}) { } 0 0 0
85 0 @names = @$exports;
86 }
87 elsif ($tagdata = $tagsref->{$spec}) {
88 0 @names = @$tagdata;
89 }
90 else {
91 0 warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS];
92 0 ++$oops;
93 0 next;
94 }
95 }
96 elsif ($spec =~ m:^/(.*)/$:){
97 0 my $patn = $1;
98 0 ▶ @allexports = keys %$export_cache unless @allexports; # only do keys once
Branch: 1 branch
BranchTrueFalseTotal
unless @allexports 0 0 0
99 0 @names = grep(/$patn/, @allexports); # not anchored by default
100 }
101 else {
102 0 @names = ($spec); # is a normal symbol name
103 }
104  
105 0 ▶ warn "Import ".($remove ? "del":"add").": @names "
Branch: 2 branches
BranchTrueFalseTotal
if $Exporter::Verbose 0 0 0
$remove ? : 0 0 0
106 if $Exporter::Verbose;
107  
108 0 ▶ if ($remove) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove) { } 0 0 0
109 0 foreach $sym (@names) { delete $imports{$sym} }
110 }
111 else {
112 0 @imports{@names} = (1) x @names;
113 }
114 }
115 0 @imports = keys %imports;
116 }
117  
118 0 my @carp;
119 0 foreach $sym (@imports) {
120 0 ▶ if (!$export_cache->{$sym}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($export_cache->{$sym}) 0 0 0
121 0 ▶ if ($sym =~ m/^\d/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sym =~ /^\d/) { } 0 0 0
elsif (not $sym =~ s/^&// && $export_cache->{$sym}) { } 0 0 0
122 0 $pkg->VERSION($sym); # inherit from UNIVERSAL
123 # If the version number was the only thing specified
124 # then we should act as if nothing was specified:
125 0 ▶ if (@imports == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports == 1) 0 0 0
126 0 @imports = @$exports;
127 0 last;
128 }
129 # We need a way to emulate 'use Foo ()' but still
130 # allow an easy version check: "use Foo 1.23, ''";
131 0 ▶ if (@imports == 2 and !$imports[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports == 2 and not $imports[1]) 0 0 0
Condition0%0/3
@imports == 2 and not $imports[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@imports == 2 and not $imports[1]
@imports == 2 not $imports[1]
Truth table0%0/3
A and not(B)
A= @imports == 2B= not $imports[1]
ABresult
0X0
100
111
132 0 @imports = ();
133 0 last;
134 }
135 ▶ } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) {
Condition0%0/3
$sym =~ s/^&// && $export_cache->{$sym}
!ll&&!rl&&r
000
MC/DC0%0/2
$sym =~ s/^&// && $export_cache->{$sym}
$sym =~ s/^&// $export_cache->{$sym}
Truth table0%0/3
A && B
A= $sym =~ s/^&//B= $export_cache->{$sym}
ABresult
0X0
100
111
136 # Last chance - see if they've updated EXPORT_OK since we
137 # cached it.
138  
139 0 ▶ unless ($cache_is_current) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cache_is_current) 0 0 0
140 0 %$export_cache = ();
141 0 _rebuild_cache ($pkg, $exports, $export_cache);
142 0 $cache_is_current = 1;
143 }
144  
145 0 ▶ if (!$export_cache->{$sym}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($export_cache->{$sym}) 0 0 0
146 # accumulate the non-exports
147 0 push @carp,
148 qq["$sym" is not exported by the $pkg module];
149 0 $oops++;
150 }
151 }
152 }
153 }
154 0 ▶ if ($oops) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oops) 0 0 0
155 0 require Carp;
156 0 Carp::croak(join("\n", @carp, "Can't continue after import errors"));
157 }
158 }
159 else {
160 0 @imports = @$exports;
161 }
162  
163 0 ▶ my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"},
Condition0%0/2
$Exporter::FailCache{$pkg} ||= {}
l!l
00
MC/DC0%0/1
$Exporter::FailCache{$pkg} ||= {}
$Exporter::FailCache{$pkg}
Truth table0%0/2
A
A= $Exporter::FailCache{$pkg}
Aresult
11
00
164 0 $Exporter::FailCache{$pkg} ||= {});
165  
166 0 ▶ if (@$fail) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$fail) 0 0 0
167 0 ▶ if (!%$fail_cache) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$fail_cache) 0 0 0
168 # Build cache of symbols. Optimise the lookup by adding
169 # barewords twice... both with and without a leading &.
170 # (Technique could be applied to $export_cache at cost of memory)
171 0 ▶ my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail;
Branch: 1 branch
BranchTrueFalseTotal
/^\w/ ? : 0 0 0
172 0 ▶ warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $Exporter::Verbose 0 0 0
173 0 @{$fail_cache}{@expanded} = (1) x @expanded;
174 }
175 0 my @failed;
176 0 ▶ foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} }
Branch: 1 branch
BranchTrueFalseTotal
if $fail_cache->{$sym} 0 0 0
177 0 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 0 0
178 0 @failed = $pkg->export_fail(@failed);
179 0 foreach $sym (@failed) {
180 0 require Carp;
181 0 Carp::carp(qq["$sym" is not implemented by the $pkg module ],
182 "on this architecture");
183 }
184 0 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 0 0
185 0 require Carp;
186 0 Carp::croak("Can't continue after import errors");
187 }
188 }
189 }
190  
191 0 ▶ warn "Importing into $callpkg from $pkg: ",
Branch: 1 branch
BranchTrueFalseTotal
if $Exporter::Verbose 0 0 0
192 join(", ",sort @imports) if $Exporter::Verbose;
193  
194 0 foreach $sym (@imports) {
195 # shortcut for the common case of no type character
196 0 ▶ (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next)
Branch: 1 branch
BranchTrueFalseTotal
unless $sym =~ s/^(\W)// 0 0 0
197 unless $sym =~ s/^(\W)//;
198 0 $type = $1;
199 no warnings 'once';
200 0 *{"${callpkg}::$sym"} =
201 0 ▶ $type eq '&' ? \&{"${pkg}::$sym"} :
Branch: 1 branch
BranchTrueFalseTotal
$type eq '$' ? : 0 0 0
202 0 ▶ $type eq '$' ? \${"${pkg}::$sym"} :
Branch: 1 branch
BranchTrueFalseTotal
$type eq '@' ? : 0 0 0
203 0 ▶ $type eq '@' ? \@{"${pkg}::$sym"} :
Branch: 1 branch
BranchTrueFalseTotal
$type eq '%' ? : 0 0 0
204 0 ▶ $type eq '%' ? \%{"${pkg}::$sym"} :
Branch: 1 branch
BranchTrueFalseTotal
$type eq '*' ? : 0 0 0
205 0 $type eq '*' ? *{"${pkg}::$sym"} :
206 0 ▶ do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
Branch: 1 branch
BranchTrueFalseTotal
$type eq '&' ? : 0 0 0
207 }
208 }
209  
210 sub heavy_export_to_level
211 {
212 0 ▶ my $pkg = shift;
Subroutine heavy_export_to_level: not called CC=1 SCAR=6.9
Pod undocumented
213 0 my $level = shift;
214 0 (undef) = shift; # XXX redundant arg
215 0 my $callpkg = caller($level);
216 0 $pkg->export($callpkg, @_);
217 }
218  
219 # Utility functions
220  
221 sub _push_tags {
222 0 ▶ my($pkg, $var, $syms) = @_;
Subroutine _push_tags: not called CC=5 SCAR=34.0
223 0 my @nontag = ();
224 0 my $export_tags = \%{"${pkg}::EXPORT_TAGS"};
225 0 push(@{"${pkg}::$var"},
226 0 ▶ map { $export_tags->{$_} ? @{$export_tags->{$_}}
Branch: 2 branches
BranchTrueFalseTotal
$export_tags->{$_} ? : 0 0 0
@$syms ? : 0 0 0
227 : scalar(push(@nontag,$_),$_) }
228 (@$syms) ? @$syms : keys %$export_tags);
229 0 ▶ if (@nontag and $^W) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nontag and $^W) 0 0 0
Condition0%0/3
@nontag and $^W
!ll&&!rl&&r
000
MC/DC0%0/2
@nontag and $^W
@nontag $^W
Truth table0%0/3
A and B
A= @nontagB= $^W
ABresult
0X0
100
111
230 # This may change to a die one day
231 0 require Carp;
232 0 Carp::carp(join(", ", @nontag)." are not tags of $pkg");
233 }
234 }
235  
236 sub heavy_require_version {
237 0 ▶ my($self, $wanted) = @_;
Subroutine heavy_require_version: not called CC=2 SCAR=17.9
Pod undocumented
238 0 ▶ my $pkg = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
239 0 return ${pkg}->VERSION($wanted);
240 }
241  
242 sub heavy_export_tags {
243 0 ▶ _push_tags((caller)[0], "EXPORT", \@_);
Subroutine heavy_export_tags: not called CC=1 SCAR=6.9
Pod undocumented
244 }
245  
246 sub heavy_export_ok_tags {
247 0 ▶ _push_tags((caller)[0], "EXPORT_OK", \@_);
Subroutine heavy_export_ok_tags: not called CC=1 SCAR=6.9
Pod undocumented
248 }
249  
250 1;
« /usr/local/lib/perl5/5.44.0/x86_64-linux/re.pm ↑ Summary /usr/local/lib/perl5/5.44.0/File/Path.pm »