line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
27
|
|
|
27
|
|
593546
|
use strict; |
|
27
|
|
|
|
|
216
|
|
|
27
|
|
|
|
|
1254
|
|
13
|
26
|
|
|
26
|
|
123
|
use warnings; |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
782
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#$| = 1; |
16
|
|
|
|
|
|
|
|
17
|
26
|
|
|
26
|
|
598
|
use 5.008_001; |
|
26
|
|
|
|
|
112
|
|
18
|
|
|
|
|
|
|
require Exporter; |
19
|
|
|
|
|
|
|
|
20
|
26
|
|
|
26
|
|
207
|
use constant IS_PRE_516_PERL => $] < 5.016; |
|
26
|
|
|
|
|
118
|
|
|
26
|
|
|
|
|
3218
|
|
21
|
|
|
|
|
|
|
|
22
|
26
|
|
|
26
|
|
246
|
use Carp (); |
|
26
|
|
|
|
|
58
|
|
|
26
|
|
|
|
|
6903
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Globals people alter. |
25
|
|
|
|
|
|
|
our ( $Indent, $Trailingcomma, $Purity, $Pad, $Varname, $Useqq, $Terse, $Freezer, |
26
|
|
|
|
|
|
|
$Toaster, $Deepcopy, $Quotekeys, $Bless, $Maxdepth, $Pair, $Sortkeys, |
27
|
|
|
|
|
|
|
$Deparse, $Sparseseen, $Maxrecurse, $Useperl ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our ( @ISA, @EXPORT, @EXPORT_OK, $VERSION ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
BEGIN { |
32
|
26
|
|
|
26
|
|
104
|
$VERSION = '2.183'; # Don't forget to set version and release |
33
|
|
|
|
|
|
|
# date in POD below! |
34
|
|
|
|
|
|
|
|
35
|
26
|
|
|
|
|
480
|
@ISA = qw(Exporter); |
36
|
26
|
|
|
|
|
136
|
@EXPORT = qw(Dumper); |
37
|
26
|
|
|
|
|
59
|
@EXPORT_OK = qw(DumperX); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# if run under miniperl, or otherwise lacking dynamic loading, |
40
|
|
|
|
|
|
|
# XSLoader should be attempted to load, or the pure perl flag |
41
|
|
|
|
|
|
|
# toggled on load failure. |
42
|
26
|
50
|
|
|
|
52
|
eval { |
43
|
26
|
|
|
|
|
157
|
require XSLoader; |
44
|
26
|
|
|
|
|
12733
|
XSLoader::load( 'Data::Dumper' ); |
45
|
26
|
|
|
|
|
38208
|
1 |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
or $Useperl = 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $IS_ASCII = ord 'A' == 65; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# module vars and their defaults |
53
|
|
|
|
|
|
|
$Indent = 2 unless defined $Indent; |
54
|
|
|
|
|
|
|
$Trailingcomma = 0 unless defined $Trailingcomma; |
55
|
|
|
|
|
|
|
$Purity = 0 unless defined $Purity; |
56
|
|
|
|
|
|
|
$Pad = "" unless defined $Pad; |
57
|
|
|
|
|
|
|
$Varname = "VAR" unless defined $Varname; |
58
|
|
|
|
|
|
|
$Useqq = 0 unless defined $Useqq; |
59
|
|
|
|
|
|
|
$Terse = 0 unless defined $Terse; |
60
|
|
|
|
|
|
|
$Freezer = "" unless defined $Freezer; |
61
|
|
|
|
|
|
|
$Toaster = "" unless defined $Toaster; |
62
|
|
|
|
|
|
|
$Deepcopy = 0 unless defined $Deepcopy; |
63
|
|
|
|
|
|
|
$Quotekeys = 1 unless defined $Quotekeys; |
64
|
|
|
|
|
|
|
$Bless = "bless" unless defined $Bless; |
65
|
|
|
|
|
|
|
#$Expdepth = 0 unless defined $Expdepth; |
66
|
|
|
|
|
|
|
$Maxdepth = 0 unless defined $Maxdepth; |
67
|
|
|
|
|
|
|
$Pair = ' => ' unless defined $Pair; |
68
|
|
|
|
|
|
|
$Useperl = 0 unless defined $Useperl; |
69
|
|
|
|
|
|
|
$Sortkeys = 0 unless defined $Sortkeys; |
70
|
|
|
|
|
|
|
$Deparse = 0 unless defined $Deparse; |
71
|
|
|
|
|
|
|
$Sparseseen = 0 unless defined $Sparseseen; |
72
|
|
|
|
|
|
|
$Maxrecurse = 1000 unless defined $Maxrecurse; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
# expects an arrayref of values to be dumped. |
76
|
|
|
|
|
|
|
# can optionally pass an arrayref of names for the values. |
77
|
|
|
|
|
|
|
# names must have leading $ sign stripped. begin the name with * |
78
|
|
|
|
|
|
|
# to cause output of arrays and hashes rather than refs. |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
sub new { |
81
|
637
|
|
|
637
|
1
|
292071
|
my($c, $v, $n) = @_; |
82
|
|
|
|
|
|
|
|
83
|
637
|
100
|
100
|
|
|
3751
|
Carp::croak("Usage: PACKAGE->new(ARRAYREF, [ARRAYREF])") |
84
|
|
|
|
|
|
|
unless (defined($v) && (ref($v) eq 'ARRAY')); |
85
|
635
|
100
|
100
|
|
|
1907
|
$n = [] unless (defined($n) && (ref($n) eq 'ARRAY')); |
86
|
|
|
|
|
|
|
|
87
|
635
|
|
|
|
|
7618
|
my($s) = { |
88
|
|
|
|
|
|
|
level => 0, # current recursive depth |
89
|
|
|
|
|
|
|
indent => $Indent, # various styles of indenting |
90
|
|
|
|
|
|
|
trailingcomma => $Trailingcomma, # whether to add comma after last elem |
91
|
|
|
|
|
|
|
pad => $Pad, # all lines prefixed by this string |
92
|
|
|
|
|
|
|
xpad => "", # padding-per-level |
93
|
|
|
|
|
|
|
apad => "", # added padding for hash keys n such |
94
|
|
|
|
|
|
|
sep => "", # list separator |
95
|
|
|
|
|
|
|
pair => $Pair, # hash key/value separator: defaults to ' => ' |
96
|
|
|
|
|
|
|
seen => {}, # local (nested) refs (id => [name, val]) |
97
|
|
|
|
|
|
|
todump => $v, # values to dump [] |
98
|
|
|
|
|
|
|
names => $n, # optional names for values [] |
99
|
|
|
|
|
|
|
varname => $Varname, # prefix to use for tagging nameless ones |
100
|
|
|
|
|
|
|
purity => $Purity, # degree to which output is evalable |
101
|
|
|
|
|
|
|
useqq => $Useqq, # use "" for strings (backslashitis ensues) |
102
|
|
|
|
|
|
|
terse => $Terse, # avoid name output (where feasible) |
103
|
|
|
|
|
|
|
freezer => $Freezer, # name of Freezer method for objects |
104
|
|
|
|
|
|
|
toaster => $Toaster, # name of method to revive objects |
105
|
|
|
|
|
|
|
deepcopy => $Deepcopy, # do not cross-ref, except to stop recursion |
106
|
|
|
|
|
|
|
quotekeys => $Quotekeys, # quote hash keys |
107
|
|
|
|
|
|
|
'bless' => $Bless, # keyword to use for "bless" |
108
|
|
|
|
|
|
|
# expdepth => $Expdepth, # cutoff depth for explicit dumping |
109
|
|
|
|
|
|
|
maxdepth => $Maxdepth, # depth beyond which we give up |
110
|
|
|
|
|
|
|
maxrecurse => $Maxrecurse, # depth beyond which we abort |
111
|
|
|
|
|
|
|
useperl => $Useperl, # use the pure Perl implementation |
112
|
|
|
|
|
|
|
sortkeys => $Sortkeys, # flag or filter for sorting hash keys |
113
|
|
|
|
|
|
|
deparse => $Deparse, # use B::Deparse for coderefs |
114
|
|
|
|
|
|
|
noseen => $Sparseseen, # do not populate the seen hash unless necessary |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
635
|
100
|
|
|
|
1683
|
if ($Indent > 0) { |
118
|
597
|
|
|
|
|
1040
|
$s->{xpad} = " "; |
119
|
597
|
|
|
|
|
953
|
$s->{sep} = "\n"; |
120
|
|
|
|
|
|
|
} |
121
|
635
|
|
|
|
|
10860
|
return bless($s, $c); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Packed numeric addresses take less memory. Plus pack is faster than sprintf |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub format_refaddr { |
127
|
2009
|
|
|
2009
|
0
|
6401
|
require Scalar::Util; |
128
|
2009
|
|
|
|
|
6132
|
pack "J", Scalar::Util::refaddr(shift); |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
# add-to or query the table of already seen references |
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
sub Seen { |
135
|
26
|
|
|
26
|
1
|
99
|
my($s, $g) = @_; |
136
|
26
|
100
|
100
|
|
|
105
|
if (defined($g) && (ref($g) eq 'HASH')) { |
137
|
24
|
|
|
|
|
38
|
my($k, $v, $id); |
138
|
24
|
|
|
|
|
91
|
while (($k, $v) = each %$g) { |
139
|
24
|
100
|
|
|
|
48
|
if (defined $v) { |
140
|
23
|
100
|
|
|
|
44
|
if (ref $v) { |
141
|
22
|
|
|
|
|
39
|
$id = format_refaddr($v); |
142
|
22
|
100
|
|
|
|
104
|
if ($k =~ /^[*](.*)$/) { |
|
|
100
|
|
|
|
|
|
143
|
16
|
100
|
|
|
|
81
|
$k = (ref $v eq 'ARRAY') ? ( "\\\@" . $1 ) : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
144
|
|
|
|
|
|
|
(ref $v eq 'HASH') ? ( "\\\%" . $1 ) : |
145
|
|
|
|
|
|
|
(ref $v eq 'CODE') ? ( "\\\&" . $1 ) : |
146
|
|
|
|
|
|
|
( "\$" . $1 ) ; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
elsif ($k !~ /^\$/) { |
149
|
5
|
|
|
|
|
12
|
$k = "\$" . $k; |
150
|
|
|
|
|
|
|
} |
151
|
22
|
|
|
|
|
124
|
$s->{seen}{$id} = [$k, $v]; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
1
|
|
|
|
|
169
|
Carp::carp("Only refs supported, ignoring non-ref item \$$k"); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
1
|
|
|
|
|
87
|
Carp::carp("Value of ref must be defined; ignoring undefined item \$$k"); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
24
|
|
|
|
|
492
|
return $s; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
2
|
|
|
|
|
3
|
return map { @$_ } values %{$s->{seen}}; |
|
0
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
15
|
|
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
# set or query the values to be dumped |
170
|
|
|
|
|
|
|
# |
171
|
|
|
|
|
|
|
sub Values { |
172
|
6
|
|
|
6
|
1
|
908
|
my($s, $v) = @_; |
173
|
6
|
100
|
|
|
|
18
|
if (defined($v)) { |
174
|
2
|
100
|
|
|
|
7
|
if (ref($v) eq 'ARRAY') { |
175
|
1
|
|
|
|
|
4
|
$s->{todump} = [@$v]; # make a copy |
176
|
1
|
|
|
|
|
3
|
return $s; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else { |
179
|
1
|
|
|
|
|
204
|
Carp::croak("Argument to Values, if provided, must be array ref"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
else { |
183
|
4
|
|
|
|
|
5
|
return @{$s->{todump}}; |
|
4
|
|
|
|
|
25
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# |
188
|
|
|
|
|
|
|
# set or query the names of the values to be dumped |
189
|
|
|
|
|
|
|
# |
190
|
|
|
|
|
|
|
sub Names { |
191
|
5
|
|
|
5
|
1
|
798
|
my($s, $n) = @_; |
192
|
5
|
100
|
|
|
|
12
|
if (defined($n)) { |
193
|
4
|
100
|
|
|
|
13
|
if (ref($n) eq 'ARRAY') { |
194
|
3
|
|
|
|
|
9
|
$s->{names} = [@$n]; # make a copy |
195
|
3
|
|
|
|
|
15
|
return $s; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
else { |
198
|
1
|
|
|
|
|
184
|
Carp::croak("Argument to Names, if provided, must be array ref"); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else { |
202
|
1
|
|
|
|
|
2
|
return @{$s->{names}}; |
|
1
|
|
|
|
|
11
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
0
|
|
|
sub DESTROY {} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub Dump { |
209
|
|
|
|
|
|
|
return &Dumpxs |
210
|
|
|
|
|
|
|
unless $Data::Dumper::Useperl || (ref($_[0]) && $_[0]->{useperl}) |
211
|
|
|
|
|
|
|
# Use pure perl version on earlier releases on EBCDIC platforms |
212
|
463
|
50
|
100
|
463
|
1
|
79262
|
|| (! $IS_ASCII && $] lt 5.021_010); |
|
2
|
|
100
|
2
|
|
14
|
|
|
2
|
|
33
|
|
|
4
|
|
|
2
|
|
66
|
|
|
2059
|
|
213
|
287
|
|
|
|
|
559
|
return &Dumpperl; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# |
217
|
|
|
|
|
|
|
# dump the refs in the current dumper object. |
218
|
|
|
|
|
|
|
# expects same args as new() if called via package name. |
219
|
|
|
|
|
|
|
# |
220
|
|
|
|
|
|
|
our @post; |
221
|
|
|
|
|
|
|
sub Dumpperl { |
222
|
287
|
|
|
287
|
0
|
528
|
my($s) = shift; |
223
|
287
|
|
|
|
|
462
|
my(@out, $val, $name); |
224
|
287
|
|
|
|
|
420
|
my($i) = 0; |
225
|
287
|
|
|
|
|
487
|
local(@post); |
226
|
|
|
|
|
|
|
|
227
|
287
|
100
|
|
|
|
786
|
$s = $s->new(@_) unless ref $s; |
228
|
|
|
|
|
|
|
|
229
|
287
|
|
|
|
|
426
|
for $val (@{$s->{todump}}) { |
|
287
|
|
|
|
|
693
|
|
230
|
981
|
|
|
|
|
1400
|
@post = (); |
231
|
981
|
|
|
|
|
1663
|
$name = $s->{names}[$i++]; |
232
|
981
|
|
|
|
|
1903
|
$name = $s->_refine_name($name, $val, $i); |
233
|
|
|
|
|
|
|
|
234
|
981
|
|
|
|
|
1372
|
my $valstr; |
235
|
|
|
|
|
|
|
{ |
236
|
981
|
|
|
|
|
1189
|
local($s->{apad}) = $s->{apad}; |
|
981
|
|
|
|
|
2127
|
|
237
|
981
|
100
|
100
|
|
|
2405
|
$s->{apad} .= ' ' x (length($name) + 3) if $s->{indent} >= 2 and !$s->{terse}; |
238
|
981
|
|
|
|
|
1776
|
$valstr = $s->_dump($val, $name); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
976
|
100
|
100
|
|
|
4209
|
$valstr = "$name = " . $valstr . ';' if @post or !$s->{terse}; |
242
|
976
|
|
|
|
|
2202
|
my $out = $s->_compose_out($valstr, \@post); |
243
|
|
|
|
|
|
|
|
244
|
976
|
|
|
|
|
2045
|
push @out, $out; |
245
|
|
|
|
|
|
|
} |
246
|
282
|
100
|
|
|
|
4403
|
return wantarray ? @out : join('', @out); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# wrap string in single quotes (escaping if needed) |
250
|
|
|
|
|
|
|
sub _quote { |
251
|
1106
|
|
|
1106
|
|
1530
|
my $val = shift; |
252
|
1106
|
|
|
|
|
2041
|
$val =~ s/([\\\'])/\\$1/g; |
253
|
1106
|
|
|
|
|
2961
|
return "'" . $val . "'"; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Old Perls (5.14-) have trouble resetting vstring magic when it is no |
257
|
|
|
|
|
|
|
# longer valid. |
258
|
26
|
|
33
|
26
|
|
274
|
use constant _bad_vsmg => defined &_vstring && (_vstring(~v0)||'') eq "v0"; |
|
26
|
|
|
|
|
79
|
|
|
26
|
|
|
|
|
101059
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# |
261
|
|
|
|
|
|
|
# twist, toil and turn; |
262
|
|
|
|
|
|
|
# and recurse, of course. |
263
|
|
|
|
|
|
|
# sometimes sordidly; |
264
|
|
|
|
|
|
|
# and curse if no recourse. |
265
|
|
|
|
|
|
|
# |
266
|
|
|
|
|
|
|
sub _dump { |
267
|
2539
|
|
|
2539
|
|
4572
|
my($s, $val, $name) = @_; |
268
|
2539
|
|
|
|
|
3372
|
my($out, $type, $id, $sname); |
269
|
|
|
|
|
|
|
|
270
|
2539
|
|
|
|
|
3571
|
$type = ref $val; |
271
|
2539
|
|
|
|
|
3381
|
$out = ""; |
272
|
|
|
|
|
|
|
|
273
|
2539
|
100
|
|
|
|
3808
|
if ($type) { |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# Call the freezer method if it's specified and the object has the |
276
|
|
|
|
|
|
|
# method. Trap errors and warn() instead of die()ing, like the XS |
277
|
|
|
|
|
|
|
# implementation. |
278
|
788
|
|
|
|
|
1197
|
my $freezer = $s->{freezer}; |
279
|
788
|
100
|
100
|
|
|
1498
|
if ($freezer and UNIVERSAL::can($val, $freezer)) { |
280
|
3
|
|
|
|
|
7
|
eval { $val->$freezer() }; |
|
3
|
|
|
|
|
9
|
|
281
|
3
|
100
|
|
|
|
35
|
warn "WARNING(Freezer method call failed): $@" if $@; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
788
|
|
|
|
|
3076
|
require Scalar::Util; |
285
|
788
|
|
|
|
|
1641
|
my $realpack = Scalar::Util::blessed($val); |
286
|
788
|
100
|
|
|
|
1542
|
my $realtype = $realpack ? Scalar::Util::reftype($val) : ref $val; |
287
|
788
|
|
|
|
|
1234
|
$id = format_refaddr($val); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# Note: By this point $name is always defined and of non-zero length. |
290
|
|
|
|
|
|
|
# Keep a tab on it so that we do not fall into recursive pit. |
291
|
788
|
100
|
|
|
|
1665
|
if (exists $s->{seen}{$id}) { |
292
|
232
|
100
|
100
|
|
|
615
|
if ($s->{purity} and $s->{level} > 0) { |
293
|
76
|
100
|
|
|
|
165
|
$out = ($realtype eq 'HASH') ? '{}' : |
|
|
100
|
|
|
|
|
|
294
|
|
|
|
|
|
|
($realtype eq 'ARRAY') ? '[]' : |
295
|
|
|
|
|
|
|
'do{my $o}' ; |
296
|
76
|
|
|
|
|
223
|
push @post, $name . " = " . $s->{seen}{$id}[0]; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
else { |
299
|
156
|
|
|
|
|
268
|
$out = $s->{seen}{$id}[0]; |
300
|
156
|
100
|
|
|
|
490
|
if ($name =~ /^([\@\%])/) { |
301
|
30
|
|
|
|
|
63
|
my $start = $1; |
302
|
30
|
100
|
|
|
|
185
|
if ($out =~ /^\\$start/) { |
303
|
10
|
|
|
|
|
25
|
$out = substr($out, 1); |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
else { |
306
|
20
|
|
|
|
|
51
|
$out = $start . '{' . $out . '}'; |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
} |
310
|
232
|
|
|
|
|
693
|
return $out; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
else { |
313
|
|
|
|
|
|
|
# store our name |
314
|
556
|
100
|
100
|
|
|
3078
|
$s->{seen}{$id} = [ ( |
|
|
100
|
|
|
|
|
|
315
|
|
|
|
|
|
|
($name =~ /^[@%]/) |
316
|
|
|
|
|
|
|
? ('\\' . $name ) |
317
|
|
|
|
|
|
|
: ($realtype eq 'CODE' and $name =~ /^[*](.*)$/) |
318
|
|
|
|
|
|
|
? ('\\&' . $1 ) |
319
|
|
|
|
|
|
|
: $name |
320
|
|
|
|
|
|
|
), $val ]; |
321
|
|
|
|
|
|
|
} |
322
|
556
|
|
|
|
|
1007
|
my $no_bless = 0; |
323
|
556
|
|
|
|
|
746
|
my $is_regex = 0; |
324
|
556
|
50
|
100
|
|
|
1203
|
if ( $realpack and ($] >= 5.009005 ? re::is_regexp($val) : $realpack eq 'Regexp') ) { |
|
|
100
|
|
|
|
|
|
325
|
54
|
|
|
|
|
77
|
$is_regex = 1; |
326
|
54
|
|
|
|
|
80
|
$no_bless = $realpack eq 'Regexp'; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# If purity is not set and maxdepth is set, then check depth: |
330
|
|
|
|
|
|
|
# if we have reached maximum depth, return the string |
331
|
|
|
|
|
|
|
# representation of the thing we are currently examining |
332
|
|
|
|
|
|
|
# at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)'). |
333
|
556
|
100
|
100
|
|
|
2399
|
if (!$s->{purity} |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
334
|
|
|
|
|
|
|
and defined($s->{maxdepth}) |
335
|
|
|
|
|
|
|
and $s->{maxdepth} > 0 |
336
|
|
|
|
|
|
|
and $s->{level} >= $s->{maxdepth}) |
337
|
|
|
|
|
|
|
{ |
338
|
9
|
|
|
|
|
43
|
return qq['$val']; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
# avoid recursing infinitely [perl #122111] |
342
|
547
|
100
|
100
|
|
|
1917
|
if ($s->{maxrecurse} > 0 |
343
|
|
|
|
|
|
|
and $s->{level} >= $s->{maxrecurse}) { |
344
|
4
|
|
|
|
|
104
|
die "Recursion limit of $s->{maxrecurse} exceeded"; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
# we have a blessed ref |
348
|
543
|
|
|
|
|
720
|
my ($blesspad); |
349
|
543
|
100
|
100
|
|
|
1120
|
if ($realpack and !$no_bless) { |
350
|
14
|
|
|
|
|
34
|
$out = $s->{'bless'} . '( '; |
351
|
14
|
|
|
|
|
30
|
$blesspad = $s->{apad}; |
352
|
14
|
100
|
|
|
|
37
|
$s->{apad} .= ' ' if ($s->{indent} >= 2); |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
543
|
|
|
|
|
774
|
$s->{level}++; |
356
|
543
|
|
|
|
|
1123
|
my $ipad = $s->{xpad} x $s->{level}; |
357
|
|
|
|
|
|
|
|
358
|
543
|
100
|
100
|
|
|
2946
|
if ($is_regex) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
359
|
54
|
|
|
|
|
69
|
my $pat; |
360
|
54
|
|
|
|
|
70
|
my $flags = ""; |
361
|
54
|
50
|
|
|
|
112
|
if (defined(*re::regexp_pattern{CODE})) { |
362
|
54
|
|
|
|
|
157
|
($pat, $flags) = re::regexp_pattern($val); |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
else { |
365
|
0
|
|
|
|
|
0
|
$pat = "$val"; |
366
|
|
|
|
|
|
|
} |
367
|
54
|
|
|
|
|
209
|
$pat =~ s < |
368
|
|
|
|
|
|
|
(\\.) # anything backslash escaped |
369
|
|
|
|
|
|
|
| (\$)(?![)|]|\z) # any unescaped $, except $| $) and end |
370
|
|
|
|
|
|
|
| / # any unescaped / |
371
|
|
|
|
|
|
|
> |
372
|
67
|
100
|
|
|
|
271
|
{ |
|
|
100
|
|
|
|
|
|
373
|
|
|
|
|
|
|
$1 ? $1 |
374
|
|
|
|
|
|
|
: $2 ? '${\q($)}' |
375
|
|
|
|
|
|
|
: '\\/' |
376
|
54
|
|
|
|
|
154
|
}gex; |
377
|
|
|
|
|
|
|
$out .= "qr/$pat/$flags"; |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
elsif ($realtype eq 'SCALAR' || $realtype eq 'REF' |
380
|
78
|
50
|
|
|
|
130
|
|| $realtype eq 'VSTRING') { |
381
|
0
|
|
|
|
|
0
|
if ($realpack) { |
382
|
|
|
|
|
|
|
$out .= 'do{\\(my $o = ' . $s->_dump($$val, "\${$name}") . ')}'; |
383
|
|
|
|
|
|
|
} |
384
|
78
|
|
|
|
|
319
|
else { |
385
|
|
|
|
|
|
|
$out .= '\\' . $s->_dump($$val, "\${$name}"); |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
} |
388
|
54
|
|
|
|
|
215
|
elsif ($realtype eq 'GLOB') { |
389
|
|
|
|
|
|
|
$out .= '\\' . $s->_dump($$val, "*{$name}"); |
390
|
|
|
|
|
|
|
} |
391
|
139
|
|
|
|
|
214
|
elsif ($realtype eq 'ARRAY') { |
392
|
139
|
|
|
|
|
225
|
my($pad, $mname); |
393
|
139
|
100
|
|
|
|
329
|
my($i) = 0; |
394
|
139
|
|
|
|
|
300
|
$out .= ($name =~ /^\@/) ? '(' : '['; |
395
|
139
|
100
|
|
|
|
599
|
$pad = $s->{sep} . $s->{pad} . $s->{apad}; |
|
|
100
|
|
|
|
|
|
396
|
|
|
|
|
|
|
($name =~ /^\@(.*)$/) ? ($mname = "\$" . $1) : |
397
|
|
|
|
|
|
|
# omit -> if $foo->[0]->{bar}, but not ${$foo->[0]}->{bar} |
398
|
|
|
|
|
|
|
($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) : |
399
|
139
|
100
|
|
|
|
337
|
($mname = $name . '->'); |
400
|
139
|
|
|
|
|
263
|
$mname .= '->' if $mname =~ /^\*.+\{[A-Z]+\}$/; |
401
|
322
|
|
|
|
|
644
|
for my $v (@$val) { |
402
|
|
|
|
|
|
|
$sname = $mname . '[' . $i . ']'; |
403
|
322
|
100
|
|
|
|
596
|
$out .= $pad . $ipad . '#' . $i |
404
|
322
|
|
|
|
|
924
|
if $s->{indent} >= 3; |
405
|
|
|
|
|
|
|
$out .= $pad . $ipad . $s->_dump($v, $sname); |
406
|
|
|
|
|
|
|
$out .= "," |
407
|
320
|
100
|
100
|
|
|
1236
|
if $i++ < $#$val |
|
|
|
100
|
|
|
|
|
408
|
|
|
|
|
|
|
|| ($s->{trailingcomma} && $s->{indent} >= 1); |
409
|
137
|
100
|
|
|
|
438
|
} |
410
|
137
|
100
|
|
|
|
368
|
$out .= $pad . ($s->{xpad} x ($s->{level} - 1)) if $i; |
411
|
|
|
|
|
|
|
$out .= ($name =~ /^\@/) ? ')' : ']'; |
412
|
|
|
|
|
|
|
} |
413
|
205
|
|
|
|
|
343
|
elsif ($realtype eq 'HASH') { |
414
|
205
|
100
|
|
|
|
570
|
my ($k, $v, $pad, $lpad, $mname, $pair); |
415
|
205
|
|
|
|
|
467
|
$out .= ($name =~ /^\%/) ? '(' : '{'; |
416
|
205
|
|
|
|
|
340
|
$pad = $s->{sep} . $s->{pad} . $s->{apad}; |
417
|
205
|
|
|
|
|
306
|
$lpad = $s->{apad}; |
418
|
205
|
100
|
|
|
|
1072
|
$pair = $s->{pair}; |
|
|
100
|
|
|
|
|
|
419
|
|
|
|
|
|
|
($name =~ /^\%(.*)$/) ? ($mname = "\$" . $1) : |
420
|
|
|
|
|
|
|
# omit -> if $foo->[0]->{bar}, but not ${$foo->[0]}->{bar} |
421
|
|
|
|
|
|
|
($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) : |
422
|
205
|
100
|
|
|
|
530
|
($mname = $name . '->'); |
423
|
205
|
100
|
|
|
|
507
|
$mname .= '->' if $mname =~ /^\*.+\{[A-Z]+\}$/; |
424
|
205
|
|
|
|
|
352
|
my $sortkeys = defined($s->{sortkeys}) ? $s->{sortkeys} : ''; |
425
|
205
|
100
|
|
|
|
465
|
my $keys = []; |
426
|
113
|
100
|
|
|
|
241
|
if ($sortkeys) { |
427
|
11
|
|
|
|
|
32
|
if (ref($s->{sortkeys}) eq 'CODE') { |
428
|
11
|
100
|
|
|
|
202
|
$keys = $s->{sortkeys}($val); |
429
|
1
|
|
|
|
|
205
|
unless (ref($keys) eq 'ARRAY') { |
430
|
1
|
|
|
|
|
42
|
Carp::carp("Sortkeys subroutine did not return ARRAYREF"); |
431
|
|
|
|
|
|
|
$keys = []; |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
} |
434
|
102
|
|
|
|
|
470
|
else { |
435
|
|
|
|
|
|
|
$keys = [ sort keys %$val ]; |
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
205
|
|
|
|
|
407
|
# Ensure hash iterator is reset |
440
|
|
|
|
|
|
|
keys(%$val); |
441
|
205
|
|
|
|
|
297
|
|
442
|
205
|
100
|
|
|
|
910
|
my $key; |
|
|
100
|
|
|
|
|
|
443
|
|
|
|
|
|
|
while (($k, $v) = ! $sortkeys ? (each %$val) : |
444
|
|
|
|
|
|
|
@$keys ? ($key = shift(@$keys), $val->{$key}) : |
445
|
|
|
|
|
|
|
() ) |
446
|
508
|
|
|
|
|
1536
|
{ |
447
|
|
|
|
|
|
|
my $nk = $s->_dump($k, ""); |
448
|
|
|
|
|
|
|
|
449
|
508
|
100
|
100
|
|
|
2863
|
# _dump doesn't quote numbers of this form |
|
|
100
|
100
|
|
|
|
|
450
|
6
|
100
|
|
|
|
22
|
if ($s->{quotekeys} && $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { |
451
|
|
|
|
|
|
|
$nk = $s->{useqq} ? qq("$nk") : qq('$nk'); |
452
|
|
|
|
|
|
|
} |
453
|
150
|
|
|
|
|
334
|
elsif (!$s->{quotekeys} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/) { |
454
|
|
|
|
|
|
|
$nk = $1 |
455
|
|
|
|
|
|
|
} |
456
|
508
|
|
|
|
|
1108
|
|
457
|
508
|
|
|
|
|
1064
|
$sname = $mname . '{' . $nk . '}'; |
458
|
|
|
|
|
|
|
$out .= $pad . $ipad . $nk . $pair; |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
# temporarily alter apad |
461
|
508
|
100
|
|
|
|
1195
|
$s->{apad} .= (" " x (length($nk) + 4)) |
462
|
508
|
|
|
|
|
1018
|
if $s->{indent} >= 2; |
463
|
|
|
|
|
|
|
$out .= $s->_dump($val->{$k}, $sname) . ","; |
464
|
505
|
100
|
|
|
|
2339
|
$s->{apad} = $lpad |
465
|
|
|
|
|
|
|
if $s->{indent} >= 2; |
466
|
202
|
100
|
|
|
|
529
|
} |
467
|
194
|
100
|
100
|
|
|
544
|
if (substr($out, -1) eq ',') { |
468
|
194
|
|
|
|
|
471
|
chop $out if !$s->{trailingcomma} || !$s->{indent}; |
469
|
|
|
|
|
|
|
$out .= $pad . ($s->{xpad} x ($s->{level} - 1)); |
470
|
202
|
100
|
|
|
|
1005
|
} |
471
|
|
|
|
|
|
|
$out .= ($name =~ /^\%/) ? ')' : '}'; |
472
|
|
|
|
|
|
|
} |
473
|
12
|
100
|
|
|
|
31
|
elsif ($realtype eq 'CODE') { |
474
|
4
|
|
|
|
|
15
|
if ($s->{deparse}) { |
475
|
4
|
|
|
|
|
5477
|
require B::Deparse; |
476
|
4
|
|
|
|
|
39
|
my $sub = 'sub ' . (B::Deparse->new)->coderef2text($val); |
477
|
4
|
|
|
|
|
23
|
my $pad = $s->{sep} . $s->{pad} . $s->{apad} . $s->{xpad} x ($s->{level} - 1); |
478
|
4
|
|
|
|
|
12
|
$sub =~ s/\n/$pad/gs; |
479
|
|
|
|
|
|
|
$out .= $sub; |
480
|
|
|
|
|
|
|
} |
481
|
8
|
|
|
|
|
20
|
else { |
482
|
8
|
100
|
|
|
|
210
|
$out .= 'sub { "DUMMY" }'; |
483
|
|
|
|
|
|
|
Carp::carp("Encountered CODE ref, using dummy placeholder") if $s->{purity}; |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
} |
486
|
1
|
|
|
|
|
259
|
else { |
487
|
|
|
|
|
|
|
Carp::croak("Can't handle '$realtype' type"); |
488
|
|
|
|
|
|
|
} |
489
|
535
|
100
|
100
|
|
|
1277
|
|
490
|
13
|
|
|
|
|
32
|
if ($realpack and !$no_bless) { # we have a blessed ref |
491
|
|
|
|
|
|
|
$out .= ', ' . _quote($realpack) . ' )'; |
492
|
13
|
50
|
|
|
|
42
|
$out .= '->' . $s->{toaster} . '()' |
493
|
13
|
|
|
|
|
26
|
if $s->{toaster} ne ''; |
494
|
|
|
|
|
|
|
$s->{apad} = $blesspad; |
495
|
535
|
|
|
|
|
939
|
} |
496
|
|
|
|
|
|
|
$s->{level}--; |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
else { # simple scalar |
499
|
1751
|
|
|
|
|
3059
|
|
500
|
1751
|
|
|
|
|
2209
|
my $ref = \$_[1]; |
501
|
|
|
|
|
|
|
my $v; |
502
|
1751
|
100
|
|
|
|
3212
|
# first, catalog the scalar |
503
|
1199
|
|
|
|
|
1995
|
if ($name ne '') { |
504
|
1199
|
100
|
|
|
|
2451
|
$id = format_refaddr($ref); |
505
|
110
|
100
|
|
|
|
259
|
if (exists $s->{seen}{$id}) { |
506
|
8
|
|
|
|
|
15
|
if ($s->{seen}{$id}[2]) { |
507
|
|
|
|
|
|
|
$out = $s->{seen}{$id}[0]; |
508
|
8
|
|
|
|
|
26
|
#warn "[<$out]\n"; |
509
|
|
|
|
|
|
|
return "\${$out}"; |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
else { |
513
|
1089
|
|
|
|
|
3236
|
#warn "[>\\$name]\n"; |
514
|
|
|
|
|
|
|
$s->{seen}{$id} = ["\\$name", $ref]; |
515
|
|
|
|
|
|
|
} |
516
|
1743
|
|
|
|
|
2604
|
} |
517
|
1743
|
100
|
66
|
|
|
13319
|
$ref = \$val; |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
518
|
74
|
|
|
|
|
267
|
if (ref($ref) eq 'GLOB') { # glob |
519
|
74
|
|
|
|
|
284
|
my $name = substr($val, 1); |
520
|
74
|
100
|
100
|
|
|
501
|
$name =~ s/^main::(?!\z)/::/; |
521
|
30
|
|
|
|
|
56
|
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::') { |
522
|
|
|
|
|
|
|
$sname = $name; |
523
|
|
|
|
|
|
|
} |
524
|
44
|
|
|
|
|
111
|
else { |
525
|
44
|
100
|
|
|
|
131
|
local $s->{useqq} = IS_PRE_516_PERL && ($s->{useqq} || $name =~ /[^\x00-\x7f]/) ? 1 : $s->{useqq}; |
526
|
|
|
|
|
|
|
$sname = $s->_dump( |
527
|
|
|
|
|
|
|
$name eq 'main::' |
528
|
|
|
|
|
|
|
? '' |
529
|
|
|
|
|
|
|
: $name, |
530
|
|
|
|
|
|
|
"", |
531
|
44
|
|
|
|
|
101
|
); |
532
|
|
|
|
|
|
|
$sname = '{' . $sname . '}'; |
533
|
74
|
100
|
|
|
|
153
|
} |
534
|
24
|
|
|
|
|
31
|
if ($s->{purity}) { |
535
|
24
|
|
|
|
|
50
|
my $k; |
536
|
24
|
|
|
|
|
62
|
local ($s->{level}) = 0; |
537
|
72
|
|
|
|
|
166
|
for $k (qw(SCALAR ARRAY HASH)) { |
538
|
72
|
100
|
|
|
|
162
|
my $gval = *$val{$k}; |
539
|
56
|
100
|
100
|
|
|
151
|
next unless defined $gval; |
540
|
|
|
|
|
|
|
next if $k eq "SCALAR" && ! defined $$gval; # always there |
541
|
|
|
|
|
|
|
|
542
|
44
|
|
|
|
|
63
|
# _dump can push into @post, so we hold our place using $postlen |
543
|
44
|
|
|
|
|
103
|
my $postlen = scalar @post; |
544
|
44
|
100
|
|
|
|
94
|
$post[$postlen] = "\*$sname = "; |
545
|
44
|
|
|
|
|
154
|
local ($s->{apad}) = " " x length($post[$postlen]) if $s->{indent} >= 2; |
546
|
|
|
|
|
|
|
$post[$postlen] .= $s->_dump($gval, "\*$sname\{$k\}"); |
547
|
|
|
|
|
|
|
} |
548
|
74
|
|
|
|
|
171
|
} |
549
|
|
|
|
|
|
|
$out .= '*' . $sname; |
550
|
|
|
|
|
|
|
} |
551
|
10
|
|
|
|
|
21
|
elsif (!defined($val)) { |
552
|
|
|
|
|
|
|
$out .= "undef"; |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
# This calls the XSUB _vstring (if the XS code is loaded). I'm not *sure* if |
555
|
|
|
|
|
|
|
# if belongs in the "Pure Perl" implementation. It sort of depends on what |
556
|
|
|
|
|
|
|
# was meant by "Pure Perl", as this subroutine already relies Scalar::Util |
557
|
|
|
|
|
|
|
# loading, which means that it has an XS dependency. De facto, it's the |
558
|
|
|
|
|
|
|
# "Pure Perl" implementation of dumping (which uses XS helper code), as |
559
|
|
|
|
|
|
|
# opposed to the C implementation (which calls out to Perl helper code). |
560
|
|
|
|
|
|
|
# So in that sense this is fine - it just happens to be a local XS helper. |
561
|
|
|
|
|
|
|
elsif (defined &_vstring and $v = _vstring($val) |
562
|
6
|
|
|
|
|
14
|
and !_bad_vsmg || eval $v eq $val) { |
563
|
|
|
|
|
|
|
$out .= $v; |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
# However the confusion comes here - if we *can't* find our XS helper, we |
566
|
|
|
|
|
|
|
# fall back to this code, which generates different (worse) results. That's |
567
|
|
|
|
|
|
|
# better than nothing, *but* it means that if you run the regression tests |
568
|
|
|
|
|
|
|
# with Dumper.so missing, the test for "vstrings" fails, because this code |
569
|
|
|
|
|
|
|
# here generates a different result. So there are actually "three" different |
570
|
|
|
|
|
|
|
# implementations of Data::Dumper (kind of sort of) but we only test two. |
571
|
|
|
|
|
|
|
elsif (!defined &_vstring |
572
|
0
|
|
|
|
|
0
|
and ref $ref eq 'VSTRING' || eval{Scalar::Util::isvstring($val)}) { |
573
|
|
|
|
|
|
|
$out .= sprintf "v%vd", $val; |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
# \d here would treat "1\x{660}" as a safe decimal number |
576
|
458
|
|
|
|
|
941
|
elsif ($val =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { # safe decimal number |
577
|
|
|
|
|
|
|
$out .= $val; |
578
|
|
|
|
|
|
|
} |
579
|
1195
|
100
|
100
|
|
|
4280
|
else { # string |
580
|
|
|
|
|
|
|
if ($s->{useqq} or $val =~ tr/\0-\377//c) { |
581
|
102
|
|
|
|
|
224
|
# Fall back to qq if there's Unicode |
582
|
|
|
|
|
|
|
$out .= qquote($val, $s->{useqq}); |
583
|
|
|
|
|
|
|
} |
584
|
1093
|
|
|
|
|
1891
|
else { |
585
|
|
|
|
|
|
|
$out .= _quote($val); |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
} |
588
|
2278
|
100
|
|
|
|
4342
|
} |
589
|
|
|
|
|
|
|
if ($id) { |
590
|
|
|
|
|
|
|
# if we made it this far, $id was added to seen list at current |
591
|
1726
|
100
|
|
|
|
3508
|
# level, so remove it to get deep copies |
|
|
50
|
|
|
|
|
|
592
|
26
|
|
|
|
|
50
|
if ($s->{deepcopy}) { |
593
|
|
|
|
|
|
|
delete($s->{seen}{$id}); |
594
|
|
|
|
|
|
|
} |
595
|
1700
|
|
|
|
|
3080
|
elsif ($name) { |
596
|
|
|
|
|
|
|
$s->{seen}{$id}[2] = 1; |
597
|
|
|
|
|
|
|
} |
598
|
2278
|
|
|
|
|
5337
|
} |
599
|
|
|
|
|
|
|
return $out; |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
# |
603
|
|
|
|
|
|
|
# non-OO style of earlier version |
604
|
|
|
|
|
|
|
# |
605
|
85
|
|
|
85
|
1
|
73075
|
sub Dumper { |
606
|
|
|
|
|
|
|
return Data::Dumper->Dump([@_]); |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
# compat stub |
610
|
16
|
|
|
16
|
0
|
8706
|
sub DumperX { |
611
|
|
|
|
|
|
|
return Data::Dumper->Dumpxs([@_], []); |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
# |
615
|
|
|
|
|
|
|
# reset the "seen" cache |
616
|
|
|
|
|
|
|
# |
617
|
12
|
|
|
12
|
1
|
9286
|
sub Reset { |
618
|
12
|
|
|
|
|
57
|
my($s) = shift; |
619
|
12
|
|
|
|
|
153
|
$s->{seen} = {}; |
620
|
|
|
|
|
|
|
return $s; |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
33
|
|
|
33
|
0
|
862
|
sub Indent { |
624
|
33
|
100
|
|
|
|
72
|
my($s, $v) = @_; |
625
|
32
|
100
|
|
|
|
64
|
if (@_ >= 2) { |
626
|
9
|
|
|
|
|
13
|
if ($v == 0) { |
627
|
9
|
|
|
|
|
17
|
$s->{xpad} = ""; |
628
|
|
|
|
|
|
|
$s->{sep} = ""; |
629
|
|
|
|
|
|
|
} |
630
|
23
|
|
|
|
|
40
|
else { |
631
|
23
|
|
|
|
|
34
|
$s->{xpad} = " "; |
632
|
|
|
|
|
|
|
$s->{sep} = "\n"; |
633
|
32
|
|
|
|
|
46
|
} |
634
|
32
|
|
|
|
|
77
|
$s->{indent} = $v; |
635
|
|
|
|
|
|
|
return $s; |
636
|
|
|
|
|
|
|
} |
637
|
1
|
|
|
|
|
3
|
else { |
638
|
|
|
|
|
|
|
return $s->{indent}; |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
} |
641
|
|
|
|
|
|
|
|
642
|
28
|
|
|
28
|
0
|
97
|
sub Trailingcomma { |
643
|
28
|
50
|
|
|
|
83
|
my($s, $v) = @_; |
644
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{trailingcomma} = $v), return $s) : $s->{trailingcomma}; |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
3
|
|
|
3
|
0
|
8
|
sub Pair { |
648
|
3
|
100
|
|
|
|
19
|
my($s, $v) = @_; |
649
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{pair} = $v), return $s) : $s->{pair}; |
650
|
|
|
|
|
|
|
} |
651
|
|
|
|
|
|
|
|
652
|
2
|
|
|
2
|
0
|
11
|
sub Pad { |
653
|
2
|
50
|
|
|
|
9
|
my($s, $v) = @_; |
654
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{pad} = $v), return $s) : $s->{pad}; |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
2
|
|
|
2
|
0
|
10
|
sub Varname { |
658
|
2
|
50
|
|
|
|
18
|
my($s, $v) = @_; |
659
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{varname} = $v), return $s) : $s->{varname}; |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
|
662
|
28
|
|
|
28
|
0
|
65
|
sub Purity { |
663
|
28
|
50
|
|
|
|
573
|
my($s, $v) = @_; |
664
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{purity} = $v), return $s) : $s->{purity}; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
6
|
|
|
6
|
0
|
31
|
sub Useqq { |
668
|
6
|
50
|
|
|
|
22
|
my($s, $v) = @_; |
669
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{useqq} = $v), return $s) : $s->{useqq}; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
9
|
|
|
9
|
0
|
36
|
sub Terse { |
673
|
9
|
100
|
|
|
|
47
|
my($s, $v) = @_; |
674
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{terse} = $v), return $s) : $s->{terse}; |
675
|
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
|
677
|
6
|
|
|
6
|
0
|
32
|
sub Freezer { |
678
|
6
|
50
|
|
|
|
27
|
my($s, $v) = @_; |
679
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{freezer} = $v), return $s) : $s->{freezer}; |
680
|
|
|
|
|
|
|
} |
681
|
|
|
|
|
|
|
|
682
|
6
|
|
|
6
|
0
|
33
|
sub Toaster { |
683
|
6
|
50
|
|
|
|
23
|
my($s, $v) = @_; |
684
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{toaster} = $v), return $s) : $s->{toaster}; |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
|
687
|
8
|
|
|
8
|
0
|
42
|
sub Deepcopy { |
688
|
8
|
50
|
|
|
|
148
|
my($s, $v) = @_; |
689
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{deepcopy} = $v), return $s) : $s->{deepcopy}; |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
7
|
|
|
7
|
0
|
28
|
sub Quotekeys { |
693
|
7
|
50
|
|
|
|
24
|
my($s, $v) = @_; |
694
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{quotekeys} = $v), return $s) : $s->{quotekeys}; |
695
|
|
|
|
|
|
|
} |
696
|
|
|
|
|
|
|
|
697
|
6
|
|
|
6
|
0
|
27
|
sub Bless { |
698
|
6
|
50
|
|
|
|
23
|
my($s, $v) = @_; |
699
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'bless'} = $v), return $s) : $s->{'bless'}; |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
|
702
|
10
|
|
|
10
|
0
|
26
|
sub Maxdepth { |
703
|
10
|
100
|
|
|
|
208
|
my($s, $v) = @_; |
704
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'maxdepth'} = $v), return $s) : $s->{'maxdepth'}; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
0
|
|
|
0
|
0
|
0
|
sub Maxrecurse { |
708
|
0
|
0
|
|
|
|
0
|
my($s, $v) = @_; |
709
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'maxrecurse'} = $v), return $s) : $s->{'maxrecurse'}; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
3
|
|
|
3
|
0
|
19
|
sub Useperl { |
713
|
3
|
50
|
|
|
|
17
|
my($s, $v) = @_; |
714
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'useperl'} = $v), return $s) : $s->{'useperl'}; |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
|
717
|
39
|
|
|
39
|
0
|
136
|
sub Sortkeys { |
718
|
39
|
50
|
|
|
|
105
|
my($s, $v) = @_; |
719
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'sortkeys'} = $v), return $s) : $s->{'sortkeys'}; |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
|
722
|
6
|
|
|
6
|
0
|
24
|
sub Deparse { |
723
|
6
|
100
|
|
|
|
26
|
my($s, $v) = @_; |
724
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'deparse'} = $v), return $s) : $s->{'deparse'}; |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
6
|
|
|
6
|
0
|
25
|
sub Sparseseen { |
728
|
6
|
50
|
|
|
|
21
|
my($s, $v) = @_; |
729
|
|
|
|
|
|
|
@_ >= 2 ? (($s->{'noseen'} = $v), return $s) : $s->{'noseen'}; |
730
|
|
|
|
|
|
|
} |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
# used by qquote below |
733
|
|
|
|
|
|
|
my %esc = ( |
734
|
|
|
|
|
|
|
"\a" => "\\a", |
735
|
|
|
|
|
|
|
"\b" => "\\b", |
736
|
|
|
|
|
|
|
"\t" => "\\t", |
737
|
|
|
|
|
|
|
"\n" => "\\n", |
738
|
|
|
|
|
|
|
"\f" => "\\f", |
739
|
|
|
|
|
|
|
"\r" => "\\r", |
740
|
|
|
|
|
|
|
"\e" => "\\e", |
741
|
|
|
|
|
|
|
); |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
my $low_controls = ($IS_ASCII) |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
# This includes \177, because traditionally it has been |
746
|
|
|
|
|
|
|
# output as octal, even though it isn't really a "low" |
747
|
|
|
|
|
|
|
# control |
748
|
|
|
|
|
|
|
? qr/[\0-\x1f\177]/ |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
# EBCDIC low controls. |
751
|
|
|
|
|
|
|
: qr/[\0-\x3f]/; |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
# put a string value in double quotes |
754
|
102
|
|
|
102
|
0
|
179
|
sub qquote { |
755
|
102
|
|
|
|
|
258
|
local($_) = shift; |
756
|
|
|
|
|
|
|
s/([\\\"\@\$])/\\$1/g; |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
# This efficiently changes the high ordinal characters to \x{} if the utf8 |
759
|
|
|
|
|
|
|
# flag is on. On ASCII platforms, the high ordinals are all the |
760
|
|
|
|
|
|
|
# non-ASCII's. On EBCDIC platforms, we don't include in these the non-ASCII |
761
|
|
|
|
|
|
|
# controls whose ordinals are less than SPACE, excluded below by the range |
762
|
|
|
|
|
|
|
# \0-\x3f. On ASCII platforms this range just compiles as part of :ascii:. |
763
|
|
|
|
|
|
|
# On EBCDIC platforms, there is just one outlier high ordinal control, and |
764
|
26
|
|
|
26
|
|
19019
|
# it gets output as \x{}. |
|
26
|
|
|
|
|
452
|
|
|
26
|
|
|
|
|
136
|
|
|
102
|
|
|
|
|
139
|
|
|
102
|
|
|
|
|
127
|
|
|
102
|
|
|
|
|
143
|
|
765
|
314
|
|
|
|
|
954
|
my $bytes; { use bytes; $bytes = length } |
766
|
102
|
100
|
33
|
|
|
451
|
s/([^[:ascii:]\0-\x3f])/sprintf("\\x{%x}",ord($1))/ge |
|
|
|
66
|
|
|
|
|
767
|
|
|
|
|
|
|
if $bytes > length |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
# The above doesn't get the EBCDIC outlier high ordinal control when |
770
|
|
|
|
|
|
|
# the string is UTF-8 but there are no UTF-8 variant characters in it. |
771
|
|
|
|
|
|
|
# We want that to come out as \x{} anyway. We need is_utf8() to do |
772
|
|
|
|
|
|
|
# this. |
773
|
|
|
|
|
|
|
|| (! $IS_ASCII && utf8::is_utf8($_)); |
774
|
102
|
100
|
|
|
|
465
|
|
775
|
|
|
|
|
|
|
return qq("$_") unless /[[:^print:]]/; # fast exit if only printables |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
# Here, there is at least one non-printable to output. First, translate the |
778
|
33
|
|
|
|
|
140
|
# escapes. |
779
|
|
|
|
|
|
|
s/([\a\b\t\n\f\r\e])/$esc{$1}/g; |
780
|
|
|
|
|
|
|
|
781
|
33
|
|
|
|
|
208
|
# no need for 3 digits in escape for octals not followed by a digit. |
|
119
|
|
|
|
|
392
|
|
782
|
|
|
|
|
|
|
s/($low_controls)(?!\d)/'\\'.sprintf('%o',ord($1))/eg; |
783
|
|
|
|
|
|
|
|
784
|
33
|
|
|
|
|
152
|
# But otherwise use 3 digits |
|
4
|
|
|
|
|
23
|
|
785
|
|
|
|
|
|
|
s/($low_controls)/'\\'.sprintf('%03o',ord($1))/eg; |
786
|
|
|
|
|
|
|
|
787
|
33
|
|
100
|
|
|
77
|
# all but last branch below not supported --BEHAVIOR SUBJECT TO CHANGE-- |
788
|
33
|
50
|
|
|
|
108
|
my $high = shift || ""; |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
789
|
0
|
0
|
|
|
|
0
|
if ($high eq "iso8859") { # Doesn't escape the Latin1 printables |
790
|
0
|
|
|
|
|
0
|
if ($IS_ASCII) { |
|
0
|
|
|
|
|
0
|
|
791
|
|
|
|
|
|
|
s/([\200-\240])/'\\'.sprintf('%o',ord($1))/eg; |
792
|
|
|
|
|
|
|
} |
793
|
0
|
|
|
|
|
0
|
else { |
794
|
0
|
|
|
|
|
0
|
my $high_control = utf8::unicode_to_native(0x9F); |
|
0
|
|
|
|
|
0
|
|
795
|
|
|
|
|
|
|
s/$high_control/sprintf('\\%o',ord($1))/eg; |
796
|
|
|
|
|
|
|
} |
797
|
|
|
|
|
|
|
} elsif ($high eq "utf8") { |
798
|
|
|
|
|
|
|
# Some discussion of what to do here is in |
799
|
|
|
|
|
|
|
# https://rt.perl.org/Ticket/Display.html?id=113088 |
800
|
|
|
|
|
|
|
# use utf8; |
801
|
|
|
|
|
|
|
# $str =~ s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge; |
802
|
|
|
|
|
|
|
} elsif ($high eq "8bit") { |
803
|
|
|
|
|
|
|
# leave it as it is |
804
|
33
|
|
|
|
|
105
|
} else { |
|
264
|
|
|
|
|
682
|
|
805
|
|
|
|
|
|
|
s/([[:^ascii:]])/'\\'.sprintf('%03o',ord($1))/eg; |
806
|
|
|
|
|
|
|
#s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge; |
807
|
|
|
|
|
|
|
} |
808
|
33
|
|
|
|
|
138
|
|
809
|
|
|
|
|
|
|
return qq("$_"); |
810
|
|
|
|
|
|
|
} |
811
|
|
|
|
|
|
|
|
812
|
981
|
|
|
981
|
|
1297
|
sub _refine_name { |
813
|
981
|
|
|
|
|
1724
|
my $s = shift; |
814
|
981
|
100
|
|
|
|
1671
|
my ($name, $val, $i) = @_; |
815
|
203
|
100
|
|
|
|
724
|
if (defined $name) { |
|
|
100
|
|
|
|
|
|
816
|
77
|
100
|
|
|
|
161
|
if ($name =~ /^[*](.*)$/) { |
817
|
76
|
100
|
|
|
|
321
|
if (defined $val) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
818
|
|
|
|
|
|
|
$name = (ref $val eq 'ARRAY') ? ( "\@" . $1 ) : |
819
|
|
|
|
|
|
|
(ref $val eq 'HASH') ? ( "\%" . $1 ) : |
820
|
|
|
|
|
|
|
(ref $val eq 'CODE') ? ( "\*" . $1 ) : |
821
|
|
|
|
|
|
|
( "\$" . $1 ) ; |
822
|
|
|
|
|
|
|
} |
823
|
1
|
|
|
|
|
4
|
else { |
824
|
|
|
|
|
|
|
$name = "\$" . $1; |
825
|
|
|
|
|
|
|
} |
826
|
|
|
|
|
|
|
} |
827
|
125
|
|
|
|
|
251
|
elsif ($name !~ /^\$/) { |
828
|
|
|
|
|
|
|
$name = "\$" . $name; |
829
|
|
|
|
|
|
|
} |
830
|
|
|
|
|
|
|
} |
831
|
778
|
|
|
|
|
1612
|
else { # no names provided |
832
|
|
|
|
|
|
|
$name = "\$" . $s->{varname} . $i; |
833
|
981
|
|
|
|
|
1960
|
} |
834
|
|
|
|
|
|
|
return $name; |
835
|
|
|
|
|
|
|
} |
836
|
|
|
|
|
|
|
|
837
|
976
|
|
|
976
|
|
1274
|
sub _compose_out { |
838
|
976
|
|
|
|
|
1752
|
my $s = shift; |
839
|
976
|
|
|
|
|
1335
|
my ($valstr, $postref) = @_; |
840
|
976
|
|
|
|
|
2188
|
my $out = ""; |
841
|
976
|
100
|
|
|
|
1192
|
$out .= $s->{pad} . $valstr . $s->{sep}; |
|
976
|
|
|
|
|
2022
|
|
842
|
|
|
|
|
|
|
if (@{$postref}) { |
843
|
32
|
|
|
|
|
110
|
$out .= $s->{pad} . |
844
|
|
|
|
|
|
|
join(';' . $s->{sep} . $s->{pad}, @{$postref}) . |
845
|
32
|
|
|
|
|
64
|
';' . |
846
|
|
|
|
|
|
|
$s->{sep}; |
847
|
976
|
|
|
|
|
1839
|
} |
848
|
|
|
|
|
|
|
return $out; |
849
|
|
|
|
|
|
|
} |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
1; |
852
|
|
|
|
|
|
|
__END__ |