blib/lib/Data/Dumper.pm

filter: Statementstmt 97.6% 373 / 382 Branchbran 84.9% 265 / 312 Conditioncond 87.3% 97 / 111 MC/DCmcdc 84.1% 53 / 63 Subroutinesub 95.6% 44 / 46 Podpod 23.3% 7 / 30 totaltotal 88.8% 839 / 944 CC 177 SCAR 39.8
CC
177
Cov
91%
_dump
106.8
Seen
11.0
qquote
10.4
CRAP 53.3
↑ Summary Dumper.xs »
1 #
2 # Data/Dumper.pm
3 #
4 # convert perl data structures into perl syntax suitable for both printing
5 # and eval
6 #
7 # Documentation at the __END__
8 #
9  
10 package Data::Dumper;
11  
12 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 #$| = 1;
16  
17 27 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 27 require Exporter;
19  
20 27 ▶use constant IS_PRE_516_PERL => "$]" < 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 27 ▶use constant SUPPORTS_CORE_BOOLS => defined &builtin::is_bool;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 27 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # Globals people alter.
26 27 our ( $Indent, $Trailingcomma, $Purity, $Pad, $Varname, $Useqq, $Terse, $Freezer,
27 $Toaster, $Deepcopy, $Quotekeys, $Bless, $Maxdepth, $Pair, $Sortkeys,
28 $Deparse, $Sparseseen, $Maxrecurse, $Useperl );
29  
30 27 our ( @ISA, @EXPORT, @EXPORT_OK, $VERSION );
31  
32 27 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
33 27 $VERSION = '2.193'; # Don't forget to set version and release
34 # date in POD below!
35  
36 27 @ISA = qw(Exporter);
37 27 @EXPORT = qw(Dumper);
38 27 @EXPORT_OK = qw(DumperX);
39  
40 # if run under miniperl, or otherwise lacking dynamic loading,
41 # XSLoader should be attempted to load, or the pure perl flag
42 # toggled on load failure.
43 27 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require XSLoader; XSLoader::load("Data::Dumper"); 1 } } or $Data::Dumper::Useperl = 1 27 0 27
44 27 require XSLoader;
45 27 XSLoader::load( 'Data::Dumper' );
46 27 1
47 }
48 or $Useperl = 1;
49 }
50  
51 27 my $IS_ASCII = ord 'A' == 65;
52  
53 # module vars and their defaults
54 27 ▶$Indent = 2 unless defined $Indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Indent 27 0 27
55 27 ▶$Trailingcomma = 0 unless defined $Trailingcomma;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Trailingcomma 27 0 27
56 27 ▶$Purity = 0 unless defined $Purity;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Purity 27 0 27
57 27 ▶$Pad = "" unless defined $Pad;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Pad 27 0 27
58 27 ▶$Varname = "VAR" unless defined $Varname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Varname 27 0 27
59 27 ▶$Useqq = 0 unless defined $Useqq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Useqq 27 0 27
60 27 ▶$Terse = 0 unless defined $Terse;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Terse 27 0 27
61 27 ▶$Freezer = "" unless defined $Freezer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Freezer 27 0 27
62 27 ▶$Toaster = "" unless defined $Toaster;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Toaster 27 0 27
63 27 ▶$Deepcopy = 0 unless defined $Deepcopy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Deepcopy 27 0 27
64 27 ▶$Quotekeys = 1 unless defined $Quotekeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Quotekeys 27 0 27
65 27 ▶$Bless = "bless" unless defined $Bless;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Bless 27 0 27
66 #$Expdepth = 0 unless defined $Expdepth;
67 27 ▶$Maxdepth = 0 unless defined $Maxdepth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Maxdepth 27 0 27
68 27 ▶$Pair = ' => ' unless defined $Pair;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Pair 27 0 27
69 27 ▶$Useperl = 0 unless defined $Useperl;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Useperl 27 0 27
70 27 ▶$Sortkeys = 0 unless defined $Sortkeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Sortkeys 27 0 27
71 27 ▶$Deparse = 0 unless defined $Deparse;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Deparse 27 0 27
72 27 ▶$Sparseseen = 0 unless defined $Sparseseen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Sparseseen 27 0 27
73 27 ▶$Maxrecurse = 1000 unless defined $Maxrecurse;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Maxrecurse 27 0 27
74  
75 #
76 # expects an arrayref of values to be dumped.
77 # can optionally pass an arrayref of names for the values.
78 # names must have leading $ sign stripped. begin the name with *
79 # to cause output of arrays and hashes rather than refs.
80 #
81 709 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
82 709 my($c, $v, $n) = @_;
83  
84 709 ▶ Carp::croak("Usage: PACKAGE->new(ARRAYREF, [ARRAYREF])")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and ref $v eq "ARRAY" 2 707 709
Condition100%3/3
defined $v and ref $v eq "ARRAY"
!ll&&!rl&&r
11707
MC/DC100%2/2
defined $v and ref $v eq "ARRAY"
defined $v ref $v eq "ARRAY"
Truth table100%3/3
A and B
A= defined $vB= ref $v eq "ARRAY"
ABresult
0X0
100
111
85 unless (defined($v) && (ref($v) eq 'ARRAY'));
86 707 ▶ $n = [] unless (defined($n) && (ref($n) eq 'ARRAY'));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and ref $n eq "ARRAY" 503 204 707
Condition100%3/3
defined $n and ref $n eq "ARRAY"
!ll&&!rl&&r
5021204
MC/DC100%2/2
defined $n and ref $n eq "ARRAY"
defined $n ref $n eq "ARRAY"
Truth table100%3/3
A and B
A= defined $nB= ref $n eq "ARRAY"
ABresult
0X0
100
111
87  
88 707 my($s) = {
89 level => 0, # current recursive depth
90 indent => $Indent, # various styles of indenting
91 trailingcomma => $Trailingcomma, # whether to add comma after last elem
92 pad => $Pad, # all lines prefixed by this string
93 xpad => "", # padding-per-level
94 apad => "", # added padding for hash keys n such
95 sep => "", # list separator
96 pair => $Pair, # hash key/value separator: defaults to ' => '
97 seen => {}, # local (nested) refs (id => [name, val])
98 todump => $v, # values to dump []
99 names => $n, # optional names for values []
100 varname => $Varname, # prefix to use for tagging nameless ones
101 purity => $Purity, # degree to which output is evalable
102 useqq => $Useqq, # use "" for strings (backslashitis ensues)
103 terse => $Terse, # avoid name output (where feasible)
104 freezer => $Freezer, # name of Freezer method for objects
105 toaster => $Toaster, # name of method to revive objects
106 deepcopy => $Deepcopy, # do not cross-ref, except to stop recursion
107 quotekeys => $Quotekeys, # quote hash keys
108 'bless' => $Bless, # keyword to use for "bless"
109 # expdepth => $Expdepth, # cutoff depth for explicit dumping
110 maxdepth => $Maxdepth, # depth beyond which we give up
111 maxrecurse => $Maxrecurse, # depth beyond which we abort
112 useperl => $Useperl, # use the pure Perl implementation
113 sortkeys => $Sortkeys, # flag or filter for sorting hash keys
114 deparse => $Deparse, # use B::Deparse for coderefs
115 noseen => $Sparseseen, # do not populate the seen hash unless necessary
116 };
117  
118 707 ▶ if ($Indent > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Data::Dumper::Indent > 0) 669 38 707
119 669 $s->{xpad} = " ";
120 669 $s->{sep} = "\n";
121 }
122 707 return bless($s, $c);
123 }
124  
125 # Packed numeric addresses take less memory. Plus pack is faster than sprintf
126  
127 2011 ▶sub format_refaddr {
Subroutine format_refaddr: called CC=1 SCAR=0.0
Pod undocumented
128 2011 require Scalar::Util;
129 2011 pack "J", Scalar::Util::refaddr(shift);
130 };
131  
132 #
133 # add-to or query the table of already seen references
134 #
135 26 ▶sub Seen {
Subroutine Seen: called CC=11 SCAR=24.0
Pod documented
136 26 my($s, $g) = @_;
137 26 ▶ if (defined($g) && (ref($g) eq 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g and ref $g eq 'HASH') { } 24 2 26
Condition100%3/3
defined $g and ref $g eq "HASH"
!ll&&!rl&&r
1124
MC/DC100%2/2
defined $g and ref $g eq "HASH"
defined $g ref $g eq "HASH"
Truth table100%3/3
A and B
A= defined $gB= ref $g eq "HASH"
ABresult
0X0
100
111
138 24 my($k, $v, $id);
139 24 ▶ while (($k, $v) = each %$g) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$g) 24 24 48
140 24 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 23 1 24
141 23 ▶ if (ref $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 22 1 23
142 22 $id = format_refaddr($v);
143 22 ▶ if ($k =~ /^[*](.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ /^[*](.*)$/) { } 16 6 22
elsif (not $k =~ /^\$/) { } 5 1 6
144 16 ▶ $k = (ref $v eq 'ARRAY') ? ( "\\\@" . $1 ) :
Branch: 3 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 5 11 16
ref $v eq 'HASH' ? : 1 10 11
ref $v eq 'CODE' ? : 9 1 10
145 (ref $v eq 'HASH') ? ( "\\\%" . $1 ) :
146 (ref $v eq 'CODE') ? ( "\\\&" . $1 ) :
147 ( "\$" . $1 ) ;
148 }
149 elsif ($k !~ /^\$/) {
150 5 $k = "\$" . $k;
151 }
152 22 $s->{seen}{$id} = [$k, $v];
153 }
154 else {
155 1 Carp::carp("Only refs supported, ignoring non-ref item \$$k");
156 }
157 }
158 else {
159 1 Carp::carp("Value of ref must be defined; ignoring undefined item \$$k");
160 }
161 }
162 24 return $s;
163 }
164 else {
165 0 return map { @$_ } values %{$s->{seen}};
166 }
167 }
168  
169 #
170 # set or query the values to be dumped
171 #
172 6 ▶sub Values {
Subroutine Values: called CC=3 SCAR=11.0
Pod documented
173 6 my($s, $v) = @_;
174 6 ▶ if (defined($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 2 4 6
175 2 ▶ if (ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 1 1 2
176 1 $s->{todump} = [@$v]; # make a copy
177 1 return $s;
178 }
179 else {
180 1 Carp::croak("Argument to Values, if provided, must be array ref");
181 }
182 }
183 else {
184 4 return @{$s->{todump}};
185 }
186 }
187  
188 #
189 # set or query the names of the values to be dumped
190 #
191 5 ▶sub Names {
Subroutine Names: called CC=3 SCAR=11.0
Pod documented
192 5 my($s, $n) = @_;
193 5 ▶ if (defined($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) { } 4 1 5
194 4 ▶ if (ref($n) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n eq 'ARRAY') { } 3 1 4
195 3 $s->{names} = [@$n]; # make a copy
196 3 return $s;
197 }
198 else {
199 1 Carp::croak("Argument to Names, if provided, must be array ref");
200 }
201 }
202 else {
203 1 return @{$s->{names}};
204 }
205 }
206  
207 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
208  
209 535 ▶sub Dump {
Subroutine Dump: called CC=6 SCAR=18.2
Pod documented
210 return &Dumpxs
211 unless $Data::Dumper::Useperl || (ref($_[0]) && $_[0]->{useperl})
212 # Use pure perl version on earlier releases on EBCDIC platforms
213 535 ▶ || (! $IS_ASCII && "$]" < 5.021_010);
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless $Data::Dumper::Useperl or ref $_[0] and $_[0]{"useperl"} or not $IS_ASCII and "$]" < "5.02101" 202 333 535
Condition75%9/12
$Data::Dumper::Useperl or ref $_[0] and $_[0]{"useperl"} or not $IS_ASCII and "$]" < "5.02101"
l!l&&r!l&&!r
3330202
$Data::Dumper::Useperl or ref $_[0] and $_[0]{"useperl"}
l!l&&r!l&&!r
3312202
ref $_[0] and $_[0]{"useperl"}
!ll&&!rl&&r
851172
not $IS_ASCII and "$]" < "5.02101"
!ll&&!rl&&r
20200
MC/DC60%3/5
$Data::Dumper::Useperl or ref $_[0] and $_[0]{"useperl"} or not $IS_ASCII and "$]" < "5.02101"
$Data::Dumper::Useperl ref $_[0] $_[0]{"useperl"} not $IS_ASCII "$]" < "5.02101"
Truth table50%4/8
A or B and C or not(D) and E
A= $Data::Dumper::UseperlB= ref $_[0]C= $_[0]{"useperl"}D= not $IS_ASCIIE= "$]" < "5.02101"
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
214 333 return &Dumpperl;
215 }
216  
217 #
218 # dump the refs in the current dumper object.
219 # expects same args as new() if called via package name.
220 #
221 27 our @post;
222 333 ▶sub Dumpperl {
Subroutine Dumpperl: called CC=8 SCAR=20.8
Pod undocumented
223 333 my($s) = shift;
224 333 my(@out, $val, $name);
225 333 my($i) = 0;
226 333 local(@post);
227  
228 333 ▶ $s = $s->new(@_) unless ref $s;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s 167 166 333
229  
230 333 for $val (@{$s->{todump}}) {
231 1027 @post = ();
232 1027 $name = $s->{names}[$i++];
233 1027 $name = $s->_refine_name($name, $val, $i);
234  
235 1027 my $valstr;
236 {
237 1027 local($s->{apad}) = $s->{apad};
238 1027 ▶ $s->{apad} .= ' ' x (length($name) + 3) if $s->{indent} >= 2 and !$s->{terse};
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 2 and not $s->{"terse"} 166 861 1027
Condition100%3/3
$s->{"indent"} >= 2 and not $s->{"terse"}
!ll&&!rl&&r
8601166
MC/DC100%2/2
$s->{"indent"} >= 2 and not $s->{"terse"}
$s->{"indent"} >= 2 not $s->{"terse"}
Truth table100%3/3
A and not(B)
A= $s->{"indent"} >= 2B= not $s->{"terse"}
ABresult
0X0
100
111
239 1027 $valstr = $s->_dump($val, $name);
240 }
241  
242 1022 ▶ $valstr = "$name = " . $valstr . ';' if @post or !$s->{terse};
Branch: 1 branch
BranchTrueFalseTotal
if @Data::Dumper::post or not $s->{"terse"} 1016 6 1022
Condition100%3/3
@Data::Dumper::post or not $s->{"terse"}
l!l&&r!l&&!r
329846
MC/DC100%2/2
@Data::Dumper::post or not $s->{"terse"}
@Data::Dumper::post not $s->{"terse"}
Truth table100%3/3
A or not(B)
A= @Data::Dumper::postB= not $s->{"terse"}
ABresult
1X1
011
000
243 1022 my $out = $s->_compose_out($valstr, \@post);
244  
245 1022 push @out, $out;
246 }
247 328 ▶ return wantarray ? @out : join('', @out);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 84 244 328
248 }
249  
250 # wrap string in single quotes (escaping if needed)
251 1058 ▶sub _quote {
Subroutine _quote: called CC=1 SCAR=0.0
252 1058 my $val = shift;
253 1058 $val =~ s/([\\\'])/\\$1/g;
254 1058 return "'" . $val . "'";
255 }
256  
257 # Old Perls (5.14-) have trouble resetting vstring magic when it is no
258 # longer valid.
259 27 ▶use constant _bad_vsmg => defined &_vstring && (_vstring(~v0)||'') eq "v0";
Subroutine BEGIN: called CC=3 SCAR=12.5
Condition40%2/5
defined &Data::Dumper::_vstring && (&_vstring("\377") || '') eq 'v0'
!ll&&!rl&&r
0270
&_vstring("\377") || ''
l!l
027
MC/DC0%0/2
defined &Data::Dumper::_vstring && (&_vstring("\377") || '') eq 'v0'
defined &Data::Dumper::_vstring &_vstring("\377")
Truth table33%1/3
A && B
A= defined &Data::Dumper::_vstringB= &_vstring("\377")
ABresult
0X0
100
111
260  
261 #
262 # twist, toil and turn;
263 # and recurse, of course.
264 # sometimes sordidly;
265 # and curse if no recourse.
266 #
267 2493 ▶sub _dump {
Subroutine _dump: called CC=106 SCAR=46.7
268 2493 my($s, $val, $name) = @_;
269 2493 my($out, $type, $id, $sname);
270  
271 2493 $type = ref $val;
272 2493 $out = "";
273  
274 2493 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 836 1657 2493
275  
276 # Call the freezer method if it's specified and the object has the
277 # method. Trap errors and warn() instead of die()ing, like the XS
278 # implementation.
279 836 my $freezer = $s->{freezer};
280 836 ▶ if ($freezer and UNIVERSAL::can($val, $freezer)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freezer and UNIVERSAL::can($val, $freezer)) 3 833 836
Condition100%3/3
$freezer and UNIVERSAL::can($val, $freezer)
!ll&&!rl&&r
83213
MC/DC100%2/2
$freezer and UNIVERSAL::can($val, $freezer)
$freezer UNIVERSAL::can($val, $freezer)
Truth table100%3/3
A and B
A= $freezerB= UNIVERSAL::can($val, $freezer)
ABresult
0X0
100
111
281 3 eval { $val->$freezer() };
282 3 ▶ warn "WARNING(Freezer method call failed): $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 2 3
283 }
284  
285 836 require Scalar::Util;
286 836 my $realpack = Scalar::Util::blessed($val);
287 836 ▶ my $realtype = $realpack ? Scalar::Util::reftype($val) : ref $val;
Branch: 1 branch
BranchTrueFalseTotal
$realpack ? : 113 723 836
288 836 $id = format_refaddr($val);
289  
290 # Note: By this point $name is always defined and of non-zero length.
291 # Keep a tab on it so that we do not fall into recursive pit.
292 836 ▶ if (exists $s->{seen}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{'seen'}{$id}) { } 232 604 836
293 232 ▶ if ($s->{purity} and $s->{level} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'purity'} and $s->{'level'} > 0) { } 76 156 232
Condition100%3/3
$s->{"purity"} and $s->{"level"} > 0
!ll&&!rl&&r
1124476
MC/DC100%2/2
$s->{"purity"} and $s->{"level"} > 0
$s->{"purity"} $s->{"level"} > 0
Truth table100%3/3
A and B
A= $s->{"purity"}B= $s->{"level"} > 0
ABresult
0X0
100
111
294 76 ▶ $out = ($realtype eq 'HASH') ? '{}' :
Branch: 2 branches
BranchTrueFalseTotal
$realtype eq 'HASH' ? : 24 52 76
$realtype eq 'ARRAY' ? : 30 22 52
295 ($realtype eq 'ARRAY') ? '[]' :
296 'do{my $o}' ;
297 76 push @post, $name . " = " . $s->{seen}{$id}[0];
298 }
299 else {
300 156 $out = $s->{seen}{$id}[0];
301 156 ▶ if ($name =~ /^([\@\%])/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^([\@\%])/) 30 126 156
302 30 my $start = $1;
303 30 ▶ if ($out =~ /^\\$start/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out =~ /^\\$start/) { } 10 20 30
304 10 $out = substr($out, 1);
305 }
306 else {
307 20 $out = $start . '{' . $out . '}';
308 }
309 }
310 }
311 232 return $out;
312 }
313 else {
314 # store our name
315 604 ▶ $s->{seen}{$id} = [ (
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^[\@%]/ ? : 32 572 604
$realtype eq 'CODE' && $name =~ /^[*](.*)$/ ? : 2 570 572
Condition100%3/3
$realtype eq "CODE" and $name =~ /^[*](.*)$/
!ll&&!rl&&r
560102
MC/DC100%2/2
$realtype eq "CODE" and $name =~ /^[*](.*)$/
$realtype eq "CODE" $name =~ /^[*](.*)$/
Truth table100%3/3
A and B
A= $realtype eq "CODE"B= $name =~ /^[*](.*)$/
ABresult
0X0
100
111
316 ($name =~ /^[@%]/)
317 ? ('\\' . $name )
318 : ($realtype eq 'CODE' and $name =~ /^[*](.*)$/)
319 ? ('\\&' . $1 )
320 : $name
321 ), $val ];
322 }
323 604 my $no_bless = 0;
324 604 my $is_regex = 0;
325 604 ▶ if ( $realpack and ($] >= 5.009005 ? re::is_regexp($val) : $realpack eq 'Regexp') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($realpack and $] >= "5.009005" ? &re::is_regexp($val) : $realpack eq "Regexp") 100 504 604
$] >= 5.009005 ? : 113 0 113
Condition100%3/3
$realpack and $] >= "5.009005" ? &re::is_regexp($val) : $realpack eq "Regexp"
!ll&&!rl&&r
49113100
MC/DC100%2/2
$realpack and $] >= "5.009005" ? &re::is_regexp($val) : $realpack eq "Regexp"
$realpack $] >= "5.009005" ? &re::is_regexp($val) : $realpack eq "Regexp"
Truth table100%3/3
A and B
A= $realpackB= $] >= "5.009005" ? &re::is_regexp($val) : $realpack eq "Regexp"
ABresult
0X0
100
111
326 100 $is_regex = 1;
327 100 $no_bless = $realpack eq 'Regexp';
328 }
329  
330 # If purity is not set and maxdepth is set, then check depth:
331 # if we have reached maximum depth, return the string
332 # representation of the thing we are currently examining
333 # at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)').
334 604 ▶ if (!$s->{purity}
Branch: 1 branch
BranchTrueFalseTotal
if (not $s->{"purity"} and defined $s->{"maxdepth"} and $s->{"maxdepth"} > 0 and $s->{"level"} >= $s->{"maxdepth"}) 9 595 604
Condition100%9/9
not $s->{"purity"} and defined $s->{"maxdepth"} and $s->{"maxdepth"} > 0 and $s->{"level"} >= $s->{"maxdepth"}
!ll&&!rl&&r
574219
not $s->{"purity"} and defined $s->{"maxdepth"} and $s->{"maxdepth"} > 0
!ll&&!rl&&r
19837630
not $s->{"purity"} and defined $s->{"maxdepth"}
!ll&&!rl&&r
18216406
MC/DC100%4/4
not $s->{"purity"} and defined $s->{"maxdepth"} and $s->{"maxdepth"} > 0 and $s->{"level"} >= $s->{"maxdepth"}
not $s->{"purity"} defined $s->{"maxdepth"} $s->{"maxdepth"} > 0 $s->{"level"} >= $s->{"maxdepth"}
Truth table100%5/5
not(A) and B and C and D
A= not $s->{"purity"}B= defined $s->{"maxdepth"}C= $s->{"maxdepth"} > 0D= $s->{"level"} >= $s->{"maxdepth"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
335 and defined($s->{maxdepth})
336 and $s->{maxdepth} > 0
337 and $s->{level} >= $s->{maxdepth})
338 {
339 9 return qq['$val'];
340 }
341  
342 # avoid recursing infinitely [perl #122111]
343 595 ▶ if ($s->{maxrecurse} > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"maxrecurse"} > 0 and $s->{"level"} >= $s->{"maxrecurse"}) 4 591 595
Condition100%3/3
$s->{"maxrecurse"} > 0 and $s->{"level"} >= $s->{"maxrecurse"}
!ll&&!rl&&r
55864
MC/DC100%2/2
$s->{"maxrecurse"} > 0 and $s->{"level"} >= $s->{"maxrecurse"}
$s->{"maxrecurse"} > 0 $s->{"level"} >= $s->{"maxrecurse"}
Truth table100%3/3
A and B
A= $s->{"maxrecurse"} > 0B= $s->{"level"} >= $s->{"maxrecurse"}
ABresult
0X0
100
111
344 and $s->{level} >= $s->{maxrecurse}) {
345 4 die "Recursion limit of $s->{maxrecurse} exceeded";
346 }
347  
348 # we have a blessed ref
349 591 my ($blesspad);
350 591 ▶ if ($realpack and !$no_bless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realpack and not $no_bless) 14 577 591
Condition100%3/3
$realpack and not $no_bless
!ll&&!rl&&r
4789914
MC/DC100%2/2
$realpack and not $no_bless
$realpack not $no_bless
Truth table100%3/3
A and not(B)
A= $realpackB= not $no_bless
ABresult
0X0
100
111
351 14 $out = $s->{'bless'} . '( ';
352 14 $blesspad = $s->{apad};
353 14 ▶ $s->{apad} .= ' ' if ($s->{indent} >= 2);
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 2 11 3 14
354 }
355  
356 591 $s->{level}++;
357 591 my $ipad = $s->{xpad} x $s->{level};
358  
359 591 ▶ if ($is_regex) {
Branch: 6 branches
BranchTrueFalseTotal
if ($is_regex) { } 100 491 591
elsif ($realtype eq 'SCALAR' or $realtype eq 'REF' or $realtype eq 'VSTRING') { } 78 413 491
elsif ($realtype eq 'GLOB') { } 54 359 413
elsif ($realtype eq 'ARRAY') { } 141 218 359
elsif ($realtype eq 'HASH') { } 205 13 218
elsif ($realtype eq 'CODE') { } 12 1 13
360 100 my $pat;
361 100 my $flags = "";
362 100 ▶ if (defined(*re::regexp_pattern{CODE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *re::regexp_pattern{'CODE'}) { } 100 0 100
363 100 ($pat, $flags) = re::regexp_pattern($val);
364 }
365 else {
366 0 $pat = "$val";
367 }
368 # Escape the pattern to make sure it is processed properly if the output
369 # is evalled. This includes handling things like escaping / characters
370 # as we output it as a qr/.../, along with sigils or other entities which
371 # might be misinterpreted.
372 # Note 1: Try to keep the $ anchor exceptions in sync with S_scan_const()
373 # in toke.c and the regex parser logic in regcomp.c
374 # Note 2: The exceptions are not required and this code should still DTRT
375 # but produce uglier output if the '$' exception rule were removed.
376 # Note 3: This escaping looks weird, but allows us to avoid concerns
377 # about whether we have misparsed the pattern or not. When the
378 # pattern is interpolated it comes back just as it was before, without
379 # us worrying if we misidentified something. The exception list is
380 # purely to make the output more readable in common cases where we
381 # are confident we won't misparse a $.
382 100 $pat =~ s ~
383 (\\.) # 1 == anything backslash escaped
384 | ( \@[\{\[]* # 2 == unescaped @ and optional { or [
385 | \$ # or unescaped $
386 (?![()|\\ \t\r\n]|\z) # .. except before one of these
387 [\{\[]*
388 ) # and optional { or [
389 | / # Otherwise: any unescaped /
390 ~
391 129 ▶ $1 ? $1 :
Branch: 2 branches
BranchTrueFalseTotal
$1 ? : 71 58 129
$2 ? : 36 22 58
392 $2 ? '${\\q(' . $2 . ')}' :
393 '\\/'
394 ~gex;
395 100 $out .= "qr/$pat/$flags";
396 }
397 ▶ elsif ($realtype eq 'SCALAR' || $realtype eq 'REF'
Condition100%6/6
$realtype eq "SCALAR" or $realtype eq "REF" or $realtype eq "VSTRING"
l!l&&r!l&&!r
726413
$realtype eq "SCALAR" or $realtype eq "REF"
l!l&&r!l&&!r
4230419
MC/DC100%3/3
$realtype eq "SCALAR" or $realtype eq "REF" or $realtype eq "VSTRING"
$realtype eq "SCALAR" $realtype eq "REF" $realtype eq "VSTRING"
Truth table100%4/4
A or B or C
A= $realtype eq "SCALAR"B= $realtype eq "REF"C= $realtype eq "VSTRING"
ABCresult
1XX1
01X1
0011
0000
398 || $realtype eq 'VSTRING') {
399 78 ▶ if ($realpack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realpack) { } 0 78 78
400 0 $out .= 'do{\\(my $o = ' . $s->_dump($$val, "\${$name}") . ')}';
401 }
402 else {
403 78 $out .= '\\' . $s->_dump($$val, "\${$name}");
404 }
405 }
406 elsif ($realtype eq 'GLOB') {
407 54 $out .= '\\' . $s->_dump($$val, "*{$name}");
408 }
409 elsif ($realtype eq 'ARRAY') {
410 141 my($pad, $mname);
411 141 my($i) = 0;
412 141 ▶ $out .= ($name =~ /^\@/) ? '(' : '[';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\@/ ? : 23 118 141
413 141 $pad = $s->{sep} . $s->{pad} . $s->{apad};
414 141 ▶ ($name =~ /^\@(.*)$/) ? ($mname = "\$" . $1) :
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\@(.*)$/ ? : 23 118 141
$name =~ /^\\?[\%\@\*\$][^{].*[]}]$/ ? : 47 71 118
415 # omit -> if $foo->[0]->{bar}, but not ${$foo->[0]}->{bar}
416 ($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) :
417 ($mname = $name . '->');
418 141 ▶ $mname .= '->' if $mname =~ /^\*.+\{[A-Z]+\}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $mname =~ /^\*.+\{[A-Z]+\}$/ 4 137 141
419 141 for my $v (@$val) {
420 326 $sname = $mname . '[' . $i . ']';
421 $out .= $pad . $ipad . '#' . $i
422 326 ▶ if $s->{indent} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 3 14 312 326
423 326 $out .= $pad . $ipad . $s->_dump($v, $sname);
424 $out .= ","
425 if $i++ < $#$val
426 324 ▶ || ($s->{trailingcomma} && $s->{indent} >= 1);
Branch: 1 branch
BranchTrueFalseTotal
if $i++ < $val->$#* or $s->{"trailingcomma"} and $s->{"indent"} >= 1 197 127 324
Condition100%6/6
$i++ < $val->$#* or $s->{"trailingcomma"} and $s->{"indent"} >= 1
l!l&&r!l&&!r
1934127
$s->{"trailingcomma"} and $s->{"indent"} >= 1
!ll&&!rl&&r
12524
MC/DC100%3/3
$i++ < $val->$#* or $s->{"trailingcomma"} and $s->{"indent"} >= 1
$i++ < $val->$#* $s->{"trailingcomma"} $s->{"indent"} >= 1
Truth table100%4/4
A or B and C
A= $i++ < $val->$#*B= $s->{"trailingcomma"}C= $s->{"indent"} >= 1
ABCresult
1XX1
0111
00X0
0100
427 }
428 139 ▶ $out .= $pad . ($s->{xpad} x ($s->{level} - 1)) if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 131 8 139
429 139 ▶ $out .= ($name =~ /^\@/) ? ')' : ']';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\@/ ? : 23 116 139
430 }
431 elsif ($realtype eq 'HASH') {
432 205 my ($k, $v, $pad, $lpad, $mname, $pair);
433 205 ▶ $out .= ($name =~ /^\%/) ? '(' : '{';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\%/ ? : 9 196 205
434 205 $pad = $s->{sep} . $s->{pad} . $s->{apad};
435 205 $lpad = $s->{apad};
436 205 $pair = $s->{pair};
437 205 ▶ ($name =~ /^\%(.*)$/) ? ($mname = "\$" . $1) :
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\%(.*)$/ ? : 9 196 205
$name =~ /^\\?[\%\@\*\$][^{].*[]}]$/ ? : 77 119 196
438 # omit -> if $foo->[0]->{bar}, but not ${$foo->[0]}->{bar}
439 ($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) :
440 ($mname = $name . '->');
441 205 ▶ $mname .= '->' if $mname =~ /^\*.+\{[A-Z]+\}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $mname =~ /^\*.+\{[A-Z]+\}$/ 12 193 205
442 205 ▶ my $sortkeys = defined($s->{sortkeys}) ? $s->{sortkeys} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{'sortkeys'} ? : 203 2 205
443 205 my $keys = [];
444 205 ▶ if ($sortkeys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sortkeys) 113 92 205
445 113 ▶ if (ref($s->{sortkeys}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s->{'sortkeys'} eq 'CODE') { } 11 102 113
446 11 $keys = $s->{sortkeys}($val);
447 11 ▶ unless (ref($keys) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys eq "ARRAY") 1 10 11
448 1 Carp::carp("Sortkeys subroutine did not return ARRAYREF");
449 1 $keys = [];
450 }
451 }
452 else {
453 102 $keys = [ sort keys %$val ];
454 }
455 }
456  
457 # Ensure hash iterator is reset
458 205 keys(%$val);
459  
460 205 my $key;
461 205 ▶ while (($k, $v) = ! $sortkeys ? (each %$val) :
Branch: 3 branches
BranchTrueFalseTotal
if (() = !$sortkeys ? each %$val : (@$keys ? ($key = shift @$keys, $val->{$key}) : ())) 460 202 662
!$sortkeys ? : 276 386 662
@$keys ? : 273 113 386
462 @$keys ? ($key = shift(@$keys), $val->{$key}) :
463 () )
464 {
465 460 my $nk = $s->_dump($k, "");
466  
467 # _dump doesn't quote numbers of this form
468 460 ▶ if ($s->{quotekeys} && $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s->{'quotekeys'} and $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { } 6 454 460
elsif (not $s->{'quotekeys'} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/) { } 134 616 750
Condition100%3/3
$s->{"quotekeys"} and $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/
!ll&&!rl&&r
1582966
MC/DC100%2/2
$s->{"quotekeys"} and $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/
$s->{"quotekeys"} $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/
Truth table100%3/3
A and B
A= $s->{"quotekeys"}B= $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/
ABresult
0X0
100
111
469 6 ▶ $nk = $s->{useqq} ? qq("$nk") : qq('$nk');
Branch: 1 branch
BranchTrueFalseTotal
$s->{'useqq'} ? : 3 3 6
470 }
471 ▶ elsif (!$s->{quotekeys} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/) {
Condition100%3/3
not $s->{"quotekeys"} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/
!ll&&!rl&&r
29624134
MC/DC100%2/2
not $s->{"quotekeys"} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/
not $s->{"quotekeys"} $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/
Truth table100%3/3
not(A) and B
A= not $s->{"quotekeys"}B= $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/
ABresult
0X0
100
111
472 134 $nk = $1
473 }
474  
475 460 $sname = $mname . '{' . $nk . '}';
476 460 $out .= $pad . $ipad . $nk . $pair;
477  
478 # temporarily alter apad
479 $s->{apad} .= (" " x (length($nk) + 4))
480 460 ▶ if $s->{indent} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 2 249 211 460
481 460 $out .= $s->_dump($val->{$k}, $sname) . ",";
482 $s->{apad} = $lpad
483 457 ▶ if $s->{indent} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 2 249 208 457
484 }
485 202 ▶ if (substr($out, -1) eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($out, -1) eq ",") 194 8 202
486 194 ▶ chop $out if !$s->{trailingcomma} || !$s->{indent};
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"trailingcomma"} and $s->{"indent"} 190 4 194
Condition100%3/3
$s->{"trailingcomma"} and $s->{"indent"}
!ll&&!rl&&r
18824
MC/DC100%2/2
$s->{"trailingcomma"} and $s->{"indent"}
$s->{"trailingcomma"} $s->{"indent"}
Truth table100%3/3
A and B
A= $s->{"trailingcomma"}B= $s->{"indent"}
ABresult
0X0
100
111
487 194 $out .= $pad . ($s->{xpad} x ($s->{level} - 1));
488 }
489 202 ▶ $out .= ($name =~ /^\%/) ? ')' : '}';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\%/ ? : 9 193 202
490 }
491 elsif ($realtype eq 'CODE') {
492 12 ▶ if ($s->{deparse}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'deparse'}) { } 4 8 12
493 4 require B::Deparse;
494 4 my $sub = 'sub ' . (B::Deparse->new)->coderef2text($val);
495 4 my $pad = $s->{sep} . $s->{pad} . $s->{apad} . $s->{xpad} x ($s->{level} - 1);
496 4 $sub =~ s/\n/$pad/gs;
497 4 $out .= $sub;
498 }
499 else {
500 8 $out .= 'sub { "DUMMY" }';
501 8 ▶ Carp::carp("Encountered CODE ref, using dummy placeholder") if $s->{purity};
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"purity"} 1 7 8
502 }
503 }
504 else {
505 1 Carp::croak("Can't handle '$realtype' type");
506 }
507  
508 583 ▶ if ($realpack and !$no_bless) { # we have a blessed ref
Branch: 1 branch
BranchTrueFalseTotal
if ($realpack and not $no_bless) 13 570 583
Condition100%3/3
$realpack and not $no_bless
!ll&&!rl&&r
4719913
MC/DC100%2/2
$realpack and not $no_bless
$realpack not $no_bless
Truth table100%3/3
A and not(B)
A= $realpackB= not $no_bless
ABresult
0X0
100
111
509 13 $out .= ', ' . _quote($realpack) . ' )';
510 $out .= '->' . $s->{toaster} . '()'
511 13 ▶ if $s->{toaster} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"toaster"} ne "" 0 13 13
512 13 $s->{apad} = $blesspad;
513 }
514 583 $s->{level}--;
515 }
516 else { # simple scalar
517  
518 1657 my $ref = \$_[1];
519 1657 my $v;
520 # first, catalog the scalar
521 1657 ▶ if ($name ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne "") 1153 504 1657
522 1153 $id = format_refaddr($ref);
523 1153 ▶ if (exists $s->{seen}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{'seen'}{$id}) { } 110 1043 1153
524 110 ▶ if ($s->{seen}{$id}[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"seen"}{$id}[2]) 8 102 110
525 8 $out = $s->{seen}{$id}[0];
526 #warn "[<$out]\n";
527 8 return "\${$out}";
528 }
529 }
530 else {
531 #warn "[>\\$name]\n";
532 1043 $s->{seen}{$id} = ["\\$name", $ref];
533 }
534 }
535 1649 $ref = \$val;
536 1649 ▶ if (ref($ref) eq 'GLOB') { # glob
Branch: 6 branches
BranchTrueFalseTotal
if (ref $ref eq 'GLOB') { } 74 1575 1649
elsif (not defined $val) { } 10 1565 1575
elsif (do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"} builtin::is_bool($val) }) { } 4 1561 1565
elsif (defined &Data::Dumper::_vstring and $v = &_vstring($val) and !0) { } 6 1555 1561
elsif (not defined &Data::Dumper::_vstring and ref $ref eq 'VSTRING' || eval { do { &Scalar::Util::isvstring($val) } }) { } 0 1555 1555
elsif ($val =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { } 410 1145 1555
537 74 my $name = substr($val, 1);
538 74 $name =~ s/^main::(?!\z)/::/;
539 74 ▶ if ($name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ && $name ne 'main::') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ and $name ne 'main::') { } 30 44 74
Condition100%3/3
$name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ and $name ne "main::"
!ll&&!rl&&r
43130
MC/DC100%2/2
$name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ and $name ne "main::"
$name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ $name ne "main::"
Truth table100%3/3
A and B
A= $name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/B= $name ne "main::"
ABresult
0X0
100
111
540 30 $sname = $name;
541 }
542 else {
543 44 local $s->{useqq} = IS_PRE_516_PERL && ($s->{useqq} || $name =~ /[^\x00-\x7f]/) ? 1 : $s->{useqq};
544 44 ▶ $sname = $s->_dump(
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'main::' ? : 1 43 44
545 $name eq 'main::'
546 ? ''
547 : $name,
548 "",
549 );
550 44 $sname = '{' . $sname . '}';
551 }
552 74 ▶ if ($s->{purity}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"purity"}) 24 50 74
553 24 my $k;
554 24 local ($s->{level}) = 0;
555 24 for $k (qw(SCALAR ARRAY HASH)) {
556 72 my $gval = *$val{$k};
557 72 ▶ next unless defined $gval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gval 16 56 72
558 56 ▶ next if $k eq "SCALAR" && ! defined $$gval; # always there
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "SCALAR" and not defined $$gval 12 44 56
Condition100%3/3
$k eq "SCALAR" and not defined $$gval
!ll&&!rl&&r
321212
MC/DC100%2/2
$k eq "SCALAR" and not defined $$gval
$k eq "SCALAR" not defined $$gval
Truth table100%3/3
A and not(B)
A= $k eq "SCALAR"B= not defined $$gval
ABresult
0X0
100
111
559  
560 # _dump can push into @post, so we hold our place using $postlen
561 44 my $postlen = scalar @post;
562 44 $post[$postlen] = "\*$sname = ";
563 44 ▶ local ($s->{apad}) = " " x length($post[$postlen]) if $s->{indent} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"indent"} >= 2 6 38 44
564 44 $post[$postlen] .= $s->_dump($gval, "\*$sname\{$k\}");
565 }
566 }
567 74 $out .= '*' . $sname;
568 }
569 elsif (!defined($val)) {
570 10 $out .= "undef";
571 }
572 elsif (SUPPORTS_CORE_BOOLS && do {
573 27 ▶ BEGIN { SUPPORTS_CORE_BOOLS and warnings->unimport("experimental::builtin") }
Subroutine BEGIN: called CC=1 SCAR=0.0
574 1565 builtin::is_bool($val)
575 }) {
576 4 ▶ $out .= $val ? '!!1' : '!!0';
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 2 2 4
577 }
578 # This calls the XSUB _vstring (if the XS code is loaded). I'm not *sure* if
579 # if belongs in the "Pure Perl" implementation. It sort of depends on what
580 # was meant by "Pure Perl", as this subroutine already relies Scalar::Util
581 # loading, which means that it has an XS dependency. De facto, it's the
582 # "Pure Perl" implementation of dumping (which uses XS helper code), as
583 # opposed to the C implementation (which calls out to Perl helper code).
584 # So in that sense this is fine - it just happens to be a local XS helper.
585 ▶ elsif (defined &_vstring and $v = _vstring($val)
Condition80%4/5
defined &Data::Dumper::_vstring and $v = &_vstring($val) and
!ll
15556
defined &Data::Dumper::_vstring and $v = &_vstring($val)
!ll&&!rl&&r
015556
MC/DC50%1/2
defined &Data::Dumper::_vstring and $v = &_vstring($val) and
defined &Data::Dumper::_vstring $v = &_vstring($val)
Truth table66%2/3
A and B
A= defined &Data::Dumper::_vstringB= $v = &_vstring($val)
ABresult
0X0
100
111
586 and !_bad_vsmg || eval $v eq $val) {
587 6 $out .= $v;
588 }
589 # However the confusion comes here - if we *can't* find our XS helper, we
590 # fall back to this code, which generates different (worse) results. That's
591 # better than nothing, *but* it means that if you run the regression tests
592 # with Dumper.so missing, the test for "vstrings" fails, because this code
593 # here generates a different result. So there are actually "three" different
594 # implementations of Data::Dumper (kind of sort of) but we only test two.
595 ▶ elsif (!defined &_vstring
Condition16%1/6
not defined &Data::Dumper::_vstring and ref $ref eq "VSTRING" || eval { do { &Scalar::Util::isvstring($val) } }
!ll&&!rl&&r
155500
ref $ref eq "VSTRING" or eval { do { &Scalar::Util::isvstring($val) } }
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined &Data::Dumper::_vstring and ref $ref eq "VSTRING" || eval { do { &Scalar::Util::isvstring($val) } }
not defined &Data::Dumper::_vstring ref $ref eq "VSTRING" eval { do { &Scalar::Util::isvstring($val) } }
Truth table25%1/4
not(A) and B or C
A= not defined &Data::Dumper::_vstringB= ref $ref eq "VSTRING"C= eval { do { &Scalar::Util::isvstring($val) } }
ABCresult
0XX0
1000
11X1
1011
596 0 and ref $ref eq 'VSTRING' || eval{Scalar::Util::isvstring($val)}) {
597 0 $out .= sprintf "v%vd", $val;
598 }
599 # \d here would treat "1\x{660}" as a safe decimal number
600 elsif ($val =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { # safe decimal number
601 410 $out .= $val;
602 }
603 else { # string
604 1145 ▶ if ($s->{useqq} or $val =~ tr/\0-\377//c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'useqq'} or $val =~ tr/\000-\377//c) { } 100 1045 1145
Condition100%3/3
$s->{"useqq"} or $val =~ tr/\000-\377//c
l!l&&r!l&&!r
82181045
MC/DC100%2/2
$s->{"useqq"} or $val =~ tr/\000-\377//c
$s->{"useqq"} $val =~ tr/\000-\377//c
Truth table100%3/3
A or B
A= $s->{"useqq"}B= $val =~ tr/\000-\377//c
ABresult
1X1
011
000
605 # Fall back to qq if there's Unicode
606 100 $out .= qquote($val, $s->{useqq});
607 }
608 else {
609 1045 $out .= _quote($val);
610 }
611 }
612 }
613 2232 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 1728 504 2232
614 # if we made it this far, $id was added to seen list at current
615 # level, so remove it to get deep copies
616 1728 ▶ if ($s->{deepcopy}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s->{'deepcopy'}) { } 26 1702 1728
elsif ($name) { } 1702 0 1702
617 26 delete($s->{seen}{$id});
618 }
619 elsif ($name) {
620 1702 $s->{seen}{$id}[2] = 1;
621 }
622 }
623 2232 return $out;
624 }
625  
626 #
627 # non-OO style of earlier version
628 #
629 177 ▶sub Dumper {
Subroutine Dumper: called CC=1 SCAR=0.0
Pod documented
630 177 return Data::Dumper->Dump([@_]);
631 }
632  
633 # compat stub
634 16 ▶sub DumperX {
Subroutine DumperX: called CC=1 SCAR=0.0
Pod undocumented
635 16 return Data::Dumper->Dumpxs([@_], []);
636 }
637  
638 #
639 # reset the "seen" cache
640 #
641 12 ▶sub Reset {
Subroutine Reset: called CC=1 SCAR=0.0
Pod documented
642 12 my($s) = shift;
643 12 $s->{seen} = {};
644 12 return $s;
645 }
646  
647 33 ▶sub Indent {
Subroutine Indent: called CC=3 SCAR=11.0
Pod undocumented
648 33 my($s, $v) = @_;
649 33 ▶ if (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) { } 32 1 33
650 32 ▶ if ($v == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v == 0) { } 9 23 32
651 9 $s->{xpad} = "";
652 9 $s->{sep} = "";
653 }
654 else {
655 23 $s->{xpad} = " ";
656 23 $s->{sep} = "\n";
657 }
658 32 $s->{indent} = $v;
659 32 return $s;
660 }
661 else {
662 1 return $s->{indent};
663 }
664 }
665  
666 28 ▶sub Trailingcomma {
Subroutine Trailingcomma: called CC=2 SCAR=7.2
Pod undocumented
667 28 my($s, $v) = @_;
668 28 ▶ @_ >= 2 ? (($s->{trailingcomma} = $v), return $s) : $s->{trailingcomma};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 28 0 28
669 }
670  
671 3 ▶sub Pair {
Subroutine Pair: called CC=2 SCAR=6.9
Pod undocumented
672 3 my($s, $v) = @_;
673 3 ▶ @_ >= 2 ? (($s->{pair} = $v), return $s) : $s->{pair};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 2 1 3
674 }
675  
676 2 ▶sub Pad {
Subroutine Pad: called CC=2 SCAR=7.2
Pod undocumented
677 2 my($s, $v) = @_;
678 2 ▶ @_ >= 2 ? (($s->{pad} = $v), return $s) : $s->{pad};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 2 0 2
679 }
680  
681 2 ▶sub Varname {
Subroutine Varname: called CC=2 SCAR=7.2
Pod undocumented
682 2 my($s, $v) = @_;
683 2 ▶ @_ >= 2 ? (($s->{varname} = $v), return $s) : $s->{varname};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 2 0 2
684 }
685  
686 28 ▶sub Purity {
Subroutine Purity: called CC=2 SCAR=7.2
Pod undocumented
687 28 my($s, $v) = @_;
688 28 ▶ @_ >= 2 ? (($s->{purity} = $v), return $s) : $s->{purity};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 28 0 28
689 }
690  
691 6 ▶sub Useqq {
Subroutine Useqq: called CC=2 SCAR=7.2
Pod undocumented
692 6 my($s, $v) = @_;
693 6 ▶ @_ >= 2 ? (($s->{useqq} = $v), return $s) : $s->{useqq};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 0 6
694 }
695  
696 9 ▶sub Terse {
Subroutine Terse: called CC=2 SCAR=6.9
Pod undocumented
697 9 my($s, $v) = @_;
698 9 ▶ @_ >= 2 ? (($s->{terse} = $v), return $s) : $s->{terse};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 3 9
699 }
700  
701 6 ▶sub Freezer {
Subroutine Freezer: called CC=2 SCAR=7.2
Pod undocumented
702 6 my($s, $v) = @_;
703 6 ▶ @_ >= 2 ? (($s->{freezer} = $v), return $s) : $s->{freezer};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 0 6
704 }
705  
706 6 ▶sub Toaster {
Subroutine Toaster: called CC=2 SCAR=7.2
Pod undocumented
707 6 my($s, $v) = @_;
708 6 ▶ @_ >= 2 ? (($s->{toaster} = $v), return $s) : $s->{toaster};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 0 6
709 }
710  
711 8 ▶sub Deepcopy {
Subroutine Deepcopy: called CC=2 SCAR=7.2
Pod undocumented
712 8 my($s, $v) = @_;
713 8 ▶ @_ >= 2 ? (($s->{deepcopy} = $v), return $s) : $s->{deepcopy};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 8 0 8
714 }
715  
716 7 ▶sub Quotekeys {
Subroutine Quotekeys: called CC=2 SCAR=7.2
Pod undocumented
717 7 my($s, $v) = @_;
718 7 ▶ @_ >= 2 ? (($s->{quotekeys} = $v), return $s) : $s->{quotekeys};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 7 0 7
719 }
720  
721 6 ▶sub Bless {
Subroutine Bless: called CC=2 SCAR=7.2
Pod undocumented
722 6 my($s, $v) = @_;
723 6 ▶ @_ >= 2 ? (($s->{'bless'} = $v), return $s) : $s->{'bless'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 0 6
724 }
725  
726 10 ▶sub Maxdepth {
Subroutine Maxdepth: called CC=2 SCAR=6.9
Pod undocumented
727 10 my($s, $v) = @_;
728 10 ▶ @_ >= 2 ? (($s->{'maxdepth'} = $v), return $s) : $s->{'maxdepth'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 9 1 10
729 }
730  
731 0 ▶sub Maxrecurse {
Subroutine Maxrecurse: not called CC=2 SCAR=17.9
Pod undocumented
732 0 my($s, $v) = @_;
733 0 ▶ @_ >= 2 ? (($s->{'maxrecurse'} = $v), return $s) : $s->{'maxrecurse'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 0 0 0
734 }
735  
736 3 ▶sub Useperl {
Subroutine Useperl: called CC=2 SCAR=7.2
Pod undocumented
737 3 my($s, $v) = @_;
738 3 ▶ @_ >= 2 ? (($s->{'useperl'} = $v), return $s) : $s->{'useperl'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 3 0 3
739 }
740  
741 39 ▶sub Sortkeys {
Subroutine Sortkeys: called CC=2 SCAR=7.2
Pod undocumented
742 39 my($s, $v) = @_;
743 39 ▶ @_ >= 2 ? (($s->{'sortkeys'} = $v), return $s) : $s->{'sortkeys'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 39 0 39
744 }
745  
746 6 ▶sub Deparse {
Subroutine Deparse: called CC=2 SCAR=6.9
Pod undocumented
747 6 my($s, $v) = @_;
748 6 ▶ @_ >= 2 ? (($s->{'deparse'} = $v), return $s) : $s->{'deparse'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 4 2 6
749 }
750  
751 6 ▶sub Sparseseen {
Subroutine Sparseseen: called CC=2 SCAR=7.2
Pod undocumented
752 6 my($s, $v) = @_;
753 6 ▶ @_ >= 2 ? (($s->{'noseen'} = $v), return $s) : $s->{'noseen'};
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 6 0 6
754 }
755  
756 # used by qquote below
757 27 my %esc = (
758 "\a" => "\\a",
759 "\b" => "\\b",
760 "\t" => "\\t",
761 "\n" => "\\n",
762 "\f" => "\\f",
763 "\r" => "\\r",
764 "\e" => "\\e",
765 );
766  
767 # The low controls are considered to be everything below SPACE, plus the
768 # outlier \c? control (but that wasn't properly in existence in early perls,
769 # so reconstruct its value here. This abandons EBCDIC support for this
770 # character for perls below 5.8)
771 27 my $low_controls = join "", map { quotemeta chr $_ } 0.. (ord(" ") - 1);
772 27 ▶$low_controls .= ($] < 5.008 || $IS_ASCII)
Branch: 1 branch
BranchTrueFalseTotal
$] < 5.008 || $IS_ASCII ? : 27 0 27
Condition33%1/3
$] < "5.008" or $IS_ASCII
l!l&&r!l&&!r
0270
MC/DC0%0/2
$] < "5.008" or $IS_ASCII
$] < "5.008" $IS_ASCII
Truth table33%1/3
A or B
A= $] < "5.008"B= $IS_ASCII
ABresult
1X1
011
000
773 ? "\x7f"
774 : chr utf8::unicode_to_native(0x9F);
775 27 my $low_controls_re = qr/[$low_controls]/;
776  
777 # put a string value in double quotes
778 108 ▶sub qquote {
Subroutine qquote: called CC=10 SCAR=23.4
Pod undocumented
779 108 local($_) = shift;
780 108 ▶ return qq("") unless defined && length; # fast exit if undef/empty
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and length $_ 3 105 108
Condition100%3/3
defined $_ and length $_
!ll&&!rl&&r
21105
MC/DC100%2/2
defined $_ and length $_
defined $_ length $_
Truth table100%3/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
781 105 s/([\\\"\@\$])/\\$1/g;
782  
783 # This efficiently changes the high ordinal characters to \x{} if the utf8
784 # flag is on. On ASCII platforms, the high ordinals are all the
785 # non-ASCII's. On EBCDIC platforms, we don't include in these the non-ASCII
786 # controls.
787 27 ▶ my $bytes; { use bytes; $bytes = length }
Subroutine BEGIN: called CC=1 SCAR=0.0
788 312 s/([^[:ascii:]$low_controls])/sprintf("\\x{%x}",ord($1))/ge
789 105 ▶ if $bytes > length;
Branch: 1 branch
BranchTrueFalseTotal
if $bytes > length $_ 44 61 105
790  
791 105 ▶ return qq("$_") unless /[[:^print:]]/; # fast exit if only printables
Branch: 1 branch
BranchTrueFalseTotal
unless /[[:^print:]]/ 70 35 105
792  
793 # Here, there is at least one non-printable to output. First, translate the
794 # escapes.
795 35 s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
796  
797 # no need for 3 digits in escape for octals not followed by a digit.
798 35 s/($low_controls_re)(?!\d)/'\\'.sprintf('%o',ord($1))/eg;
799  
800 # But otherwise use 3 digits
801 35 s/($low_controls_re)/'\\'.sprintf('%03o',ord($1))/eg;
802  
803 # all but last branch below not supported --BEHAVIOR SUBJECT TO CHANGE--
804 35 ▶ my $high = shift || "";
Condition100%2/2
shift() || ''
l!l
323
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
805 35 ▶ if ($high eq "iso8859") { # Doesn't escape the Latin1 printables
Branch: 3 branches
BranchTrueFalseTotal
if ($high eq 'iso8859') { } 0 35 35
elsif ($high eq 'utf8') { } 0 35 35
elsif ($high eq '8bit') { } 0 35 35
806 # Could use /u and [:cntrl:] etc, if khw were confident it worked in
807 # early early perls
808 0 ▶ s/([\200-\240])/'\\'.sprintf('%o',ord($1))/eg if $IS_ASCII;
Branch: 1 branch
BranchTrueFalseTotal
if $IS_ASCII 0 0 0
809 } elsif ($high eq "utf8") {
810 # Some discussion of what to do here is in
811 # https://rt.perl.org/Ticket/Display.html?id=113088
812 # use utf8;
813 # $str =~ s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;
814 } elsif ($high eq "8bit") {
815 # leave it as it is
816 } else {
817 35 s/([[:^ascii:]])/'\\'.sprintf('%03o',ord($1))/eg;
818 #s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;
819 }
820  
821 35 return qq("$_");
822 }
823  
824 1027 ▶sub _refine_name {
Subroutine _refine_name: called CC=8 SCAR=20.8
825 1027 my $s = shift;
826 1027 my ($name, $val, $i) = @_;
827 1027 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 203 824 1027
828 203 ▶ if ($name =~ /^[*](.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^[*](.*)$/) { } 77 126 203
elsif (not $name =~ /^\$/) { } 125 1 126
829 77 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 76 1 77
830 76 ▶ $name = (ref $val eq 'ARRAY') ? ( "\@" . $1 ) :
Branch: 3 branches
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 27 49 76
ref $val eq 'HASH' ? : 35 14 49
ref $val eq 'CODE' ? : 4 10 14
831 (ref $val eq 'HASH') ? ( "\%" . $1 ) :
832 (ref $val eq 'CODE') ? ( "\*" . $1 ) :
833 ( "\$" . $1 ) ;
834 }
835 else {
836 1 $name = "\$" . $1;
837 }
838 }
839 elsif ($name !~ /^\$/) {
840 125 $name = "\$" . $name;
841 }
842 }
843 else { # no names provided
844 824 $name = "\$" . $s->{varname} . $i;
845 }
846 1027 return $name;
847 }
848  
849 1022 ▶sub _compose_out {
Subroutine _compose_out: called CC=2 SCAR=6.9
850 1022 my $s = shift;
851 1022 my ($valstr, $postref) = @_;
852 1022 my $out = "";
853 1022 $out .= $s->{pad} . $valstr . $s->{sep};
854 1022 ▶ if (@{$postref}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$postref;}) 32 990 1022
855 $out .= $s->{pad} .
856 32 join(';' . $s->{sep} . $s->{pad}, @{$postref}) .
857 ';' .
858 32 $s->{sep};
859 }
860 1022 return $out;
861 }
862  
863 27 1;
864 __END__
↑ Summary Dumper.xs »