blib/lib/Test2/Util/Importer.pm

filter: Statementstmt 64.5% 235 / 364 Branchbran 47.3% 89 / 188 Conditioncond 39.4% 75 / 190 MC/DCmcdc 8.4% 9 / 107 Subroutinesub 60.0% 24 / 40 Podpod 0.0% 0 / 19 totaltotal 47.5% 432 / 908 CC 185 SCAR 43.2
CC
185
Cov
54%
_build_menu
220.1
_parse_args
163.6
do_unimport
56.0
CRAP 75.3
« lib/Test/Builder/Tester.pm ↑ Summary blib/lib/Test2/IPC.pm »
1 package Test2::Util::Importer;
2 381 ▶use strict; no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 177 ▶use warnings; no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 177 our $VERSION = '1.302226';
6  
7 177 my %SIG_TO_SLOT = (
8 '&' => 'CODE',
9 '$' => 'SCALAR',
10 '%' => 'HASH',
11 '@' => 'ARRAY',
12 '*' => 'GLOB',
13 );
14  
15 177 our %IMPORTED;
16  
17 # This will be used to check if an import arg is a version number
18 177 my %NUMERIC = map +($_ => 1), 0 .. 9;
19  
20 179 ▶sub IMPORTER_MENU() {
Subroutine IMPORTER_MENU: called CC=1 SCAR=0.0
Pod undocumented
21 return (
22 export_ok => [qw/optimal_import/],
23 export_anon => {
24 171 ▶ import => sub {
Subroutine __ANON__: called CC=5 SCAR=16.4
25 171 my $from = shift;
26 171 my @caller = caller(0);
27  
28 171 ▶ _version_check($from, \@caller, shift @_) if @_ && $NUMERIC{substr($_[0], 0, 1)};
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $NUMERIC{substr $_[0], 0, 1} 148 171 319
Condition33%1/3
@_ and $NUMERIC{substr $_[0], 0, 1}
!ll&&!rl&&r
01710
MC/DC0%0/2
@_ and $NUMERIC{substr $_[0], 0, 1}
@_ $NUMERIC{substr $_[0], 0, 1}
Truth table33%1/3
A and B
A= @_B= $NUMERIC{substr $_[0], 0, 1}
ABresult
0X0
100
111
29  
30 171 my $file = _mod_to_file($from);
31 171 ▶ _load_file(\@caller, $file) unless $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{$file} 0 171 171
32  
33 171 ▶ return if optimal_import($from, $caller[0], \@caller, @_);
Branch: 1 branch
BranchTrueFalseTotal
if optimal_import($from, $caller[0], \@caller, @_) 2 169 171
34  
35 169 my $self = __PACKAGE__->new(
36 from => $from,
37 caller => \@caller,
38 );
39  
40 169 $self->do_import($caller[0], @_);
41 },
42 },
43 179 );
44 }
45  
46 ###########################################################################
47 #
48 # These are class methods
49 # import and unimport are what you would expect.
50 # import_into and unimport_from are the indirect forms you can use in other
51 # package import() methods.
52 #
53 # These all attempt to do a fast optimal-import if possible, then fallback to
54 # the full-featured import that constructs an object when needed.
55 #
56  
57 499 ▶sub import {
Subroutine import: called CC=6 SCAR=18.1
58 499 my $class = shift;
59  
60 499 my @caller = caller(0);
61  
62 499 ▶ _version_check($class, \@caller, shift @_) if @_ && $NUMERIC{substr($_[0], 0, 1)};
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $NUMERIC{substr $_[0], 0, 1} 0 499 499
Condition66%2/3
@_ and $NUMERIC{substr $_[0], 0, 1}
!ll&&!rl&&r
1583410
MC/DC0%0/2
@_ and $NUMERIC{substr $_[0], 0, 1}
@_ $NUMERIC{substr $_[0], 0, 1}
Truth table66%2/3
A and B
A= @_B= $NUMERIC{substr $_[0], 0, 1}
ABresult
0X0
100
111
63  
64 499 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 158 341 499
65  
66 341 my ($from, @args) = @_;
67  
68 341 my $file = _mod_to_file($from);
69 341 ▶ _load_file(\@caller, $file) unless $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{$file} 162 179 341
70  
71 341 ▶ return if optimal_import($from, $caller[0], \@caller, @args);
Branch: 1 branch
BranchTrueFalseTotal
if optimal_import($from, $caller[0], \@caller, @args) 0 341 341
72  
73 341 my $self = $class->new(
74 from => $from,
75 caller => \@caller,
76 );
77  
78 341 $self->do_import($caller[0], @args);
79 }
80  
81 0 ▶sub unimport {
Subroutine unimport: not called CC=1 SCAR=6.9
82 0 my $class = shift;
83 0 my @caller = caller(0);
84  
85 0 my $self = $class->new(
86 from => $caller[0],
87 caller => \@caller,
88 );
89  
90 0 $self->do_unimport(@_);
91 }
92  
93 345 ▶sub import_into {
Subroutine import_into: called CC=5 SCAR=17.6
Pod undocumented
94 345 my $class = shift;
95 345 my ($from, $into, @args) = @_;
96  
97 345 my @caller;
98  
99 345 ▶ if (ref($into)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $into) { } 0 345 345
elsif ($into =~ /^\d+$/) { } 0 345 345
100 0 @caller = @$into;
101 0 $into = $caller[0];
102 }
103 elsif ($into =~ m/^\d+$/) {
104 0 @caller = caller($into + 1);
105 0 $into = $caller[0];
106 }
107 else {
108 345 @caller = caller(0);
109 }
110  
111 345 my $file = _mod_to_file($from);
112 345 ▶ _load_file(\@caller, $file) unless $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{$file} 0 345 345
113  
114 345 ▶ return if optimal_import($from, $into, \@caller, @args);
Branch: 1 branch
BranchTrueFalseTotal
if optimal_import($from, $into, \@caller, @args) 328 17 345
115  
116 17 my $self = $class->new(
117 from => $from,
118 caller => \@caller,
119 );
120  
121 17 $self->do_import($into, @args);
122 }
123  
124 0 ▶sub unimport_from {
Subroutine unimport_from: not called CC=2 SCAR=17.9
Pod undocumented
125 0 my $class = shift;
126 0 my ($from, @args) = @_;
127  
128 0 my @caller;
129 0 ▶ if ($from =~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from =~ /^\d+$/) { } 0 0 0
130 0 @caller = caller($from + 1);
131 0 $from = $caller[0];
132 }
133 else {
134 0 @caller = caller(0);
135 }
136  
137 0 my $self = $class->new(
138 from => $from,
139 caller => \@caller,
140 );
141  
142 0 $self->do_unimport(@args);
143 }
144  
145 ###########################################################################
146 #
147 # Constructors
148 #
149  
150 527 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
151 527 my $class = shift;
152 527 my %params = @_;
153  
154 527 ▶ my $caller = $params{caller} || [caller()];
Condition50%1/2
$params{'caller'} || [caller()]
l!l
5270
MC/DC0%0/1
$params{'caller'} || [caller()]
$params{'caller'}
Truth table50%1/2
A
A= $params{'caller'}
Aresult
11
00
155  
156 die "You must specify a package to import from at $caller->[1] line $caller->[2].\n"
157 527 ▶ unless $params{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"from"} 0 527 527
158  
159 return bless {
160 from => $params{from},
161 caller => $params{caller}, # Do not use our caller.
162 527 }, $class;
163 }
164  
165 ###########################################################################
166 #
167 # Shortcuts for getting symbols without any namespace modifications
168 #
169  
170 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
171 0 my $proto = shift;
172 0 my @caller = caller(1);
173  
174 0 ▶ my $self = ref($proto) ? $proto : $proto->new(
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 0 0
175 from => shift(@_),
176 caller => \@caller,
177 );
178  
179 0 my %result;
180 0 ▶ $self->do_import($caller[0], @_, sub { $result{$_[0]} = $_[1] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
181 0 return \%result;
182 }
183  
184 0 ▶sub get_list {
Subroutine get_list: not called CC=2 SCAR=17.9
Pod undocumented
185 0 my $proto = shift;
186 0 my @caller = caller(1);
187  
188 0 ▶ my $self = ref($proto) ? $proto : $proto->new(
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 0 0
189 from => shift(@_),
190 caller => \@caller,
191 );
192  
193 0 my @result;
194 0 ▶ $self->do_import($caller[0], @_, sub { push @result => $_[1] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
195 0 return @result;
196 }
197  
198 0 ▶sub get_one {
Subroutine get_one: not called CC=2 SCAR=17.9
Pod undocumented
199 0 my $proto = shift;
200 0 my @caller = caller(1);
201  
202 0 ▶ my $self = ref($proto) ? $proto : $proto->new(
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 0 0
203 from => shift(@_),
204 caller => \@caller,
205 );
206  
207 0 my $result;
208 0 ▶ $self->do_import($caller[0], @_, sub { $result = $_[1] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
209 0 return $result;
210 }
211  
212 ###########################################################################
213 #
214 # Object methods
215 #
216  
217 527 ▶sub do_import {
Subroutine do_import: called CC=4 SCAR=14.5
Pod undocumented
218 527 my $self = shift;
219  
220 527 my ($into, $versions, $exclude, $import, $set) = $self->parse_args(@_);
221  
222 # Exporter supported multiple version numbers being listed...
223 527 ▶ _version_check($self->from, $self->get_caller, @$versions) if @$versions;
Branch: 1 branch
BranchTrueFalseTotal
if @$versions 0 527 527
224  
225 527 ▶ return unless @$import;
Branch: 1 branch
BranchTrueFalseTotal
unless @$import 0 527 527
226  
227 527 ▶ $self->_handle_fail($into, $import) if $self->menu($into)->{fail};
Branch: 1 branch
BranchTrueFalseTotal
if $self->menu($into)->{"fail"} 0 527 527
228 527 $self->_set_symbols($into, $exclude, $import, $set);
229 }
230  
231 0 ▶sub do_unimport {
Subroutine do_unimport: not called CC=7 SCAR=40.3
Pod undocumented
232 0 my $self = shift;
233  
234 0 my $from = $self->from;
235 0 ▶ my $imported = $IMPORTED{$from} or $self->croak("'$from' does not have any imports to remove");
Branch: 1 branch
BranchTrueFalseTotal
my $imported = $Test2::Util::Importer::IMPORTED{$from} or $self->croak("'${from}' does not have any imports to remove") 0 0 0
236  
237 0 my %allowed = map { $_ => 1 } @$imported;
238  
239 0 ▶ my @args = @_ ? @_ : @$imported;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
240  
241 0 my $stash = \%{"$from\::"};
242  
243 0 for my $name (@args) {
244 0 $name =~ s/^&//;
245  
246 0 ▶ $self->croak("Sub '$name' was not imported using " . ref($self)) unless $allowed{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed{$name} 0 0 0
247  
248 0 my $glob = delete $stash->{$name};
249 0 local *GLOBCLONE = *$glob;
250  
251 0 for my $type (qw/SCALAR HASH ARRAY FORMAT IO/) {
252 0 ▶ next unless defined(*{$glob}{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{$glob;}{$type} 0 0 0
253 0 *{"$from\::$name"} = *{$glob}{$type}
254 }
255 }
256 }
257  
258 2125 ▶sub from { $_[0]->{from} }
Subroutine from: called CC=1 SCAR=0.0
Pod undocumented
259  
260 0 ▶sub from_file {
Subroutine from_file: not called CC=2 SCAR=17.9
Pod undocumented
261 0 my $self = shift;
262  
263 0 ▶ $self->{from_file} ||= _mod_to_file($self->{from});
Condition0%0/3
$self->{"from_file"} ||= _mod_to_file($self->{"from"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"from_file"} ||= _mod_to_file($self->{"from"})
$self->{"from_file"} _mod_to_file($self->{"from"})
Truth table0%0/3
A ||= B
A= $self->{"from_file"}B= _mod_to_file($self->{"from"})
ABresult
1X1
011
000
264  
265 0 return $self->{from_file};
266 }
267  
268 0 ▶sub load_from {
Subroutine load_from: not called CC=2 SCAR=17.9
Pod undocumented
269 0 my $self = shift;
270 0 my $from_file = $self->from_file;
271 0 my $this_file = __FILE__;
272  
273 0 ▶ return if $INC{$from_file};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$from_file} 0 0 0
274  
275 0 my $caller = $self->get_caller;
276  
277 0 _load_file($caller, $from_file);
278 }
279  
280 706 ▶sub get_caller {
Subroutine get_caller: called CC=6 SCAR=32.9
Pod undocumented
281 706 my $self = shift;
282 706 ▶ return $self->{caller} if $self->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"caller"} 706 0 706
283  
284 0 my $level = 1;
285 0 ▶ while(my @caller = caller($level++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller $level++) 0 0 0
286 0 ▶ return \@caller if @caller && !$caller[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if @caller and not $caller[0]->isa(__PACKAGE__) 0 0 0
Condition0%0/3
@caller and not $caller[0]->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/2
@caller and not $caller[0]->isa(__PACKAGE__)
@caller not $caller[0]->isa(__PACKAGE__)
Truth table0%0/3
A and not(B)
A= @callerB= not $caller[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
287 0 ▶ last unless @caller;
Branch: 1 branch
BranchTrueFalseTotal
unless @caller 0 0 0
288 }
289  
290 # Fallback
291 0 return [caller(0)];
292 }
293  
294 0 ▶sub croak {
Subroutine croak: not called CC=3 SCAR=24.8
Pod undocumented
295 0 my $self = shift;
296 0 my ($msg) = @_;
297 0 my $caller = $self->get_caller;
298 0 ▶ my $file = $caller->[1] || 'unknown file';
Condition0%0/2
$caller->[1] || 'unknown file'
l!l
00
MC/DC0%0/1
$caller->[1] || 'unknown file'
$caller->[1]
Truth table0%0/2
A
A= $caller->[1]
Aresult
11
00
299 0 ▶ my $line = $caller->[2] || 'unknown line';
Condition0%0/2
$caller->[2] || 'unknown line'
l!l
00
MC/DC0%0/1
$caller->[2] || 'unknown line'
$caller->[2]
Truth table0%0/2
A
A= $caller->[2]
Aresult
11
00
300 0 die "$msg at $file line $line.\n";
301 }
302  
303 0 ▶sub carp {
Subroutine carp: not called CC=3 SCAR=24.8
Pod undocumented
304 0 my $self = shift;
305 0 my ($msg) = @_;
306 0 my $caller = $self->get_caller;
307 0 ▶ my $file = $caller->[1] || 'unknown file';
Condition0%0/2
$caller->[1] || 'unknown file'
l!l
00
MC/DC0%0/1
$caller->[1] || 'unknown file'
$caller->[1]
Truth table0%0/2
A
A= $caller->[1]
Aresult
11
00
308 0 ▶ my $line = $caller->[2] || 'unknown line';
Condition0%0/2
$caller->[2] || 'unknown line'
l!l
00
MC/DC0%0/1
$caller->[2] || 'unknown line'
$caller->[2]
Truth table0%0/2
A
A= $caller->[2]
Aresult
11
00
309 0 warn "$msg at $file line $line.\n";
310 }
311  
312 2125 ▶sub menu {
Subroutine menu: called CC=5 SCAR=16.8
Pod undocumented
313 2125 my $self = shift;
314 2125 my ($into) = @_;
315  
316 2125 ▶ $self->croak("menu() requires the name of the destination package")
Branch: 1 branch
BranchTrueFalseTotal
unless $into 0 2125 2125
317 unless $into;
318  
319 2125 my $for = $self->{menu_for};
320 2125 ▶ delete $self->{menu} if $for && $for ne $into;
Branch: 1 branch
BranchTrueFalseTotal
if $for and $for ne $into 0 2125 2125
Condition66%2/3
$for and $for ne $into
!ll&&!rl&&r
52715980
MC/DC0%0/2
$for and $for ne $into
$for $for ne $into
Truth table66%2/3
A and B
A= $forB= $for ne $into
ABresult
0X0
100
111
321 2125 ▶ return $self->{menu} || $self->reload_menu($into);
Condition66%2/3
$self->{'menu'} || $self->reload_menu($into)
l!l&&r!l&&!r
15985270
MC/DC0%0/2
$self->{'menu'} || $self->reload_menu($into)
$self->{'menu'} $self->reload_menu($into)
Truth table66%2/3
A || B
A= $self->{'menu'}B= $self->reload_menu($into)
ABresult
1X1
011
000
322 }
323  
324 527 ▶sub reload_menu {
Subroutine reload_menu: called CC=12 SCAR=25.7
Pod undocumented
325 527 my $self = shift;
326 527 my ($into) = @_;
327  
328 527 ▶ $self->croak("reload_menu() requires the name of the destination package")
Branch: 1 branch
BranchTrueFalseTotal
unless $into 0 527 527
329 unless $into;
330  
331 527 my $from = $self->from;
332  
333 527 ▶ if (my $menu_sub = *{"$from\::IMPORTER_MENU"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $menu_sub = *{"${from}::IMPORTER_MENU";}{'CODE'}) { } 179 348 527
334 # Hook, other exporter modules can define this method to be compatible with
335 # Importer.pm
336  
337 179 my %got = $from->$menu_sub($into, $self->get_caller);
338  
339 179 ▶ $got{export} ||= [];
Condition50%1/2
$got{"export"} ||= []
l!l
0179
MC/DC0%0/1
$got{"export"} ||= []
$got{"export"}
Truth table50%1/2
A
A= $got{"export"}
Aresult
11
00
340 179 ▶ $got{export_ok} ||= [];
Condition50%1/2
$got{"export_ok"} ||= []
l!l
1790
MC/DC0%0/1
$got{"export_ok"} ||= []
$got{"export_ok"}
Truth table50%1/2
A
A= $got{"export_ok"}
Aresult
11
00
341 179 ▶ $got{export_tags} ||= {};
Condition50%1/2
$got{"export_tags"} ||= {}
l!l
0179
MC/DC0%0/1
$got{"export_tags"} ||= {}
$got{"export_tags"}
Truth table50%1/2
A
A= $got{"export_tags"}
Aresult
11
00
342 179 ▶ $got{export_fail} ||= [];
Condition50%1/2
$got{"export_fail"} ||= []
l!l
0179
MC/DC0%0/1
$got{"export_fail"} ||= []
$got{"export_fail"}
Truth table50%1/2
A
A= $got{"export_fail"}
Aresult
11
00
343 179 ▶ $got{export_anon} ||= {};
Condition50%1/2
$got{"export_anon"} ||= {}
l!l
1790
MC/DC0%0/1
$got{"export_anon"} ||= {}
$got{"export_anon"}
Truth table50%1/2
A
A= $got{"export_anon"}
Aresult
11
00
344 179 ▶ $got{export_magic} ||= {};
Condition50%1/2
$got{"export_magic"} ||= {}
l!l
0179
MC/DC0%0/1
$got{"export_magic"} ||= {}
$got{"export_magic"}
Truth table50%1/2
A
A= $got{"export_magic"}
Aresult
11
00
345  
346 $self->croak("'$from' provides both 'generate' and 'export_gen' in its IMPORTER_MENU (They are exclusive, module must pick 1)")
347 179 ▶ if $got{export_gen} && $got{generate};
Branch: 1 branch
BranchTrueFalseTotal
if $got{"export_gen"} and $got{"generate"} 0 179 179
Condition33%1/3
$got{"export_gen"} and $got{"generate"}
!ll&&!rl&&r
17900
MC/DC0%0/2
$got{"export_gen"} and $got{"generate"}
$got{"export_gen"} $got{"generate"}
Truth table33%1/3
A and B
A= $got{"export_gen"}B= $got{"generate"}
ABresult
0X0
100
111
348  
349 179 ▶ $got{export_gen} ||= {};
Condition50%1/2
$got{"export_gen"} ||= {}
l!l
0179
MC/DC0%0/1
$got{"export_gen"} ||= {}
$got{"export_gen"}
Truth table50%1/2
A
A= $got{"export_gen"}
Aresult
11
00
350  
351 179 $self->{menu} = $self->_build_menu($into => \%got, 1);
352 }
353 else {
354 348 my %got;
355 348 $got{export} = \@{"$from\::EXPORT"};
356 348 $got{export_ok} = \@{"$from\::EXPORT_OK"};
357 348 $got{export_tags} = \%{"$from\::EXPORT_TAGS"};
358 348 $got{export_fail} = \@{"$from\::EXPORT_FAIL"};
359 348 $got{export_gen} = \%{"$from\::EXPORT_GEN"};
360 348 $got{export_anon} = \%{"$from\::EXPORT_ANON"};
361 348 $got{export_magic} = \%{"$from\::EXPORT_MAGIC"};
362  
363 348 $self->{menu} = $self->_build_menu($into => \%got, 0);
364 }
365  
366 527 $self->{menu_for} = $into;
367  
368 527 return $self->{menu};
369 }
370  
371 527 ▶sub _build_menu {
Subroutine _build_menu: called CC=36 SCAR=53.9
372 527 my $self = shift;
373 527 my ($into, $got, $new_style) = @_;
374  
375 527 my $from = $self->from;
376  
377 527 ▶ my $export = $got->{export} || [];
Condition50%1/2
$got->{'export'} || []
l!l
5270
MC/DC0%0/1
$got->{'export'} || []
$got->{'export'}
Truth table50%1/2
A
A= $got->{'export'}
Aresult
11
00
378 527 ▶ my $export_ok = $got->{export_ok} || [];
Condition50%1/2
$got->{'export_ok'} || []
l!l
5270
MC/DC0%0/1
$got->{'export_ok'} || []
$got->{'export_ok'}
Truth table50%1/2
A
A= $got->{'export_ok'}
Aresult
11
00
379 527 ▶ my $export_tags = $got->{export_tags} || {};
Condition50%1/2
$got->{'export_tags'} || {}
l!l
5270
MC/DC0%0/1
$got->{'export_tags'} || {}
$got->{'export_tags'}
Truth table50%1/2
A
A= $got->{'export_tags'}
Aresult
11
00
380 527 ▶ my $export_fail = $got->{export_fail} || [];
Condition50%1/2
$got->{'export_fail'} || []
l!l
5270
MC/DC0%0/1
$got->{'export_fail'} || []
$got->{'export_fail'}
Truth table50%1/2
A
A= $got->{'export_fail'}
Aresult
11
00
381 527 ▶ my $export_anon = $got->{export_anon} || {};
Condition50%1/2
$got->{'export_anon'} || {}
l!l
5270
MC/DC0%0/1
$got->{'export_anon'} || {}
$got->{'export_anon'}
Truth table50%1/2
A
A= $got->{'export_anon'}
Aresult
11
00
382 527 ▶ my $export_gen = $got->{export_gen} || {};
Condition50%1/2
$got->{'export_gen'} || {}
l!l
5270
MC/DC0%0/1
$got->{'export_gen'} || {}
$got->{'export_gen'}
Truth table50%1/2
A
A= $got->{'export_gen'}
Aresult
11
00
383 527 ▶ my $export_magic = $got->{export_magic} || {};
Condition50%1/2
$got->{'export_magic'} || {}
l!l
5270
MC/DC0%0/1
$got->{'export_magic'} || {}
$got->{'export_magic'}
Truth table50%1/2
A
A= $got->{'export_magic'}
Aresult
11
00
384  
385 527 my $generate = $got->{generate};
386  
387 0 ▶ $generate ||= sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
388 0 my $symbol = shift;
389 0 my ($sig, $name) = ($symbol =~ m/^(\W?)(.*)$/);
390 0 ▶ $sig ||= '&';
Condition0%0/2
$sig ||= "&"
l!l
00
MC/DC0%0/1
$sig ||= "&"
$sig
Truth table0%0/2
A
A= $sig
Aresult
11
00
391  
392 0 my $do = $export_gen->{"${sig}${name}"};
393 0 ▶ $do ||= $export_gen->{$name} if !$sig || $sig eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if not $sig or $sig eq "&" 0 0 0
Condition0%0/6
not $sig or $sig eq "&"
l!l&&r!l&&!r
000
$do ||= $export_gen->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $sig or $sig eq "&"
not $sig $sig eq "&"
MC/DC0%0/2
$do ||= $export_gen->{$name}
$do $export_gen->{$name}
Truth table0%0/3
not(A) or B
A= not $sigB= $sig eq "&"
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $doB= $export_gen->{$name}
ABresult
1X1
011
000
394  
395 0 ▶ return undef unless $do;
Branch: 1 branch
BranchTrueFalseTotal
unless $do 0 0 0
396  
397 0 $from->$do($into, $symbol);
398 527 ▶ } if $export_gen && keys %$export_gen;
Branch: 1 branch
BranchTrueFalseTotal
if $export_gen and keys %$export_gen 169 358 527
Condition50%3/6
$export_gen and keys %$export_gen
!ll&&!rl&&r
0358169
$generate ||= sub { my $symbol = shift(); my($sig, $name) = $symbol =~ /^(\W?)(.*)$/; $sig ||= "&"; my $do = $$export_gen{"$sig$name"}; $do ||= $export_gen->{$name} if not $sig or $sig eq "&"; return undef unless $do; $from->$do($into, $symbol); }
l!l&&r!l&&!r
01690
MC/DC50%1/2
$export_gen and keys %$export_gen
$export_gen keys %$export_gen
MC/DC0%0/2
$generate ||= sub { my $symbol = shift(); my($sig, $name) = $symbol =~ /^(\W?)(.*)$/; $sig ||= "&"; my $do = $$export_gen{"$sig$name"}; $do ||= $export_gen->{$name} if not $sig or $sig eq "&"; return undef unless $do; $from->$do($into, $symbol); }
$generate sub { my $symbol = shift(); my($sig, $name) = $symbol =~ /^(\W?)(.*)$/; $sig ||= "&"; my $do = $$export_gen{"$sig$name"}; $do ||= $export_gen->{$name} if not $sig or $sig eq "&"; return undef unless $do; $from->$do($into, $symbol); }
Truth table66%2/3
A and B
A= $export_genB= keys %$export_gen
ABresult
0X0
100
111
Truth table33%1/3
A ||= B
A= $generateB= sub { my $symbol = shift(); my($sig, $name) = $symbol =~ /^(\W?)(.*)$/; $sig ||= "&"; my $do = $$export_gen{"$sig$name"}; $do ||= $export_gen->{$name} if not $sig or $sig eq "&"; return undef unless $do; $from->$do($into, $symbol); }
ABresult
1X1
011
000
399  
400 527 my $lookup = {};
401 527 my $exports = {};
402 527 for my $sym (@$export, @$export_ok, keys %$export_gen, keys %$export_anon) {
403 1962 my ($sig, $name) = ($sym =~ m/^(\W?)(.*)$/);
404 1962 ▶ $sig ||= '&';
Condition100%2/2
$sig ||= "&"
l!l
1691793
MC/DC100%1/1
$sig ||= "&"
$sig
Truth table100%2/2
A
A= $sig
Aresult
11
00
405  
406 1962 $lookup->{"${sig}${name}"} = 1;
407 1962 ▶ $lookup->{$name} = 1 if $sig eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "&" 1962 0 1962
408  
409 1962 ▶ next if $export_gen->{"${sig}${name}"};
Branch: 1 branch
BranchTrueFalseTotal
if $$export_gen{"$sig$name"} 169 1793 1962
410 1793 ▶ next if $sig eq '&' && $export_gen->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "&" and $export_gen->{$name} 0 1793 1793
Condition33%1/3
$sig eq "&" and $export_gen->{$name}
!ll&&!rl&&r
017930
MC/DC0%0/2
$sig eq "&" and $export_gen->{$name}
$sig eq "&" $export_gen->{$name}
Truth table33%1/3
A and B
A= $sig eq "&"B= $export_gen->{$name}
ABresult
0X0
100
111
411 1793 ▶ next if $got->{generate} && $generate->("${sig}${name}");
Branch: 1 branch
BranchTrueFalseTotal
if $got->{"generate"} and &$generate("$sig$name") 0 1793 1793
Condition33%1/3
$got->{"generate"} and &$generate("$sig$name")
!ll&&!rl&&r
179300
MC/DC0%0/2
$got->{"generate"} and &$generate("$sig$name")
$got->{"generate"} &$generate("$sig$name")
Truth table33%1/3
A and B
A= $got->{"generate"}B= &$generate("$sig$name")
ABresult
0X0
100
111
412  
413 1793 my $fqn = "$from\::$name";
414 # We cannot use *{$fqn}{TYPE} here, it breaks for autoloaded subs, this
415 # does not:
416 $exports->{"${sig}${name}"} = $export_anon->{$sym} || (
417 1614 ▶ $sig eq '&' ? \&{$fqn} :
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '$' ? : 0 0 0
418 0 ▶ $sig eq '$' ? \${$fqn} :
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '@' ? : 0 0 0
419 0 ▶ $sig eq '@' ? \@{$fqn} :
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '%' ? : 0 0 0
420 0 ▶ $sig eq '%' ? \%{$fqn} :
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '*' ? : 0 0 0
421 0 ▶ $sig eq '*' ? \*{$fqn} :
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '&' ? : 1614 0 1614
Condition66%2/3
$export_anon->{$sym} || ($sig eq '&' ? \&{$fqn;} : ($sig eq '$' ? \${$fqn;} : ($sig eq '@' ? \@{$fqn;} : ($sig eq '%' ? \%{$fqn;} : ($sig eq '*' ? \*{$fqn;} : (next))))))
l!l&&r!l&&!r
17916140
MC/DC0%0/2
$export_anon->{$sym} || ($sig eq '&' ? \&{$fqn;} : ($sig eq '$' ? \${$fqn;} : ($sig eq '@' ? \@{$fqn;} : ($sig eq '%' ? \%{$fqn;} : ($sig eq '*' ? \*{$fqn;} : (next))))))
$export_anon->{$sym} ($sig eq '&' ? \&{$fqn;} : ($sig eq '$' ? \${$fqn;} : ($sig eq '@' ? \@{$fqn;} : ($sig eq '%' ? \%{$fqn;} : ($sig eq '*' ? \*{$fqn;} : (next))))))
Truth table66%2/3
A || B
A= $export_anon->{$sym}B= ($sig eq '&' ? \&{$fqn;} : ($sig eq '$' ? \${$fqn;} : ($sig eq '@' ? \@{$fqn;} : ($sig eq '%' ? \%{$fqn;} : ($sig eq '*' ? \*{$fqn;} : (next))))))
ABresult
1X1
011
000
422 # Sometimes people (CGI::Carp) put invalid names (^name=) into
423 # @EXPORT. We simply go to 'next' in these cases. These modules
424 # have hooks to prevent anyone actually trying to import these.
425 next
426 );
427 }
428  
429 527 ▶ my $f_import = $new_style || $from->can('import');
Condition66%2/3
$new_style || $from->can('import')
l!l&&r!l&&!r
1793480
MC/DC0%0/2
$new_style || $from->can('import')
$new_style $from->can('import')
Truth table66%2/3
A || B
A= $new_styleB= $from->can('import')
ABresult
1X1
011
000
430 $self->croak("'$from' does not provide any exports")
431 unless $new_style
432 || keys %$exports
433 || $from->isa('Exporter')
434 527 ▶ || ($INC{'Exporter.pm'} && $f_import && $f_import == \&Exporter::import);
Branch: 1 branch
BranchTrueFalseTotal
unless $new_style or keys %$exports or $from->isa("Exporter") or $INC{"Exporter.pm"} and $f_import and $f_import == \&Exporter::import 0 527 527
Condition26%4/15
$new_style or keys %$exports or $from->isa("Exporter") or $INC{"Exporter.pm"} and $f_import and $f_import == \&Exporter::import
l!l&&r!l&&!r
52700
$new_style or keys %$exports or $from->isa("Exporter")
l!l&&r!l&&!r
52700
$new_style or keys %$exports
l!l&&r!l&&!r
1793480
$INC{"Exporter.pm"} and $f_import and $f_import == \&Exporter::import
!ll&&!rl&&r
000
$INC{"Exporter.pm"} and $f_import
!ll&&!rl&&r
000
MC/DC0%0/6
$new_style or keys %$exports or $from->isa("Exporter") or $INC{"Exporter.pm"} and $f_import and $f_import == \&Exporter::import
$new_style keys %$exports $from->isa("Exporter") $INC{"Exporter.pm"} $f_import $f_import == \&Exporter::import
Truth table28%2/7
A or B or C or D and E and F
A= $new_styleB= keys %$exportsC= $from->isa("Exporter")D= $INC{"Exporter.pm"}E= $f_importF= $f_import == \&Exporter::import
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001111
0000XX0
00010X0
0001100
435  
436 # Do not cleanup or normalize the list added to the DEFAULT tag, legacy....
437 527 my $tags = {
438 %$export_tags,
439 'DEFAULT' => [ @$export ],
440 };
441  
442 # Add 'ALL' tag unless already specified. We want to normalize it.
443 527 ▶ $tags->{ALL} ||= [ sort grep {m/^[\&\$\@\%\*]/} keys %$lookup ];
Condition50%1/2
$tags->{"ALL"} ||= [sort(grep({/^[\&\$\@\%\*]/;} keys %$lookup))]
l!l
0527
MC/DC0%0/1
$tags->{"ALL"} ||= [sort(grep({/^[\&\$\@\%\*]/;} keys %$lookup))]
$tags->{"ALL"}
Truth table50%1/2
A
A= $tags->{"ALL"}
Aresult
11
00
444  
445 my $fail = @$export_fail ? {
446 map {
447 0 ▶ my ($sig, $name) = (m/^(\W?)(.*)$/);
Branch: 1 branch
BranchTrueFalseTotal
@$export_fail ? : 0 527 527
448 0 ▶ $sig ||= '&';
Condition0%0/2
$sig ||= "&"
l!l
00
MC/DC0%0/1
$sig ||= "&"
$sig
Truth table0%0/2
A
A= $sig
Aresult
11
00
449 0 ▶ ("${sig}${name}" => 1, $sig eq '&' ? ($name => 1) : ())
Branch: 1 branch
BranchTrueFalseTotal
$sig eq '&' ? : 0 0 0
450 } @$export_fail
451 } : undef;
452  
453 527 my $menu = {
454 lookup => $lookup,
455 exports => $exports,
456 tags => $tags,
457 fail => $fail,
458 generate => $generate,
459 magic => $export_magic,
460 };
461  
462 527 return $menu;
463 }
464  
465 527 ▶sub parse_args {
Subroutine parse_args: called CC=1 SCAR=0.0
Pod undocumented
466 527 my $self = shift;
467 527 my ($into, @args) = @_;
468  
469 527 my $menu = $self->menu($into);
470  
471 527 my @out = $self->_parse_args($into, $menu, \@args);
472 527 pop @out;
473 527 return @out;
474 }
475  
476 544 ▶sub _parse_args {
Subroutine _parse_args: called CC=43 SCAR=51.0
477 544 my $self = shift;
478 544 my ($into, $menu, $args, $is_tag) = @_;
479  
480 544 my $from = $self->from;
481 544 my $main_menu = $self->menu($into);
482 544 ▶ $menu ||= $main_menu;
Condition33%1/3
$menu ||= $main_menu
l!l&&r!l&&!r
54400
MC/DC0%0/2
$menu ||= $main_menu
$menu $main_menu
Truth table33%1/3
A ||= B
A= $menuB= $main_menu
ABresult
1X1
011
000
483  
484 # First we strip out versions numbers and setters, this simplifies the logic late.
485 544 my @sets;
486 my @versions;
487 544 my @leftover;
488 544 for my $arg (@$args) {
489 177 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
490  
491 # Code refs are custom setters
492 # If the first character is an ASCII numeric then it is a version number
493 1633 ▶ push @sets => $arg and next if ref($arg) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "CODE" 0 1633 1633
Condition25%1/4
ref $arg eq 'CODE' && (push(@sets, $arg) && (next))
!ll
16330
push @sets, $arg and next
!ll
00
MC/DC0%0/2
ref $arg eq 'CODE' && (push(@sets, $arg) && (next))
ref $arg eq 'CODE' push @sets, $arg
Truth table33%1/3
A && B
A= ref $arg eq 'CODE'B= push @sets, $arg
ABresult
0X0
100
111
494 1633 ▶ push @versions => $arg xor next if $NUMERIC{substr($arg, 0, 1)};
Branch: 1 branch
BranchTrueFalseTotal
if $NUMERIC{substr($arg, 0, 1)} 0 1633 1633
Condition16%1/6
$NUMERIC{substr($arg, 0, 1)} && (push(@versions, $arg) ^^ (next))
!ll
16330
push @versions, $arg xor next
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/3
$NUMERIC{substr($arg, 0, 1)} && (push(@versions, $arg) ^^ (next))
$NUMERIC{substr($arg, 0, 1)} push @versions, $arg next
Truth table0%0/5
A && B xor C
A= $NUMERIC{substr($arg, 0, 1)}B= push @versions, $argC= next
ABCresult
0XX0
1110
1000
1101
1011
495 1633 push @leftover => $arg;
496 }
497  
498 544 ▶ $self->carp("Multiple setters specified, only 1 will be used") if @sets > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @sets > 1 0 544 544
499 544 my $set = pop @sets;
500  
501 544 $args = \@leftover;
502 544 ▶ @$args = (':DEFAULT') unless $is_tag || @$args || @versions;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_tag or @$args or @versions 4 540 544
Condition83%5/6
$is_tag or @$args or @versions
l!l&&r!l&&!r
54004
$is_tag or @$args
l!l&&r!l&&!r
175234
MC/DC66%2/3
$is_tag or @$args or @versions
$is_tag @$args @versions
Truth table75%3/4
A or B or C
A= $is_tagB= @$argsC= @versions
ABCresult
1XX1
01X1
0011
0000
503  
504 544 my %exclude;
505 my @import;
506  
507 544 ▶ while(my $full_arg = shift @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $full_arg = shift @$args) 1475 544 2019
508 1475 my $arg = $full_arg;
509 1475 my $lead = substr($arg, 0, 1);
510  
511 1475 my ($spec, $exc);
512 1475 ▶ if ($lead eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lead eq '!') { } 4 1471 1475
513 4 $exc = $lead;
514  
515 4 ▶ if ($arg eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq '!') { } 0 4 4
516 # If the current arg is just '!' then we are negating the next item.
517 0 $arg = shift @$args;
518 }
519 else {
520 # Strip off the '!'
521 4 substr($arg, 0, 1, '');
522 }
523  
524 # Exporter.pm legacy behavior
525 # negated first item implies starting with default set:
526 4 ▶ unshift @$args => ':DEFAULT' unless @import || keys %exclude || @versions;
Branch: 1 branch
BranchTrueFalseTotal
unless @import or keys %exclude or @versions 2 2 4
Condition66%4/6
@import or keys %exclude or @versions
l!l&&r!l&&!r
202
@import or keys %exclude
l!l&&r!l&&!r
202
MC/DC33%1/3
@import or keys %exclude or @versions
@import keys %exclude @versions
Truth table50%2/4
A or B or C
A= @importB= keys %excludeC= @versions
ABCresult
1XX1
01X1
0011
0000
527  
528 # Now we have a new lead character
529 4 $lead = substr($arg, 0, 1);
530 }
531 else {
532 # If the item is followed by a reference then they are asking us to
533 # do something special...
534 1471 ▶ $spec = ref($args->[0]) eq 'HASH' ? shift @$args : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $args->[0] eq 'HASH' ? : 164 1307 1471
535 }
536  
537 1475 ▶ if($lead eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lead eq ":") 17 1458 1475
538 17 substr($arg, 0, 1, '');
539 17 ▶ my $tag = $menu->{tags}->{$arg} or $self->croak("$from does not export the :$arg tag");
Branch: 1 branch
BranchTrueFalseTotal
my $tag = $menu->{"tags"}{$arg} or $self->croak("$from does not export the :$arg tag") 17 0 17
540  
541 17 my (undef, $cvers, $cexc, $cimp, $cset, $newmenu) = $self->_parse_args($into, $menu, $tag, $arg);
542  
543 17 ▶ $self->croak("Exporter specified version numbers (" . join(', ', @$cvers) . ") in the :$arg tag!")
Branch: 1 branch
BranchTrueFalseTotal
if @$cvers 0 17 17
544 if @$cvers;
545  
546 17 ▶ $self->croak("Exporter specified a custom symbol setter in the :$arg tag!")
Branch: 1 branch
BranchTrueFalseTotal
if $cset 0 17 17
547 if $cset;
548  
549 # Merge excludes
550 17 %exclude = (%exclude, %$cexc);
551  
552 17 ▶ if ($exc) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exc) { } 0 17 17
elsif ($spec and keys %$spec) { } 0 17 17
553 0 ▶ $exclude{$_} = 1 for grep {!ref($_) && substr($_, 0, 1) ne '+'} map {$_->[0]} @$cimp;
Condition0%0/3
!ref($_) && substr($_, 0, 1) ne '+'
!ll&&!rl&&r
000
MC/DC0%0/2
!ref($_) && substr($_, 0, 1) ne '+'
!ref($_) substr($_, 0, 1) ne '+'
Truth table0%0/3
not(A) && B
A= !ref($_)B= substr($_, 0, 1) ne '+'
ABresult
0X0
100
111
554 }
555 ▶ elsif ($spec && keys %$spec) {
Condition33%1/3
$spec and keys %$spec
!ll&&!rl&&r
0170
MC/DC0%0/2
$spec and keys %$spec
$spec keys %$spec
Truth table33%1/3
A and B
A= $specB= keys %$spec
ABresult
0X0
100
111
556 $self->croak("Cannot use '-as' to rename multiple symbols included by: $full_arg")
557 0 ▶ if $spec->{'-as'} && @$cimp > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"-as"} and @$cimp > 1 0 0 0
Condition0%0/3
$spec->{"-as"} and @$cimp > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$spec->{"-as"} and @$cimp > 1
$spec->{"-as"} @$cimp > 1
Truth table0%0/3
A and B
A= $spec->{"-as"}B= @$cimp > 1
ABresult
0X0
100
111
558  
559 0 for my $set (@$cimp) {
560 0 my ($sym, $cspec) = @$set;
561  
562 # Start with a blind squash, spec from tag overrides the ones inside.
563 0 my $nspec = {%$cspec, %$spec};
564  
565 0 ▶ $nspec->{'-prefix'} = "$spec->{'-prefix'}$cspec->{'-prefix'}" if $spec->{'-prefix'} && $cspec->{'-prefix'};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"-prefix"} and $cspec->{"-prefix"} 0 0 0
Condition0%0/3
$spec->{"-prefix"} and $cspec->{"-prefix"}
!ll&&!rl&&r
000
MC/DC0%0/2
$spec->{"-prefix"} and $cspec->{"-prefix"}
$spec->{"-prefix"} $cspec->{"-prefix"}
Truth table0%0/3
A and B
A= $spec->{"-prefix"}B= $cspec->{"-prefix"}
ABresult
0X0
100
111
566 0 ▶ $nspec->{'-postfix'} = "$cspec->{'-postfix'}$spec->{'-postfix'}" if $spec->{'-postfix'} && $cspec->{'-postfix'};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"-postfix"} and $cspec->{"-postfix"} 0 0 0
Condition0%0/3
$spec->{"-postfix"} and $cspec->{"-postfix"}
!ll&&!rl&&r
000
MC/DC0%0/2
$spec->{"-postfix"} and $cspec->{"-postfix"}
$spec->{"-postfix"} $cspec->{"-postfix"}
Truth table0%0/3
A and B
A= $spec->{"-postfix"}B= $cspec->{"-postfix"}
ABresult
0X0
100
111
567  
568 0 push @import => [$sym, $nspec];
569 }
570 }
571 else {
572 17 push @import => @$cimp;
573 }
574  
575 # New menu
576 17 $menu = $newmenu;
577  
578 17 next;
579 }
580  
581 # Process the item to figure out what symbols are being touched, if it
582 # is a tag or regex than it can be multiple.
583 1458 my @list;
584 1458 ▶ if(ref($arg) eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'Regexp') { } 0 1458 1458
elsif ($lead eq '/' and $arg =~ m[^/(.*)/$]) { } 0 1458 1458
585 0 @list = sort grep /$arg/, keys %{$menu->{lookup}};
586 }
587 ▶ elsif($lead eq '/' && $arg =~ m{^/(.*)/$}) {
Condition33%1/3
$lead eq "/" and $arg =~ m[^/(.*)/$]
!ll&&!rl&&r
145800
MC/DC0%0/2
$lead eq "/" and $arg =~ m[^/(.*)/$]
$lead eq "/" $arg =~ m[^/(.*)/$]
Truth table33%1/3
A and B
A= $lead eq "/"B= $arg =~ m[^/(.*)/$]
ABresult
0X0
100
111
588 0 my $pattern = $1;
589 0 @list = sort grep /$1/, keys %{$menu->{lookup}};
590 }
591 else {
592 1458 @list = ($arg);
593 }
594  
595 # Normalize list, always have a sigil
596 1458 ▶ @list = map {m/^\W/ ? $_ : "\&$_" } @list;
Branch: 1 branch
BranchTrueFalseTotal
/^\W/ ? : 198 1260 1458
597  
598 1458 ▶ if ($exc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exc) { } 4 1454 1458
599 4 $exclude{$_} = 1 for @list;
600 }
601 else {
602 $self->croak("Cannot use '-as' to rename multiple symbols included by: $full_arg")
603 1454 ▶ if $spec->{'-as'} && @list > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"-as"} and @list > 1 0 1454 1454
Condition66%2/3
$spec->{"-as"} and @list > 1
!ll&&!rl&&r
12901640
MC/DC0%0/2
$spec->{"-as"} and @list > 1
$spec->{"-as"} @list > 1
Truth table66%2/3
A and B
A= $spec->{"-as"}B= @list > 1
ABresult
0X0
100
111
604  
605 1454 push @import => [$_, $spec] for @list;
606 }
607 }
608  
609 544 return ($into, \@versions, \%exclude, \@import, $set, $menu);
610 }
611  
612 0 ▶sub _handle_fail {
Subroutine _handle_fail: not called CC=5 SCAR=34.0
613 0 my $self = shift;
614 0 my ($into, $import) = @_;
615  
616 0 my $from = $self->from;
617 0 my $menu = $self->menu($into);
618  
619 # Historically Exporter would strip the '&' off of sub names passed into export_fail.
620 0 ▶ my @fail = map {my $x = $_->[0]; $x =~ s/^&//; $x} grep $menu->{fail}->{$_->[0]}, @$import or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@fail) = map({my $x = $_->[0]; $x =~ s/^&//; $x;} grep($menu->{"fail"}{$_->[0]}, @$import)) or return 0 0 0
621  
622 0 ▶ my @real_fail = $from->can('export_fail') ? $from->export_fail(@fail) : @fail;
Branch: 1 branch
BranchTrueFalseTotal
$from->can('export_fail') ? : 0 0 0
623  
624 0 ▶ if (@real_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if (@real_fail) 0 0 0
625 $self->carp(qq["$_" is not implemented by the $from module on this architecture])
626 0 for @real_fail;
627  
628 0 $self->croak("Can't continue after import errors");
629 }
630  
631 0 $self->reload_menu($menu);
632 0 return;
633 }
634  
635 527 ▶sub _set_symbols {
Subroutine _set_symbols: called CC=23 SCAR=36.7
636 527 my $self = shift;
637 527 my ($into, $exclude, $import, $custom_set) = @_;
638  
639 527 my $from = $self->from;
640 527 my $menu = $self->menu($into);
641 527 my $caller = $self->get_caller();
642  
643 177 ▶ my $set_symbol = $custom_set || eval <<" EOT" || die $@;
Subroutine BEGIN: called CC=2 SCAR=8.3
Subroutine BEGIN: called CC=2 SCAR=8.3
Branch: 2 branches
BranchTrueFalseTotal
if defined $caller->[9] 381 0 381
if defined $caller->[9] 328 0 328
Condition40%2/5
$custom_set || eval qq[# Inherit the callers warning settings. If they have warnings and we\n# redefine their subs they will hear about it. If they do not have warnings\n# on they will not.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }\n#line $caller->[2] "$caller->[1]"\nsub { *{"$into\\::\$_[0]"} = \$_[1] }\n] || die($@)
l!l
5270
$custom_set or eval qq[# Inherit the callers warning settings. If they have warnings and we\n# redefine their subs they will hear about it. If they do not have warnings\n# on they will not.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }\n#line $caller->[2] "$caller->[1]"\nsub { *{"$into\\::\$_[0]"} = \$_[1] }\n]
l!l&&r!l&&!r
05270
MC/DC0%0/2
$custom_set || eval qq[# Inherit the callers warning settings. If they have warnings and we\n# redefine their subs they will hear about it. If they do not have warnings\n# on they will not.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }\n#line $caller->[2] "$caller->[1]"\nsub { *{"$into\\::\$_[0]"} = \$_[1] }\n] || die($@)
$custom_set eval qq[# Inherit the callers warning settings. If they have warnings and we\n# redefine their subs they will hear about it. If they do not have warnings\n# on they will not.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }\n#line $caller->[2] "$caller->[1]"\nsub { *{"$into\\::\$_[0]"} = \$_[1] }\n]
Truth table33%1/3
A or B
A= $custom_setB= eval qq[# Inherit the callers warning settings. If they have warnings and we\n# redefine their subs they will hear about it. If they do not have warnings\n# on they will not.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }\n#line $caller->[2] "$caller->[1]"\nsub { *{"$into\\::\$_[0]"} = \$_[1] }\n]
ABresult
1X1
011
000
644 # Inherit the callers warning settings. If they have warnings and we
645 # redefine their subs they will hear about it. If they do not have warnings
646 # on they will not.
647 BEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] }
648 #line $caller->[2] "$caller->[1]"
649 sub { *{"$into\\::\$_[0]"} = \$_[1] }
650 EOT
651  
652 527 for my $set (@$import) {
653 1454 my ($symbol, $spec) = @$set;
654  
655 1454 ▶ my ($sig, $name) = ($symbol =~ m/^(\W)(.*)$/) or die "Invalid symbol: $symbol";
Branch: 1 branch
BranchTrueFalseTotal
() = $symbol =~ /^(\W)(.*)$/ or die "Invalid symbol: $symbol" 1454 0 1454
656  
657 # Find the thing we are actually shoving in a new namespace
658 1454 my $ref = $menu->{exports}->{$symbol};
659 1454 ▶ $ref ||= $menu->{generate}->($symbol) if $menu->{generate};
Branch: 1 branch
BranchTrueFalseTotal
if $menu->{"generate"} 169 1285 1454
Condition33%1/3
$ref ||= $menu->{"generate"}->($symbol)
l!l&&r!l&&!r
16900
MC/DC0%0/2
$ref ||= $menu->{"generate"}->($symbol)
$ref $menu->{"generate"}->($symbol)
Truth table33%1/3
A ||= B
A= $refB= $menu->{"generate"}->($symbol)
ABresult
1X1
011
000
660  
661 # Exporter.pm supported listing items in @EXPORT that are not actually
662 # available for export. So if it is listed (lookup) but nothing is
663 # there (!$ref) we simply skip it.
664 1454 ▶ $self->croak("$from does not export $symbol") unless $ref || $menu->{lookup}->{"${sig}${name}"};
Branch: 1 branch
BranchTrueFalseTotal
unless $ref or $menu->{"lookup"}{"$sig$name"} 0 1454 1454
Condition33%1/3
$ref or $menu->{"lookup"}{"$sig$name"}
l!l&&r!l&&!r
145400
MC/DC0%0/2
$ref or $menu->{"lookup"}{"$sig$name"}
$ref $menu->{"lookup"}{"$sig$name"}
Truth table33%1/3
A or B
A= $refB= $menu->{"lookup"}{"$sig$name"}
ABresult
1X1
011
000
665 1454 ▶ next unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 1454 1454
666  
667 1454 my $type = ref($ref);
668 1454 ▶ $type = 'SCALAR' if $type eq 'REF';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "REF" 0 1454 1454
669 $self->croak("Symbol '$sig$name' requested, but reference (" . ref($ref) . ") does not match sigil ($sig)")
670 1454 ▶ if $ref && $type ne $SIG_TO_SLOT{$sig};
Branch: 1 branch
BranchTrueFalseTotal
if $ref and $type ne $SIG_TO_SLOT{$sig} 0 1454 1454
Condition33%1/3
$ref and $type ne $SIG_TO_SLOT{$sig}
!ll&&!rl&&r
014540
MC/DC0%0/2
$ref and $type ne $SIG_TO_SLOT{$sig}
$ref $type ne $SIG_TO_SLOT{$sig}
Truth table33%1/3
A and B
A= $refB= $type ne $SIG_TO_SLOT{$sig}
ABresult
0X0
100
111
671  
672 # If they directly renamed it then we assume they want it under the new
673 # name, otherwise excludes get kicked. It is useful to be able to
674 # exclude an item in a tag/match where the group has a prefix/postfix.
675 1454 ▶ next if $exclude->{"${sig}${name}"} && !$spec->{'-as'};
Branch: 1 branch
BranchTrueFalseTotal
if $$exclude{"$sig$name"} and not $spec->{"-as"} 4 1450 1454
Condition100%3/3
$$exclude{"$sig$name"} and not $spec->{"-as"}
!ll&&!rl&&r
144824
MC/DC100%2/2
$$exclude{"$sig$name"} and not $spec->{"-as"}
$$exclude{"$sig$name"} not $spec->{"-as"}
Truth table100%3/3
A and not(B)
A= $$exclude{"$sig$name"}B= not $spec->{"-as"}
ABresult
0X0
100
111
676  
677 1450 ▶ my $new_name = join '' => ($spec->{'-prefix'} || '', $spec->{'-as'} || $name, $spec->{'-postfix'} || '');
Condition57%4/7
$spec->{'-prefix'} || ''
l!l
01450
$spec->{'-as'} || $name
l!l&&r!l&&!r
16412860
$spec->{'-postfix'} || ''
l!l
01450
MC/DC0%0/1
$spec->{'-prefix'} || ''
$spec->{'-prefix'}
MC/DC0%0/2
$spec->{'-as'} || $name
$spec->{'-as'} $name
MC/DC0%0/1
$spec->{'-postfix'} || ''
$spec->{'-postfix'}
Truth table50%1/2
A
A= $spec->{'-prefix'}
Aresult
11
00
Truth table66%2/3
A || B
A= $spec->{'-as'}B= $name
ABresult
1X1
011
000
Truth table50%1/2
A
A= $spec->{'-postfix'}
Aresult
11
00
678  
679 # Set the symbol (finally!)
680 1450 $set_symbol->($new_name, $ref, sig => $sig, symbol => $symbol, into => $into, from => $from, spec => $spec);
681  
682 # The remaining things get skipped with a custom setter
683 1450 ▶ next if $custom_set;
Branch: 1 branch
BranchTrueFalseTotal
if $custom_set 0 1450 1450
684  
685 # Record the import so that we can 'unimport'
686 1450 ▶ push @{$IMPORTED{$into}} => $new_name if $sig eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "&" 1450 0 1450
687  
688 # Apply magic
689 1450 my $magic = $menu->{magic}->{$symbol};
690 1450 ▶ $magic ||= $menu->{magic}->{$name} if $sig eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "&" 1450 0 1450
Condition33%1/3
$magic ||= $menu->{"magic"}{$name}
l!l&&r!l&&!r
001450
MC/DC0%0/2
$magic ||= $menu->{"magic"}{$name}
$magic $menu->{"magic"}{$name}
Truth table33%1/3
A ||= B
A= $magicB= $menu->{"magic"}{$name}
ABresult
1X1
011
000
691 1450 ▶ $from->$magic(into => $into, orig_name => $name, new_name => $new_name, ref => $ref)
Branch: 1 branch
BranchTrueFalseTotal
if $magic 0 1450 1450
692 if $magic;
693 }
694 }
695  
696 ###########################################################################
697 #
698 # The rest of these are utility functions, not methods!
699 #
700  
701 0 ▶sub _version_check {
Subroutine _version_check: not called CC=2 SCAR=17.9
702 0 my ($mod, $caller, @versions) = @_;
703  
704 0 ▶ eval <<" EOT" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval qq[#line $caller->[2] "$caller->[1]"\n\$mod->VERSION(\$_) for \@versions;\n1;\n] or die $@ 0 0 0
705 #line $caller->[2] "$caller->[1]"
706 \$mod->VERSION(\$_) for \@versions;
707 1;
708 EOT
709 }
710  
711 857 ▶sub _mod_to_file {
Subroutine _mod_to_file: called CC=1 SCAR=0.0
712 857 my $file = shift;
713 857 $file =~ s{::}{/}g;
714 857 $file .= '.pm';
715 857 return $file;
716 }
717  
718 162 ▶sub _load_file {
Subroutine _load_file: called CC=2 SCAR=7.2
719 162 my ($caller, $file) = @_;
720  
721 162 ▶ eval <<" EOT" || die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval qq[#line $caller->[2] "$caller->[1]"\nrequire \$file;\n] or die $@ 162 0 162
722 #line $caller->[2] "$caller->[1]"
723 require \$file;
724 EOT
725 }
726  
727  
728 177 my %HEAVY_VARS = (
729 IMPORTER_MENU => 'CODE', # Origin package has a custom menu
730 EXPORT_FAIL => 'ARRAY', # Origin package has a failure handler
731 EXPORT_GEN => 'HASH', # Origin package has generators
732 EXPORT_ANON => 'HASH', # Origin package has anonymous exports
733 EXPORT_MAGIC => 'HASH', # Origin package has magic to apply post-export
734 );
735  
736 857 ▶sub optimal_import {
Subroutine optimal_import: called CC=11 SCAR=24.7
Pod undocumented
737 857 my ($from, $into, $caller, @args) = @_;
738  
739 857 ▶ defined(*{"$from\::$_"}{$HEAVY_VARS{$_}}) and return 0 for keys %HEAVY_VARS;
Branch: 1 branch
BranchTrueFalseTotal
defined *{"${from}::$_";}{$HEAVY_VARS{$_}} and return 0 354 3207 3561
740  
741 # Default to @EXPORT
742 503 ▶ @args = @{"$from\::EXPORT"} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 328 175 503
743  
744 # Subs will be listed without sigil in %allowed, all others keep sigil
745 my %allowed = map +(substr($_, 0, 1) eq '&' ? substr($_, 1) : $_ => 1),
746 503 ▶ @{"$from\::EXPORT"}, @{"$from\::EXPORT_OK"};
Branch: 1 branch
BranchTrueFalseTotal
substr($_, 0, 1) eq '&' ? : 0 29444 29444
747  
748 # First check if it is allowed, stripping '&' if necessary, which will also
749 # let scalars in, we will deal with those shortly.
750 # If not allowed return 0 (need to do a heavy import)
751 # if it is allowed then see if it has a CODE slot, if so use it, otherwise
752 # we have a symbol that needs heavy due to non-sub, autoload, etc.
753 # This will not allow $foo to import foo() since '$from' still contains the
754 # sigil making it an invalid symbol name in our globref below.
755 my %final = map +(
756 (!ref($_) && ($allowed{$_} || (substr($_, 0, 1, "") eq '&' && $allowed{$_})))
757 503 ▶ ? ($_ => *{"$from\::$_"}{CODE} || return 0)
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && ($allowed{$_} || substr($_, 0, 1, '') eq '&' && $allowed{$_}) ? : 28695 173 28868
Condition63%7/11
not ref $_ and $allowed{$_} || substr($_, 0, 1, "") eq "&" && $allowed{$_}
!ll&&!rl&&r
1621128695
$allowed{$_} or substr($_, 0, 1, "") eq "&" and $allowed{$_}
l!l&&r!l&&!r
28695011
substr($_, 0, 1, "") eq "&" and $allowed{$_}
!ll&&!rl&&r
1100
*{"${from}::$_";}{"CODE"} or return 0
l!l
286950
MC/DC50%2/4
not ref $_ and $allowed{$_} || substr($_, 0, 1, "") eq "&" && $allowed{$_}
not ref $_ $allowed{$_} substr($_, 0, 1, "") eq "&" $allowed{$_}
MC/DC0%0/1
*{"${from}::$_";}{"CODE"} or return 0
*{"${from}::$_";}{"CODE"}
Truth table60%3/5
not(A) and B or C and D
A= not ref $_B= $allowed{$_}C= substr($_, 0, 1, "") eq "&"D= $allowed{$_}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table50%1/2
A
A= *{"${from}::$_";}{"CODE"}
Aresult
11
00
758 : return 0
759 ), @args;
760  
761 330 ▶ eval <<" EOT" || die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval qq[# If the caller has redefine warnings enabled then we want to warn them if\n# their import redefines things.\nBEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] };\n#line $caller->[2] "$caller->[1]"\n(*{"$into\\::\$_"} = \$final{\$_}, push \@{\$Test2::Util::Importer::IMPORTED{\$into}} => \$_) for keys %final;\n1;\n] or die $@ 330 0 330
762 # If the caller has redefine warnings enabled then we want to warn them if
763 # their import redefines things.
764 BEGIN { \${^WARNING_BITS} = \$caller->[9] if defined \$caller->[9] };
765 #line $caller->[2] "$caller->[1]"
766 (*{"$into\\::\$_"} = \$final{\$_}, push \@{\$Test2::Util::Importer::IMPORTED{\$into}} => \$_) for keys %final;
767 1;
768 EOT
769 }
770  
771 177 1;
772  
773 __END__
« lib/Test/Builder/Tester.pm ↑ Summary blib/lib/Test2/IPC.pm »