blib/lib/Sub/Delete.pm

filter: Statementstmt 100% 40 / 40 Branchbran 75.0% 15 / 20 Conditioncond 71.4% 15 / 21 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 81.0% 81 / 100 CC 21 SCAR 29.2
CC
21
Cov
86%
delete_sub
23.5
BEGIN
1.0
BEGIN
1.0
CRAP 18.5
↑ Summary
1 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Sub::Delete;
4  
5 1 $VERSION = '1.00003';
6 1 @EXPORT = delete_sub;
7 1 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use constant point0 => 0+$] eq 5.01;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # This sub must come before any lexical vars.
11 19 ▶sub strict_eval($) {
Subroutine strict_eval: called CC=1 SCAR=0.0
Pod undocumented
12 19 local %^H if point0;
13 19 local *@;
14 use#
15 1 ▶ strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
17 eval shift
18 19 }
19  
20 1 my %sigils = qw( SCALAR $ ARRAY @ HASH % );
21  
22 16 ▶sub delete_sub {
Subroutine delete_sub: called CC=21 SCAR=31.6
Pod undocumented
23 16 my $sub = shift;
24 16 ▶ my($stashname, $key) = $sub =~ /(.*::)((?:(?!::).)*)\z/s
Branch: 1 branch
BranchTrueFalseTotal
$sub =~ /(.*::)((?:(?!::).)*)\z/s ? : 4 12 16
25 ? ($1,$2) : (caller()."::", $sub);
26 16 ▶ exists +(my $stash = \%$stashname)->{$key} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists +(my $stash = \%$stashname)->{$key} or return 16 0 16
27 ref $stash->{$key} eq 'SCALAR' and # perl5.10 constant
28 16 ▶ delete $stash->{$key}, return;
Branch: 1 branch
BranchTrueFalseTotal
ref $stash->{$key} eq "SCALAR" and delete $stash->{$key}, return 0 16 16
29 16 my $globname = "$stashname$key";
30 16 my $glob = *$globname; # autovivify the glob in case future perl
31 16 ▶ defined *$glob{CODE} or return; # versions add new funny stuff
Branch: 1 branch
BranchTrueFalseTotal
defined *$glob{"CODE"} or return 16 0 16
32 16 ▶ my $check_importedness
Condition33%1/3
$stashname =~ /^(?:(?!\d)\w*(?:::\w*)*)\z/ && $key =~ /^(?!\d)\w+\z/
!ll&&!rl&&r
0016
MC/DC0%0/2
$stashname =~ /^(?:(?!\d)\w*(?:::\w*)*)\z/ && $key =~ /^(?!\d)\w+\z/
$stashname =~ /^(?:(?!\d)\w*(?:::\w*)*)\z/ $key =~ /^(?!\d)\w+\z/
Truth table33%1/3
A && B
A= $stashname =~ /^(?:(?!\d)\w*(?:::\w*)*)\z/B= $key =~ /^(?!\d)\w+\z/
ABresult
0X0
100
111
33 = $stashname =~ /^(?:(?!\d)\w*(?:::\w*)*)\z/
34 && $key =~ /^(?!\d)\w+\z/;
35 16 my %imported_slots;
36 my $package;
37 16 ▶ if($check_importedness) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_importedness) 16 0 16
38 16 $package = substr $stashname, 0, -2;
39 16 for (qw "SCALAR ARRAY HASH") {
40 48 ▶ defined *$glob{$_} or next;
Branch: 1 branch
BranchTrueFalseTotal
defined *$glob{$_} or next 19 29 48
41 19 $imported_slots{$_} = strict_eval
42 "package $package; 0 && $sigils{$_}$key; 1"
43 }
44 }
45 16 delete $stash->{$key};
46 keys %imported_slots == 1 and exists $imported_slots{SCALAR}
47 and !$imported_slots{SCALAR} and Internals::SvREFCNT $$glob =>== 1
48 and !defined *$glob{IO} and !defined *$glob{FORMAT}
49 16 ▶ and return; # empty glob
Branch: 1 branch
BranchTrueFalseTotal
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"} and &Internals::SvREFCNT(\$$glob) == 1 and not defined *$glob{"IO"} and not defined *$glob{"FORMAT"} and return 11 5 16
Condition80%12/15
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"} and &Internals::SvREFCNT(\$$glob) == 1 and not defined *$glob{"IO"} and not defined *$glob{"FORMAT"}
!ll&&!rl&&r
5011
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"} and &Internals::SvREFCNT(\$$glob) == 1 and not defined *$glob{"IO"}
!ll&&!rl&&r
5011
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"} and &Internals::SvREFCNT(\$$glob) == 1
!ll&&!rl&&r
4111
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"}
!ll&&!rl&&r
3112
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"}
!ll&&!rl&&r
3013
MC/DC50%3/6
keys %imported_slots == 1 and exists $imported_slots{"SCALAR"} and not $imported_slots{"SCALAR"} and &Internals::SvREFCNT(\$$glob) == 1 and not defined *$glob{"IO"} and not defined *$glob{"FORMAT"}
keys %imported_slots == 1 exists $imported_slots{"SCALAR"} not $imported_slots{"SCALAR"} &Internals::SvREFCNT(\$$glob) == 1 not defined *$glob{"IO"} not defined *$glob{"FORMAT"}
Truth table57%4/7
A and B and not(C) and D and not(E) and not(F)
A= keys %imported_slots == 1B= exists $imported_slots{"SCALAR"}C= not $imported_slots{"SCALAR"}D= &Internals::SvREFCNT(\$$glob) == 1E= not defined *$glob{"IO"}F= not defined *$glob{"FORMAT"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
50 5 my $newglob = \*$globname;
51 5 local *alias = *$newglob;
52 defined *$glob{$_} and (
53 !$check_importedness || $imported_slots{$_}
54 ? *$newglob
55 : *alias
56 ) = *$glob{$_}
57 5 ▶ for qw "SCALAR ARRAY HASH";
Branch: 2 branches
BranchTrueFalseTotal
defined *$glob{$_} and !$check_importedness || $imported_slots{$_} ? *$newglob : *alias = *$glob{$_} 8 7 15
!$check_importedness || $imported_slots{$_} ? : 1 7 8
Condition66%2/3
not $check_importedness or $imported_slots{$_}
l!l&&r!l&&!r
017
MC/DC50%1/2
not $check_importedness or $imported_slots{$_}
not $check_importedness $imported_slots{$_}
Truth table66%2/3
not(A) or B
A= not $check_importednessB= $imported_slots{$_}
ABresult
1X1
011
000
58 defined *$glob{$_} and *$newglob = *$glob{$_}
59 5 ▶ for qw "IO FORMAT";
Branch: 1 branch
BranchTrueFalseTotal
defined *$glob{$_} and *$newglob = *$glob{$_} 0 10 10
60 return # nothing;
61 5 }
62  
63 1 1;
64  
65 __END__
↑ Summary