blib/lib/Package/Stash/PP.pm

filter: Statementstmt 95.6% 198 / 207 Branchbran 84.2% 64 / 76 Conditioncond 80.8% 59 / 73 MC/DCmcdc 60.5% 23 / 38 Subroutinesub 100% 35 / 35 Podpod 9.0% 1 / 11 totaltotal 86.3% 380 / 440 CC 65 SCAR 16.5
CC
65
Cov
90%
add_symbol
11.0
_valid_for_type
10.0
get_symbol
9.4
CRAP 5.2
↑ Summary lib/Package/Stash.pm »
1 package Package::Stash::PP;
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 # ABSTRACT: Pure perl implementation of the Package::Stash API
5  
6 22 our $VERSION = '0.40';
7  
8 24 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Scalar::Util qw(blessed reftype weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 # before 5.12, assigning to the ISA glob would make it lose its magical ->isa
13 # powers
14 24 ▶use constant BROKEN_ISA_ASSIGNMENT => ($] < 5.012);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 # before 5.10, stashes don't ever seem to drop to a refcount of zero, so
16 # weakening them isn't helpful
17 24 ▶use constant BROKEN_WEAK_STASH => ($] < 5.010);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 # before 5.10, the scalar slot was always treated as existing if the
19 # glob existed
20 24 ▶use constant BROKEN_SCALAR_INITIALIZATION => ($] < 5.010);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 # add_method on anon stashes triggers rt.perl #1804 otherwise
22 # fixed in perl commit v5.13.3-70-g0fe688f
23 24 ▶use constant BROKEN_GLOB_ASSIGNMENT => ($] < 5.013004);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 # pre-5.10, ->isa lookups were cached in the ::ISA::CACHE:: slot
25 24 ▶use constant HAS_ISA_CACHE => ($] < 5.010);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 #pod =head1 SYNOPSIS
28 #pod
29 #pod use Package::Stash;
30 #pod
31 #pod =head1 DESCRIPTION
32 #pod
33 #pod This is a backend for L<Package::Stash> implemented in pure perl, for those without a compiler or who would like to use this inline in scripts.
34 #pod
35 #pod =cut
36  
37 62 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod undocumented
38 63 my $class = shift;
39 63 my ($package) = @_;
40  
41 63 ▶ if (!defined($package) || (ref($package) && reftype($package) ne 'HASH')) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $package or ref $package and builtin::reftype($package) ne 'HASH') { } 4 58 62
elsif (ref $package and builtin::reftype($package) eq 'HASH') { } 1 57 58
elsif ($package =~ /\A[0-9A-Z_a-z]+(?:::[0-9A-Z_a-z]+)*\z/) { } 47 10 57
Condition100%6/6
not defined $package or ref $package and builtin::reftype($package) ne "HASH"
l!l&&r!l&&!r
2258
ref $package and builtin::reftype($package) ne "HASH"
!ll&&!rl&&r
5712
MC/DC100%3/3
not defined $package or ref $package and builtin::reftype($package) ne "HASH"
not defined $package ref $package builtin::reftype($package) ne "HASH"
Truth table100%4/4
not(A) or B and C
A= not defined $packageB= ref $packageC= builtin::reftype($package) ne "HASH"
ABCresult
1XX1
0111
00X0
0100
42 4 confess "Package::Stash->new must be passed the name of the "
43 . "package to access";
44 }
45 ▶ elsif (ref($package) && reftype($package) eq 'HASH') {
Condition66%2/3
ref $package and builtin::reftype($package) eq "HASH"
!ll&&!rl&&r
5701
MC/DC50%1/2
ref $package and builtin::reftype($package) eq "HASH"
ref $package builtin::reftype($package) eq "HASH"
Truth table66%2/3
A and B
A= ref $packageB= builtin::reftype($package) eq "HASH"
ABresult
0X0
100
111
46 1 confess "The PP implementation of Package::Stash does not support "
47 . "anonymous stashes before perl 5.14"
48 if BROKEN_GLOB_ASSIGNMENT;
49  
50 1 return bless {
51 'namespace' => $package,
52 }, $class;
53 }
54 elsif ($package =~ /\A[0-9A-Z_a-z]+(?:::[0-9A-Z_a-z]+)*\z/) {
55 47 return bless {
56 'package' => $package,
57 }, $class;
58 }
59 else {
60 10 confess "$package is not a module name";
61 }
62  
63 }
64  
65 49 ▶sub name {
Subroutine name: called CC=3 SCAR=11.1
Pod undocumented
66 49 ▶ confess "Can't call name as a class method"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 2 47 49
67 unless blessed($_[0]);
68 confess "Can't get the name of an anonymous package"
69 47 ▶ unless defined($_[0]->{package});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0]{"package"} 0 47 47
70 47 return $_[0]->{package};
71 }
72  
73 372 ▶sub namespace {
Subroutine namespace: called CC=3 SCAR=11.0
Pod undocumented
74 372 ▶ confess "Can't call namespace as a class method"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 372 372
75 unless blessed($_[0]);
76  
77 372 if (BROKEN_WEAK_STASH) {
78 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 return \%{$_[0]->name . '::'};
80 }
81 else {
82 372 ▶ return $_[0]->{namespace} if defined $_[0]->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]{"namespace"} 327 45 372
83  
84 {
85 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 45 $_[0]->{namespace} = \%{$_[0]->name . '::'};
87 }
88  
89 45 weaken($_[0]->{namespace});
90  
91 45 return $_[0]->{namespace};
92 }
93 }
94  
95 {
96 22 my %SIGIL_MAP = (
97 '$' => 'SCALAR',
98 '@' => 'ARRAY',
99 '%' => 'HASH',
100 '&' => 'CODE',
101 '' => 'IO',
102 );
103  
104 359 ▶ sub _deconstruct_variable_name {
Subroutine _deconstruct_variable_name: called CC=6 SCAR=18.0
105 359 my ($variable) = @_;
106  
107 359 my @ret;
108 359 ▶ if (ref($variable) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $variable eq 'HASH') { } 88 271 359
109 88 @ret = @{$variable}{qw[name sigil type]};
110 }
111 else {
112 271 ▶ (defined $variable && length $variable)
Branch: 1 branch
BranchTrueFalseTotal
defined $variable and length $variable or confess("You must pass a variable name") 271 0 271
Condition33%1/3
defined $variable and length $variable
!ll&&!rl&&r
00271
MC/DC0%0/2
defined $variable and length $variable
defined $variable length $variable
Truth table33%1/3
A and B
A= defined $variableB= length $variable
ABresult
0X0
100
111
113 || confess "You must pass a variable name";
114  
115 271 my $sigil = substr($variable, 0, 1, '');
116  
117 271 ▶ if (exists $SIGIL_MAP{$sigil}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SIGIL_MAP{$sigil}) { } 245 26 271
118 245 @ret = ($variable, $sigil, $SIGIL_MAP{$sigil});
119 }
120 else {
121 26 @ret = ("${sigil}${variable}", '', $SIGIL_MAP{''});
122 }
123 }
124  
125 # XXX in pure perl, this will access things in inner packages,
126 # in xs, this will segfault - probably look more into this at
127 # some point
128 359 ▶ ($ret[0] !~ /::/)
Branch: 1 branch
BranchTrueFalseTotal
$ret[0] =~ /::/ and confess("Variable names may not contain ::") 3 356 359
129 || confess "Variable names may not contain ::";
130  
131 356 return @ret;
132 }
133 }
134  
135 22 ▶sub _valid_for_type {
Subroutine _valid_for_type: called CC=10 SCAR=23.0
136 68 my ($value, $type) = @_;
137 68 ▶ if ($type eq 'HASH' || $type eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'HASH' or $type eq 'ARRAY' or $type eq 'IO' or $type eq 'CODE') { } 43 25 68
Condition100%9/9
$type eq "HASH" or $type eq "ARRAY" or $type eq "IO" or $type eq "CODE"
l!l&&r!l&&!r
301325
$type eq "HASH" or $type eq "ARRAY" or $type eq "IO"
l!l&&r!l&&!r
26438
$type eq "HASH" or $type eq "ARRAY"
l!l&&r!l&&!r
121442
MC/DC100%4/4
$type eq "HASH" or $type eq "ARRAY" or $type eq "IO" or $type eq "CODE"
$type eq "HASH" $type eq "ARRAY" $type eq "IO" $type eq "CODE"
Truth table100%5/5
A or B or C or D
A= $type eq "HASH"B= $type eq "ARRAY"C= $type eq "IO"D= $type eq "CODE"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
138 || $type eq 'IO' || $type eq 'CODE') {
139 43 return reftype($value) eq $type;
140 }
141 else {
142 25 my $ref = reftype($value);
143 25 ▶ return !defined($ref) || $ref eq 'SCALAR' || $ref eq 'REF' || $ref eq 'LVALUE' || $ref eq 'REGEXP' || $ref eq 'VSTRING';
Condition93%14/15
!defined($ref) || $ref eq 'SCALAR' || $ref eq 'REF' || $ref eq 'LVALUE' || $ref eq 'REGEXP' || $ref eq 'VSTRING'
l!l&&r!l&&!r
1915
not defined $ref or $ref eq "SCALAR" or $ref eq "REF" or $ref eq "LVALUE" or $ref eq "REGEXP"
l!l&&r!l&&!r
1816
not defined $ref or $ref eq "SCALAR" or $ref eq "REF" or $ref eq "LVALUE"
l!l&&r!l&&!r
1717
not defined $ref or $ref eq "SCALAR" or $ref eq "REF"
l!l&&r!l&&!r
1708
not defined $ref or $ref eq "SCALAR"
l!l&&r!l&&!r
6118
MC/DC83%5/6
!defined($ref) || $ref eq 'SCALAR' || $ref eq 'REF' || $ref eq 'LVALUE' || $ref eq 'REGEXP' || $ref eq 'VSTRING'
not defined $ref $ref eq "SCALAR" $ref eq "REF" $ref eq "LVALUE" $ref eq "REGEXP" $ref eq 'VSTRING'
Truth table85%6/7
not(A) or B or C or D or E || F
A= not defined $refB= $ref eq "SCALAR"C= $ref eq "REF"D= $ref eq "LVALUE"E= $ref eq "REGEXP"F= $ref eq 'VSTRING'
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
144 }
145 }
146  
147 78 ▶sub add_symbol {
Subroutine add_symbol: called CC=11 SCAR=24.0
Pod undocumented
148 78 my ($self, $variable, $initial_value, %opts) = @_;
149  
150 78 my ($name, $sigil, $type) = _deconstruct_variable_name($variable);
151  
152 77 ▶ if (@_ > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 68 9 77
153 68 ▶ _valid_for_type($initial_value, $type)
Branch: 1 branch
BranchTrueFalseTotal
_valid_for_type($initial_value, $type) or confess("$initial_value is not of type $type") 59 9 68
154 || confess "$initial_value is not of type $type";
155  
156 # cheap fail-fast check for PERLDBf_SUBLINE and '&'
157 59 ▶ if ($^P and $^P & 0x10 && $sigil eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^P and ($^P & 16 and $sigil eq "&")) 2 57 59
Condition66%4/6
$^P and ($^P & 16 and $sigil eq "&")
!ll&&!rl&&r
0572
$^P & 16 and $sigil eq "&"
!ll&&!rl&&r
5702
MC/DC33%1/3
$^P and ($^P & 16 and $sigil eq "&")
$^P $^P & 16 $sigil eq "&"
Truth table50%2/4
A and B and C
A= $^PB= $^P & 16C= $sigil eq "&"
ABCresult
0XX0
10X0
1100
1111
158 2 my $filename = $opts{filename};
159 2 my $first_line_num = $opts{first_line_num};
160  
161 2 ▶ (undef, $filename, $first_line_num) = caller
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 1 1 2
162 if not defined $filename;
163  
164 2 ▶ my $last_line_num = $opts{last_line_num} || ($first_line_num ||= 0);
Condition60%3/5
$opts{'last_line_num'} || ($first_line_num ||= 0)
l!l&&r!l&&!r
110
$first_line_num ||= 0
l!l
10
MC/DC0%0/2
$opts{'last_line_num'} || ($first_line_num ||= 0)
$opts{'last_line_num'} ($first_line_num ||= 0)
MC/DC0%0/1
$first_line_num ||= 0
$first_line_num
Truth table66%2/3
A || B
A= $opts{'last_line_num'}B= ($first_line_num ||= 0)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $first_line_num
Aresult
11
00
165  
166 # http://perldoc.perl.org/perldebguts.html#Debugger-Internals
167 2 $DB::sub{$self->name . '::' . $name} = "$filename:$first_line_num-$last_line_num";
168 }
169 }
170  
171 68 if (BROKEN_GLOB_ASSIGNMENT) {
172 if (@_ > 2) {
173 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
174 24 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
175 *{ $self->name . '::' . $name } = ref $initial_value
176 ? $initial_value : \$initial_value;
177 }
178 else {
179 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
180 if (BROKEN_ISA_ASSIGNMENT && $name eq 'ISA') {
181 *{ $self->name . '::' . $name };
182 }
183 else {
184 my $undef = _undef_ref_for_type($type);
185 *{ $self->name . '::' . $name } = $undef;
186 }
187 }
188 }
189 else {
190 68 my $namespace = $self->namespace;
191 {
192 # using glob aliasing instead of Symbol::gensym, because otherwise,
193 # magic doesn't get applied properly.
194 # see <20120710063744.19360.qmail@lists-nntp.develooper.com> on p5p
195 68 local *__ANON__:: = $namespace;
196 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
197 24 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
198 24 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
199 68 *{"__ANON__::$name"};
200 }
201  
202 68 ▶ if (@_ > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) { } 59 9 68
203 24 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
204 59 ▶ *{ $namespace->{$name} } = ref $initial_value
Branch: 1 branch
BranchTrueFalseTotal
ref $initial_value ? : 53 6 59
205 ? $initial_value : \$initial_value;
206 }
207 else {
208 9 return if BROKEN_ISA_ASSIGNMENT && $name eq 'ISA';
209 9 *{ $namespace->{$name} } = _undef_ref_for_type($type);
210 }
211 }
212 }
213  
214 9 ▶sub _undef_ref_for_type {
Subroutine _undef_ref_for_type: called CC=6 SCAR=19.1
215 9 my ($type) = @_;
216  
217 9 ▶ if ($type eq 'ARRAY') {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 3 6 9
elsif ($type eq 'HASH') { } 2 4 6
elsif ($type eq 'SCALAR') { } 3 1 4
elsif ($type eq 'IO') { } 1 0 1
elsif ($type eq 'CODE') { } 0 0 0
218 3 return [];
219 }
220 elsif ($type eq 'HASH') {
221 2 return {};
222 }
223 elsif ($type eq 'SCALAR') {
224 3 return \undef;
225 }
226 elsif ($type eq 'IO') {
227 1 return Symbol::geniosym;
228 }
229 elsif ($type eq 'CODE') {
230 0 confess "Don't know how to vivify CODE variables";
231 }
232 else {
233 0 confess "Unknown type $type in vivication";
234 }
235 }
236  
237 10 ▶sub remove_glob {
Subroutine remove_glob: called CC=1 SCAR=0.0
Pod undocumented
238 10 my ($self, $name) = @_;
239 10 delete $self->namespace->{$name};
240 }
241  
242 124 ▶sub has_symbol {
Subroutine has_symbol: called CC=6 SCAR=18.0
Pod undocumented
243 124 my ($self, $variable) = @_;
244  
245 124 my ($name, $sigil, $type) = _deconstruct_variable_name($variable);
246  
247 124 my $namespace = $self->namespace;
248  
249 124 ▶ return unless exists $namespace->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $namespace->{$name} 4 120 124
250  
251 120 my $entry_ref = \$namespace->{$name};
252 120 ▶ if (reftype($entry_ref) eq 'GLOB') {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($entry_ref) eq 'GLOB') { } 120 0 120
253 120 ▶ if ($type eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'SCALAR') { } 31 89 120
254 31 if (BROKEN_SCALAR_INITIALIZATION) {
255 return defined ${ *{$entry_ref}{$type} };
256 }
257 else {
258 31 my $sv = B::svref_2object($entry_ref)->SV;
259 31 ▶ return $sv->isa('B::SV')
Condition83%5/6
$sv->isa('B::SV') || $sv->isa('B::SPECIAL') && $B::specialsv_name[$$sv] ne 'Nullsv'
l!l&&r!l&&!r
16114
$sv->isa("B::SPECIAL") and $B::specialsv_name[$$sv] ne "Nullsv"
!ll&&!rl&&r
0141
MC/DC66%2/3
$sv->isa('B::SV') || $sv->isa('B::SPECIAL') && $B::specialsv_name[$$sv] ne 'Nullsv'
$sv->isa('B::SV') $sv->isa("B::SPECIAL") $B::specialsv_name[$$sv] ne "Nullsv"
Truth table75%3/4
A || B and C
A= $sv->isa('B::SV')B= $sv->isa("B::SPECIAL")C= $B::specialsv_name[$$sv] ne "Nullsv"
ABCresult
1XX1
0111
00X0
0100
260 || ($sv->isa('B::SPECIAL')
261 && $B::specialsv_name[$$sv] ne 'Nullsv');
262 }
263 }
264 else {
265 89 return defined *{$entry_ref}{$type};
266 }
267 }
268 else {
269 # a symbol table entry can be -1 (stub), string (stub with prototype),
270 # or reference (constant)
271 0 return $type eq 'CODE';
272 }
273 }
274  
275 147 ▶sub get_symbol {
Subroutine get_symbol: called CC=8 SCAR=22.4
Pod undocumented
276 147 my ($self, $variable, %opts) = @_;
277  
278 147 my ($name, $sigil, $type) = _deconstruct_variable_name($variable);
279  
280 145 my $namespace = $self->namespace;
281  
282 145 ▶ if (!exists $namespace->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $namespace->{$name}) 13 132 145
283 13 ▶ if ($opts{vivify}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'vivify'}) { } 7 6 13
284 7 $self->add_symbol($variable);
285 }
286 else {
287 6 return undef;
288 }
289 }
290  
291 139 my $entry_ref = \$namespace->{$name};
292  
293 139 ▶ if (ref($entry_ref) eq 'GLOB') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry_ref eq 'GLOB') { } 138 1 139
294 138 return *{$entry_ref}{$type};
295 }
296 else {
297 1 ▶ if ($type eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'CODE') { } 1 0 1
298 1 ▶ if (BROKEN_GLOB_ASSIGNMENT || defined($self->{package})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"package"}) 0 1 1
299 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
300 0 return \&{ $self->name . '::' . $name };
301 }
302  
303 # XXX we should really be able to support arbitrary anonymous
304 # stashes here... (not just via Package::Anon)
305 1 ▶ if (blessed($namespace) && $namespace->isa('Package::Anon')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($namespace) and $namespace->isa('Package::Anon')) { } 0 1 1
Condition33%1/3
builtin::blessed($namespace) and $namespace->isa("Package::Anon")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($namespace) and $namespace->isa("Package::Anon")
builtin::blessed($namespace) $namespace->isa("Package::Anon")
Truth table33%1/3
A and B
A= builtin::blessed($namespace)B= $namespace->isa("Package::Anon")
ABresult
0X0
100
111
306 # ->can will call gv_init for us, which inflates the glob
307 # don't know how to do this in general
308 0 $namespace->bless(\(my $foo))->can($name);
309 }
310 else {
311 1 confess "Don't know how to inflate a " . ref($entry_ref)
312 . " into a full coderef (perhaps you could use"
313 . " Package::Anon instead of a bare stash?)"
314 }
315  
316 0 return *{ $namespace->{$name} }{CODE};
317 }
318 else {
319 0 return undef;
320 }
321 }
322 }
323  
324 16 ▶sub get_or_add_symbol {
Subroutine get_or_add_symbol: called CC=1 SCAR=0.0
Pod undocumented
325 16 my $self = shift;
326 16 $self->get_symbol(@_, vivify => 1);
327 }
328  
329 10 ▶sub remove_symbol {
Subroutine remove_symbol: called CC=7 SCAR=19.5
Pod documented
330 10 my ($self, $variable) = @_;
331  
332 10 my ($name, $sigil, $type) = _deconstruct_variable_name($variable);
333  
334 # FIXME:
335 # no doubt this is grossly inefficient and
336 # could be done much easier and faster in XS
337  
338 10 my %desc = (
339 SCALAR => { sigil => '$', type => 'SCALAR', name => $name },
340 ARRAY => { sigil => '@', type => 'ARRAY', name => $name },
341 HASH => { sigil => '%', type => 'HASH', name => $name },
342 CODE => { sigil => '&', type => 'CODE', name => $name },
343 IO => { sigil => '', type => 'IO', name => $name },
344 );
345 10 ▶ confess "This should never ever ever happen" if !$desc{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $desc{$type} 0 10 10
346  
347 10 ▶ my @types_to_store = grep { $type ne $_ && $self->has_symbol($desc{$_}) }
Condition100%3/3
$type ne $_ && $self->has_symbol($desc{$_})
!ll&&!rl&&r
102020
MC/DC100%2/2
$type ne $_ && $self->has_symbol($desc{$_})
$type ne $_ $self->has_symbol($desc{$_})
Truth table100%3/3
A && B
A= $type ne $_B= $self->has_symbol($desc{$_})
ABresult
0X0
100
111
348 keys %desc;
349 10 my %values = map { $_, $self->get_symbol($desc{$_}) } @types_to_store;
350  
351 $values{SCALAR} = $self->get_symbol($desc{SCALAR})
352 if !defined $values{SCALAR}
353 10 ▶ && $type ne 'SCALAR'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $values{"SCALAR"} and $type ne "SCALAR" and !!0 0 10 10
Condition100%5/5
not defined $values{"SCALAR"} and $type ne "SCALAR" and !!0
!ll
82
not defined $values{"SCALAR"} and $type ne "SCALAR"
!ll&&!rl&&r
622
MC/DC100%2/2
not defined $values{"SCALAR"} and $type ne "SCALAR" and !!0
not defined $values{"SCALAR"} $type ne "SCALAR"
Truth table100%3/3
not(A) and B
A= not defined $values{"SCALAR"}B= $type ne "SCALAR"
ABresult
0X0
100
111
354 && BROKEN_SCALAR_INITIALIZATION;
355  
356 10 $self->remove_glob($name);
357  
358 $self->add_symbol($desc{$_} => $values{$_})
359 10 for grep { defined $values{$_} } keys %values;
360 }
361  
362 22 ▶sub list_all_symbols {
Subroutine list_all_symbols: called CC=7 SCAR=19.5
Pod undocumented
363 22 my ($self, $type_filter) = @_;
364  
365 22 my $namespace = $self->namespace;
366 22 if (HAS_ISA_CACHE) {
367 return grep { $_ ne '::ISA::CACHE::' } keys %{$namespace}
368 unless defined $type_filter;
369 }
370 else {
371 22 ▶ return keys %{$namespace}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type_filter 4 18 22
372 unless defined $type_filter;
373 }
374  
375 # NOTE:
376 # or we can filter based on
377 # type (SCALAR|ARRAY|HASH|CODE)
378 18 ▶ if ($type_filter eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type_filter eq 'CODE') { } 7 11 18
elsif ($type_filter eq 'SCALAR') { } 3 8 11
379 return grep {
380 # any non-typeglob in the symbol table is a constant or stub
381 ref(\$namespace->{$_}) ne 'GLOB'
382 # regular subs are stored in the CODE slot of the typeglob
383 53 || defined(*{$namespace->{$_}}{CODE})
384 7 ▶ } keys %{$namespace};
Condition66%2/3
ref \$namespace->{$_} ne 'GLOB' || defined *{$namespace->{$_};}{'CODE'}
l!l&&r!l&&!r
02528
MC/DC50%1/2
ref \$namespace->{$_} ne 'GLOB' || defined *{$namespace->{$_};}{'CODE'}
ref \$namespace->{$_} ne 'GLOB' defined *{$namespace->{$_};}{'CODE'}
Truth table66%2/3
A || B
A= ref \$namespace->{$_} ne 'GLOB'B= defined *{$namespace->{$_};}{'CODE'}
ABresult
1X1
011
000
385 }
386 elsif ($type_filter eq 'SCALAR') {
387 return grep {
388 !(HAS_ISA_CACHE && $_ eq '::ISA::CACHE::') &&
389 (BROKEN_SCALAR_INITIALIZATION
390 ? (ref(\$namespace->{$_}) eq 'GLOB'
391 && defined(${*{$namespace->{$_}}{'SCALAR'}}))
392 17 : (do {
393 17 my $entry = \$namespace->{$_};
394 17 ▶ ref($entry) eq 'GLOB'
Condition66%2/3
ref $entry eq 'GLOB' && B::svref_2object($entry)->SV->isa('B::SV')
!ll&&!rl&&r
0152
MC/DC50%1/2
ref $entry eq 'GLOB' && B::svref_2object($entry)->SV->isa('B::SV')
ref $entry eq 'GLOB' B::svref_2object($entry)->SV->isa('B::SV')
Truth table66%2/3
A && B
A= ref $entry eq 'GLOB'B= B::svref_2object($entry)->SV->isa('B::SV')
ABresult
0X0
100
111
395 && B::svref_2object($entry)->SV->isa('B::SV')
396 }))
397 3 } keys %{$namespace};
398 }
399 else {
400 return grep {
401 ref(\$namespace->{$_}) eq 'GLOB'
402 60 ▶ && defined(*{$namespace->{$_}}{$type_filter})
Condition66%2/3
ref \$namespace->{$_} eq 'GLOB' && defined *{$namespace->{$_};}{$type_filter}
!ll&&!rl&&r
04614
MC/DC50%1/2
ref \$namespace->{$_} eq 'GLOB' && defined *{$namespace->{$_};}{$type_filter}
ref \$namespace->{$_} eq 'GLOB' defined *{$namespace->{$_};}{$type_filter}
Truth table66%2/3
A && B
A= ref \$namespace->{$_} eq 'GLOB'B= defined *{$namespace->{$_};}{$type_filter}
ABresult
0X0
100
111
403 8 } keys %{$namespace};
404 }
405 }
406  
407 6 ▶sub get_all_symbols {
Subroutine get_all_symbols: called CC=2 SCAR=6.9
Pod undocumented
408 6 my ($self, $type_filter) = @_;
409  
410 6 my $namespace = $self->namespace;
411 6 ▶ return { %{$namespace} } unless defined $type_filter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type_filter 2 4 6
412  
413 return {
414 4 map { $_ => $self->get_symbol({name => $_, type => $type_filter}) }
415 $self->list_all_symbols($type_filter)
416 }
417 }
418  
419 __END__
↑ Summary lib/Package/Stash.pm »