/usr/local/lib/perl5/5.44.0/base.pm

filter: Statementstmt 0.0% 0 / 93 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 37 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 210 CC 39 SCAR 53.9
CC
39
Cov
0%
import
462.0
inherit_fields
90.0
has_fields
20.0
CRAP 218.2
« /usr/local/lib/perl5/5.44.0/vars.pm ↑ Summary /usr/local/lib/perl5/5.44.0/HTTP/Tiny.pm »
1 use 5.008;
2 package base;
3  
4 use strict 'vars';
5 our $VERSION = '2.27';
6 $VERSION =~ tr/_//d;
7  
8 # simplest way to avoid indexing of the package: no package statement
9 0 ▶sub base::__inc::unhook { @INC = grep !(ref eq 'CODE' && $_ == $_[0]), @INC }
Subroutine unhook: not called CC=2 SCAR=17.9
Condition0%0/3
ref $_ eq 'CODE' && $_ == $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq 'CODE' && $_ == $_[0]
ref $_ eq 'CODE' $_ == $_[0]
Truth table0%0/3
A && B
A= ref $_ eq 'CODE'B= $_ == $_[0]
ABresult
0X0
100
111
10 # instance is blessed array of coderefs to be removed from @INC at scope exit
11 0 ▶sub base::__inc::scope_guard::DESTROY { base::__inc::unhook $_ for @{$_[0]} }
Subroutine DESTROY: not called CC=2 SCAR=17.9
12  
13 # constant.pm is slow
14 sub SUCCESS () { 1 }
15  
16 sub PUBLIC () { 2**0 }
17 sub PRIVATE () { 2**1 }
18 sub INHERITED () { 2**2 }
19 sub PROTECTED () { 2**3 }
20  
21  
22 my $Fattr = \%fields::attr;
23  
24 sub has_fields {
25 0 ▶ my($base) = shift;
Subroutine has_fields: not called CC=4 SCAR=30.0
Pod undocumented
26 0 my $fglob = ${"$base\::"}{FIELDS};
27 0 ▶ return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$fglob && 'GLOB' eq ref $fglob && *$fglob{'HASH'} ? : 0 0 0
Condition0%0/5
$fglob and "GLOB" eq ref $fglob and *$fglob{"HASH"}
!ll
00
$fglob and "GLOB" eq ref $fglob
!ll&&!rl&&r
000
MC/DC0%0/2
$fglob and "GLOB" eq ref $fglob and *$fglob{"HASH"}
$fglob "GLOB" eq ref $fglob
Truth table0%0/3
A and B
A= $fglobB= "GLOB" eq ref $fglob
ABresult
0X0
100
111
28 }
29  
30 sub has_attr {
31 0 ▶ my($proto) = shift;
Subroutine has_attr: not called CC=2 SCAR=17.9
Pod undocumented
32 0 ▶ my($class) = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
33 0 return exists $Fattr->{$class};
34 }
35  
36 sub get_attr {
37 0 ▶ $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
Subroutine get_attr: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $$Fattr{$_[0]} 0 0 0
38 0 return $Fattr->{$_[0]};
39 }
40  
41 if ($] < 5.009) {
42 *get_fields = sub {
43 # Shut up a possible typo warning.
44 () = \%{$_[0].'::FIELDS'};
45 my $f = \%{$_[0].'::FIELDS'};
46  
47 # should be centralized in fields? perhaps
48 # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' }
49 # is used here anyway, it doesn't matter.
50 bless $f, 'pseudohash' if (ref($f) ne 'pseudohash');
51  
52 return $f;
53 }
54 }
55 else {
56 *get_fields = sub {
57 # Shut up a possible typo warning.
58 0 ▶ () = \%{$_[0].'::FIELDS'};
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 return \%{$_[0].'::FIELDS'};
60 }
61 }
62  
63 if ($] < 5.008) {
64 *_module_to_filename = sub {
65 (my $fn = $_[0]) =~ s!::!/!g;
66 $fn .= '.pm';
67 return $fn;
68 }
69 }
70 else {
71 *_module_to_filename = sub {
72 0 ▶ (my $fn = $_[0]) =~ s!::!/!g;
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 $fn .= '.pm';
74 0 utf8::encode($fn);
75 0 return $fn;
76 }
77 }
78  
79  
80 sub import {
81 0 ▶ my $class = shift;
Subroutine import: not called CC=21 SCAR=61.4
82  
83 0 ▶ return SUCCESS unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
84  
85 # List of base classes from which we will inherit %FIELDS.
86 0 my $fields_base;
87  
88 0 my $inheritor = caller(0);
89  
90 0 my @bases;
91 0 foreach my $base (@_) {
92 0 ▶ if ( $inheritor eq $base ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inheritor eq $base) 0 0 0
93 0 warn "Class '$inheritor' tried to inherit from itself\n";
94 }
95  
96 0 ▶ next if grep $_->isa($base), ($inheritor, @bases);
Branch: 1 branch
BranchTrueFalseTotal
if grep $_->isa($base), ($inheritor, @bases) 0 0 0
97  
98 # Following blocks help isolate $SIG{__DIE__} and @INC changes
99 {
100 0 my $sigdie;
101 {
102 0 local $SIG{__DIE__};
103 0 my $fn = _module_to_filename($base);
104 0 my $dot_hidden;
105 0 eval {
106 0 my $guard;
107 0 ▶ if ($INC[-1] eq '.' && %{"$base\::"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC[-1] eq "." and %{"${base}::";}) 0 0 0
Condition0%0/3
$INC[-1] eq "." and %{"${base}::";}
!ll&&!rl&&r
000
MC/DC0%0/2
$INC[-1] eq "." and %{"${base}::";}
$INC[-1] eq "." %{"${base}::";}
Truth table0%0/3
A and B
A= $INC[-1] eq "."B= %{"${base}::";}
ABresult
0X0
100
111
108 # So: the package already exists => this an optional load
109 # And: there is a dot at the end of @INC => we want to hide it
110 # However: we only want to hide it during our *own* require()
111 # (i.e. without affecting nested require()s).
112 # So we add a hook to @INC whose job is to hide the dot, but which
113 # first checks checks the callstack depth, because within nested
114 # require()s the callstack is deeper.
115 # Since CORE::GLOBAL::require makes it unknowable in advance what
116 # the exact relevant callstack depth will be, we have to record it
117 # inside a hook. So we put another hook just for that at the front
118 # of @INC, where it's guaranteed to run -- immediately.
119 # The dot-hiding hook does its job by sitting directly in front of
120 # the dot and removing itself from @INC when reached. This causes
121 # the dot to move up one index in @INC, causing the loop inside
122 # pp_require() to skip it.
123 # Loaded coded may disturb this precise arrangement, but that's OK
124 # because the hook is inert by that time. It is only active during
125 # the top-level require(), when @INC is in our control. The only
126 # possible gotcha is if other hooks already in @INC modify @INC in
127 # some way during that initial require().
128 # Note that this jiggery hookery works just fine recursively: if
129 # a module loaded via base.pm uses base.pm itself, there will be
130 # one pair of hooks in @INC per base::import call frame, but the
131 # pairs from different nestings do not interfere with each other.
132 0 my $lvl;
133 0 ▶ unshift @INC, sub { return if defined $lvl; 1 while defined caller ++$lvl; () };
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if defined $lvl 0 0 0
defined caller ++$lvl and do { '???' } 0 0 0
134 0 ▶ splice @INC, -1, 0, sub { return if defined caller $lvl; ++$dot_hidden, &base::__inc::unhook; () };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if defined caller $lvl 0 0 0
135 0 $guard = bless [ @INC[0,-2] ], 'base::__inc::scope_guard';
136 }
137 0 require $fn
138 };
139 0 ▶ if ($dot_hidden && (my @fn = grep -e && !( -d _ || -b _ ), $fn.'c', $fn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dot_hidden and my(@fn) = grep((-e $_ && !(-d _ || -b _)), $fn . 'c', $fn)) 0 0 0
Condition0%0/9
$dot_hidden and my(@fn) = grep((-e $_ && !(-d _ || -b _)), $fn . 'c', $fn)
!ll&&!rl&&r
000
-e $_ && !(-d _ || -b _)
!ll&&!rl&&r
000
-d _ || -b _
l!l&&r!l&&!r
000
MC/DC0%0/2
$dot_hidden and my(@fn) = grep((-e $_ && !(-d _ || -b _)), $fn . 'c', $fn)
$dot_hidden my(@fn) = grep((-e $_ && !(-d _ || -b _)), $fn . 'c', $fn)
MC/DC0%0/3
-e $_ && !(-d _ || -b _)
-e $_ -d _ -b _
Truth table0%0/3
A and B
A= $dot_hiddenB= my(@fn) = grep((-e $_ && !(-d _ || -b _)), $fn . 'c', $fn)
ABresult
0X0
100
111
Truth table0%0/4
A && not(B || C)
A= -e $_B= -d _C= -b _
ABCresult
0XX0
11X0
1010
1001
140 0 require Carp;
141 0 Carp::croak(<<ERROR);
142 Base class package "$base" is not empty but "$fn[0]" exists in the current directory.
143 To help avoid security issues, base.pm now refuses to load optional modules
144 from the current working directory when it is the last entry in \@INC.
145 If your software worked on previous versions of Perl, the best solution
146 is to use FindBin to detect the path properly and to add that path to
147 \@INC. As a last resort, you can re-enable looking in the current working
148 directory by adding "use lib '.'" to your code.
149 ERROR
150 }
151 # Only ignore "Can't locate" errors from our eval require.
152 # Other fatal errors (syntax etc) must be reported.
153 #
154 # changing the check here is fragile - if the check
155 # here isn't catching every error you want, you should
156 # probably be using parent.pm, which doesn't try to
157 # guess whether require is needed or failed,
158 # see [perl #118561]
159 0 ▶ die if $@ && $@ !~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s
Branch: 1 branch
BranchTrueFalseTotal
if $@ and not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s or $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/ 0 0 0
Condition0%0/6
$@ and not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s or $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/
l!l&&r!l&&!r
000
$@ and not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s
!ll&&!rl&&r
000
MC/DC0%0/3
$@ and not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s or $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/
$@ not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/
Truth table0%0/5
A and not(B) or C
A= $@B= not $@ =~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/sC= $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/
ABCresult
11X1
0X11
1011
0X00
1000
160 || $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/;
161 0 ▶ unless (%{"$base\::"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%{"${base}::";}) 0 0 0
162 0 require Carp;
163 0 local $" = " ";
164 0 Carp::croak(<<ERROR);
165 Base class package "$base" is empty.
166 (Perhaps you need to 'use' the module which defines that package first,
167 or make that module available in \@INC (\@INC contains: @INC).
168 ERROR
169 }
170 0 ▶ $sigdie = $SIG{__DIE__} || undef;
Condition0%0/2
$SIG{'__DIE__'} || undef
l!l
00
MC/DC0%0/1
$SIG{'__DIE__'} || undef
$SIG{'__DIE__'}
Truth table0%0/2
A
A= $SIG{'__DIE__'}
Aresult
11
00
171 }
172 # Make sure a global $SIG{__DIE__} makes it out of the localization.
173 0 ▶ $SIG{__DIE__} = $sigdie if defined $sigdie;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sigdie 0 0 0
174 }
175 0 push @bases, $base;
176  
177 0 ▶ if ( has_fields($base) || has_attr($base) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_fields($base) or has_attr($base)) 0 0 0
Condition0%0/3
has_fields($base) or has_attr($base)
l!l&&r!l&&!r
000
MC/DC0%0/2
has_fields($base) or has_attr($base)
has_fields($base) has_attr($base)
Truth table0%0/3
A or B
A= has_fields($base)B= has_attr($base)
ABresult
1X1
011
000
178 # No multiple fields inheritance *suck*
179 0 ▶ if ($fields_base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields_base) { } 0 0 0
180 0 require Carp;
181 0 Carp::croak("Can't multiply inherit fields");
182 } else {
183 0 $fields_base = $base;
184 }
185 }
186 }
187 # Save this until the end so it's all or nothing if the above loop croaks.
188 0 push @{"$inheritor\::ISA"}, @bases;
189  
190 0 ▶ if( defined $fields_base ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields_base) 0 0 0
191 0 inherit_fields($inheritor, $fields_base);
192 }
193 }
194  
195  
196 sub inherit_fields {
197 0 ▶ my($derived, $base) = @_;
Subroutine inherit_fields: not called CC=9 SCAR=45.0
Pod undocumented
198  
199 0 ▶ return SUCCESS unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $base 0 0 0
200  
201 0 my $battr = get_attr($base);
202 0 my $dattr = get_attr($derived);
203 0 my $dfields = get_fields($derived);
204 0 my $bfields = get_fields($base);
205  
206 0 $dattr->[0] = @$battr;
207  
208 0 ▶ if( keys %$dfields ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$dfields) 0 0 0
209 0 warn <<"END";
210 $derived is inheriting from $base but already has its own fields!
211 This will cause problems. Be sure you use base BEFORE declaring fields.
212 END
213  
214 }
215  
216 # Iterate through the base's fields adding all the non-private
217 # ones to the derived class. Hang on to the original attribute
218 # (Public, Private, etc...) and add Inherited.
219 # This is all too complicated to do efficiently with add_fields().
220 0 ▶ while (my($k,$v) = each %$bfields) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$bfields) 0 0 0
221 0 my $fno;
222 0 ▶ if ($fno = $dfields->{$k} and $fno != $v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fno = $dfields->{$k} and $fno != $v) 0 0 0
Condition0%0/3
$fno = $dfields->{$k} and $fno != $v
!ll&&!rl&&r
000
MC/DC0%0/2
$fno = $dfields->{$k} and $fno != $v
$fno = $dfields->{$k} $fno != $v
Truth table0%0/3
A and B
A= $fno = $dfields->{$k}B= $fno != $v
ABresult
0X0
100
111
223 0 require Carp;
224 0 Carp::croak ("Inherited fields can't override existing fields");
225 }
226  
227 0 ▶ if( $battr->[$v] & PRIVATE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($battr->[$v] & 2) { } 0 0 0
228 0 $dattr->[$v] = PRIVATE | INHERITED;
229 }
230 else {
231 0 $dattr->[$v] = INHERITED | $battr->[$v];
232 0 $dfields->{$k} = $v;
233 }
234 }
235  
236 0 foreach my $idx (1..$#{$battr}) {
237 0 ▶ next if defined $dattr->[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if defined $dattr->[$idx] 0 0 0
238 0 $dattr->[$idx] = $battr->[$idx] & INHERITED;
239 }
240 }
241  
242  
243 1;
244  
245 __END__
« /usr/local/lib/perl5/5.44.0/vars.pm ↑ Summary /usr/local/lib/perl5/5.44.0/HTTP/Tiny.pm »