line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
35
|
|
|
35
|
|
141929
|
use strict; |
|
35
|
|
|
|
|
114
|
|
|
35
|
|
|
|
|
1041
|
|
2
|
35
|
|
|
35
|
|
249
|
use warnings; |
|
35
|
|
|
|
|
69
|
|
|
35
|
|
|
|
|
1805
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Dumper; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.036'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
35
|
|
|
35
|
|
230
|
use Scalar::Util qw/ blessed refaddr reftype /; |
|
35
|
|
|
|
|
74
|
|
|
35
|
|
|
|
|
1909
|
|
8
|
35
|
|
|
35
|
|
1257
|
use YAML::PP; |
|
35
|
|
|
|
|
78
|
|
|
35
|
|
|
|
|
1027
|
|
9
|
35
|
|
|
35
|
|
17654
|
use YAML::PP::Emitter; |
|
35
|
|
|
|
|
104
|
|
|
35
|
|
|
|
|
1216
|
|
10
|
35
|
|
|
35
|
|
15461
|
use YAML::PP::Representer; |
|
35
|
|
|
|
|
91
|
|
|
35
|
|
|
|
|
1034
|
|
11
|
35
|
|
|
35
|
|
13882
|
use YAML::PP::Writer; |
|
35
|
|
|
|
|
97
|
|
|
35
|
|
|
|
|
1040
|
|
12
|
35
|
|
|
35
|
|
14134
|
use YAML::PP::Writer::File; |
|
35
|
|
|
|
|
97
|
|
|
35
|
|
|
|
|
1309
|
|
13
|
35
|
|
|
|
|
66055
|
use YAML::PP::Common qw/ |
14
|
|
|
|
|
|
|
YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE |
15
|
|
|
|
|
|
|
YAML_DOUBLE_QUOTED_SCALAR_STYLE |
16
|
|
|
|
|
|
|
YAML_ANY_SCALAR_STYLE |
17
|
|
|
|
|
|
|
YAML_LITERAL_SCALAR_STYLE YAML_FOLDED_SCALAR_STYLE |
18
|
|
|
|
|
|
|
YAML_FLOW_SEQUENCE_STYLE YAML_FLOW_MAPPING_STYLE |
19
|
|
|
|
|
|
|
YAML_BLOCK_MAPPING_STYLE YAML_BLOCK_SEQUENCE_STYLE |
20
|
35
|
|
|
35
|
|
258
|
/; |
|
35
|
|
|
|
|
79
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
184
|
|
|
184
|
0
|
879
|
my ($class, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
184
|
|
|
|
|
418
|
my $header = delete $args{header}; |
26
|
184
|
100
|
|
|
|
478
|
$header = 1 unless defined $header; |
27
|
184
|
|
|
|
|
357
|
my $footer = delete $args{footer}; |
28
|
184
|
100
|
|
|
|
426
|
$footer = 0 unless defined $footer; |
29
|
184
|
|
|
|
|
311
|
my $version_directive = delete $args{version_directive}; |
30
|
184
|
|
|
|
|
296
|
my $preserve = delete $args{preserve}; |
31
|
|
|
|
|
|
|
|
32
|
184
|
|
66
|
|
|
560
|
my $schema = delete $args{schema} || YAML::PP->default_schema( |
33
|
|
|
|
|
|
|
boolean => 'perl', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
184
|
|
66
|
|
|
470
|
my $emitter = delete $args{emitter} || YAML::PP::Emitter->new; |
37
|
184
|
100
|
|
|
|
582
|
unless (blessed($emitter)) { |
38
|
183
|
|
|
|
|
997
|
$emitter = YAML::PP::Emitter->new( |
39
|
|
|
|
|
|
|
%$emitter |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
184
|
50
|
|
|
|
556
|
if (keys %args) { |
44
|
0
|
|
|
|
|
0
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
45
|
|
|
|
|
|
|
} |
46
|
184
|
|
|
|
|
781
|
my $self = bless { |
47
|
|
|
|
|
|
|
representer => YAML::PP::Representer->new( |
48
|
|
|
|
|
|
|
schema => $schema, |
49
|
|
|
|
|
|
|
preserve => $preserve, |
50
|
|
|
|
|
|
|
), |
51
|
|
|
|
|
|
|
version_directive => $version_directive, |
52
|
|
|
|
|
|
|
emitter => $emitter, |
53
|
|
|
|
|
|
|
seen => {}, |
54
|
|
|
|
|
|
|
anchors => {}, |
55
|
|
|
|
|
|
|
anchor_num => 0, |
56
|
|
|
|
|
|
|
header => $header, |
57
|
|
|
|
|
|
|
footer => $footer, |
58
|
|
|
|
|
|
|
}, $class; |
59
|
184
|
|
|
|
|
487
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clone { |
63
|
9
|
|
|
9
|
0
|
17
|
my ($self) = @_; |
64
|
9
|
|
|
|
|
16
|
my $clone = { |
65
|
|
|
|
|
|
|
representer => $self->representer->clone, |
66
|
|
|
|
|
|
|
emitter => $self->emitter->clone, |
67
|
|
|
|
|
|
|
version_directive => $self->version_directive, |
68
|
|
|
|
|
|
|
seen => {}, |
69
|
|
|
|
|
|
|
anchors => {}, |
70
|
|
|
|
|
|
|
anchor_num => 0, |
71
|
|
|
|
|
|
|
header => $self->header, |
72
|
|
|
|
|
|
|
footer => $self->footer, |
73
|
|
|
|
|
|
|
}; |
74
|
9
|
|
|
|
|
44
|
return bless $clone, ref $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub init { |
78
|
1224
|
|
|
1224
|
0
|
1999
|
my ($self) = @_; |
79
|
1224
|
|
|
|
|
2455
|
$self->{seen} = {}; |
80
|
1224
|
|
|
|
|
2322
|
$self->{anchors} = {}; |
81
|
1224
|
|
|
|
|
2004
|
$self->{anchor_num} = 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
12293
|
|
|
12293
|
0
|
40767
|
sub emitter { return $_[0]->{emitter} } |
85
|
2465
|
|
|
2465
|
0
|
6916
|
sub representer { return $_[0]->{representer} } |
86
|
0
|
|
|
0
|
0
|
0
|
sub set_representer { $_[0]->{representer} = $_[1] } |
87
|
1200
|
|
|
1200
|
0
|
3842
|
sub header { return $_[0]->{header} } |
88
|
1232
|
|
|
1232
|
0
|
2519
|
sub footer { return $_[0]->{footer} } |
89
|
1233
|
|
|
1233
|
0
|
3135
|
sub version_directive { return $_[0]->{version_directive} } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub dump { |
92
|
1192
|
|
|
1192
|
0
|
2471
|
my ($self, @docs) = @_; |
93
|
1192
|
|
|
|
|
2152
|
$self->emitter->init; |
94
|
|
|
|
|
|
|
|
95
|
1191
|
|
|
|
|
2470
|
$self->emitter->stream_start_event({}); |
96
|
|
|
|
|
|
|
|
97
|
1191
|
|
|
|
|
3658
|
for my $i (0 .. $#docs) { |
98
|
1224
|
|
100
|
|
|
3969
|
my $header_implicit = ($i == 0 and not $self->header); |
99
|
1224
|
|
|
|
|
3509
|
my %args = ( |
100
|
|
|
|
|
|
|
implicit => $header_implicit, |
101
|
|
|
|
|
|
|
); |
102
|
1224
|
100
|
|
|
|
2464
|
if ($self->version_directive) { |
103
|
18
|
|
|
|
|
38
|
my ($major, $minor) = split m/\./, $self->representer->schema->yaml_version; |
104
|
18
|
|
|
|
|
67
|
$args{version_directive} = { major => $major, minor => $minor }; |
105
|
|
|
|
|
|
|
} |
106
|
1224
|
|
|
|
|
2316
|
$self->emitter->document_start_event( \%args ); |
107
|
1224
|
|
|
|
|
3148
|
$self->init; |
108
|
1224
|
|
|
|
|
4129
|
$self->_check_references($docs[ $i ]); |
109
|
1224
|
|
|
|
|
3161
|
$self->_dump_node($docs[ $i ]); |
110
|
1223
|
|
|
|
|
3288
|
my $footer_implicit = (not $self->footer); |
111
|
1223
|
|
|
|
|
2424
|
$self->emitter->document_end_event({ implicit => $footer_implicit }); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
1190
|
|
|
|
|
2397
|
$self->emitter->stream_end_event({}); |
115
|
|
|
|
|
|
|
|
116
|
1190
|
|
|
|
|
2386
|
my $output = $self->emitter->writer->output; |
117
|
1190
|
|
|
|
|
2192
|
$self->emitter->finish; |
118
|
1190
|
|
|
|
|
2790
|
return $output; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dump_node { |
122
|
2362
|
|
|
2362
|
|
4078
|
my ($self, $value) = @_; |
123
|
2362
|
|
|
|
|
5227
|
my $node = { |
124
|
|
|
|
|
|
|
value => $value, |
125
|
|
|
|
|
|
|
}; |
126
|
2362
|
100
|
|
|
|
5214
|
if (ref $value) { |
127
|
|
|
|
|
|
|
|
128
|
569
|
|
|
|
|
905
|
my $seen = $self->{seen}; |
129
|
569
|
|
|
|
|
1220
|
my $refaddr = refaddr $value; |
130
|
569
|
100
|
100
|
|
|
2208
|
if ($seen->{ $refaddr } and $seen->{ $refaddr } > 1) { |
131
|
142
|
|
|
|
|
333
|
my $anchor = $self->{anchors}->{ $refaddr }; |
132
|
142
|
100
|
|
|
|
280
|
unless (defined $anchor) { |
133
|
69
|
100
|
|
|
|
134
|
if ($self->representer->preserve_alias) { |
134
|
21
|
100
|
|
|
|
98
|
if (ref $node->{value} eq 'YAML::PP::Preserve::Scalar') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
135
|
7
|
100
|
|
|
|
22
|
if (defined $node->{value}->alias) { |
136
|
5
|
|
|
|
|
13
|
$node->{anchor} = $node->{value}->alias; |
137
|
5
|
|
|
|
|
20
|
$self->{anchors}->{ $refaddr } = $node->{value}->alias; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif (reftype $node->{value} eq 'HASH') { |
141
|
7
|
50
|
|
|
|
12
|
if (my $tied = tied %{ $node->{value} } ) { |
|
7
|
|
|
|
|
29
|
|
142
|
7
|
100
|
|
|
|
19
|
if (defined $tied->{alias}) { |
143
|
5
|
|
|
|
|
13
|
$node->{anchor} = $tied->{alias}; |
144
|
5
|
|
|
|
|
14
|
$self->{anchors}->{ $refaddr } = $node->{anchor}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
elsif (reftype $node->{value} eq 'ARRAY') { |
149
|
7
|
50
|
|
|
|
13
|
if (my $tied = tied @{ $node->{value} } ) { |
|
7
|
|
|
|
|
24
|
|
150
|
7
|
100
|
|
|
|
23
|
if (defined $tied->{alias}) { |
151
|
5
|
|
|
|
|
8
|
$node->{anchor} = $tied->{alias}; |
152
|
5
|
|
|
|
|
13
|
$self->{anchors}->{ $refaddr } = $node->{anchor}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
69
|
100
|
|
|
|
167
|
unless (defined $node->{anchor}) { |
158
|
54
|
|
|
|
|
95
|
my $num = ++$self->{anchor_num}; |
159
|
54
|
|
|
|
|
97
|
$self->{anchors}->{ $refaddr } = $num; |
160
|
54
|
|
|
|
|
104
|
$node->{anchor} = $num; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
73
|
|
|
|
|
116
|
$node->{value} = $anchor; |
165
|
73
|
|
|
|
|
223
|
$self->_emit_node([ alias => $node ]); |
166
|
73
|
|
|
|
|
228
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
2289
|
|
|
|
|
4269
|
$node = $self->representer->represent_node($node); |
172
|
2288
|
|
|
|
|
5628
|
$self->_emit_node($node); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _emit_node { |
176
|
2361
|
|
|
2361
|
|
4714
|
my ($self, $item) = @_; |
177
|
2361
|
|
|
|
|
4748
|
my ($type, $node, %args) = @$item; |
178
|
2361
|
100
|
|
|
|
4906
|
if ($type eq 'alias') { |
179
|
73
|
|
|
|
|
130
|
$self->emitter->alias_event({ value => $node->{value} }); |
180
|
73
|
|
|
|
|
169
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
2288
|
100
|
|
|
|
4495
|
if ($type eq 'mapping') { |
183
|
205
|
|
100
|
|
|
706
|
my $style = $args{style} || YAML_BLOCK_MAPPING_STYLE; |
184
|
|
|
|
|
|
|
# TODO |
185
|
205
|
50
|
66
|
|
|
600
|
if ($node->{items} and @{ $node->{items} } == 0) { |
|
199
|
|
|
|
|
675
|
|
186
|
|
|
|
|
|
|
# $style = YAML_FLOW_MAPPING_STYLE; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
$self->emitter->mapping_start_event({ |
189
|
|
|
|
|
|
|
anchor => $node->{anchor}, |
190
|
|
|
|
|
|
|
style => $style, |
191
|
|
|
|
|
|
|
tag => $node->{tag}, |
192
|
205
|
|
|
|
|
455
|
}); |
193
|
205
|
|
|
|
|
310
|
for (@{ $node->{items} }) { |
|
205
|
|
|
|
|
510
|
|
194
|
834
|
|
|
|
|
1874
|
$self->_dump_node($_); |
195
|
|
|
|
|
|
|
} |
196
|
204
|
|
|
|
|
489
|
$self->emitter->mapping_end_event; |
197
|
204
|
|
|
|
|
1235
|
return; |
198
|
|
|
|
|
|
|
} |
199
|
2083
|
100
|
|
|
|
3873
|
if ($type eq 'sequence') { |
200
|
128
|
|
100
|
|
|
469
|
my $style = $args{style} || YAML_BLOCK_SEQUENCE_STYLE; |
201
|
128
|
100
|
|
|
|
185
|
if (@{ $node->{items} } == 0) { |
|
128
|
|
|
|
|
323
|
|
202
|
|
|
|
|
|
|
# $style = YAML_FLOW_SEQUENCE_STYLE; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
$self->emitter->sequence_start_event({ |
205
|
|
|
|
|
|
|
anchor => $node->{anchor}, |
206
|
|
|
|
|
|
|
style => $style, |
207
|
|
|
|
|
|
|
tag => $node->{tag}, |
208
|
128
|
|
|
|
|
260
|
}); |
209
|
128
|
|
|
|
|
191
|
for (@{ $node->{items} }) { |
|
128
|
|
|
|
|
314
|
|
210
|
304
|
|
|
|
|
676
|
$self->_dump_node($_); |
211
|
|
|
|
|
|
|
} |
212
|
128
|
|
|
|
|
307
|
$self->emitter->sequence_end_event; |
213
|
128
|
|
|
|
|
461
|
return; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
$self->emitter->scalar_event({ |
216
|
|
|
|
|
|
|
value => $node->{items}->[0], |
217
|
|
|
|
|
|
|
style => $node->{style}, |
218
|
|
|
|
|
|
|
anchor => $node->{anchor}, |
219
|
|
|
|
|
|
|
tag => $node->{tag}, |
220
|
1955
|
|
|
|
|
3817
|
}); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub dump_string { |
225
|
1185
|
|
|
1185
|
0
|
3964
|
my ($self, @docs) = @_; |
226
|
1185
|
|
|
|
|
3832
|
my $writer = YAML::PP::Writer->new; |
227
|
1185
|
|
|
|
|
2818
|
$self->emitter->set_writer($writer); |
228
|
1185
|
|
|
|
|
3010
|
my $output = $self->dump(@docs); |
229
|
1184
|
|
|
|
|
3918
|
return $output; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub dump_file { |
233
|
6
|
|
|
6
|
0
|
15
|
my ($self, $file, @docs) = @_; |
234
|
6
|
|
|
|
|
62
|
my $writer = YAML::PP::Writer::File->new(output => $file); |
235
|
6
|
|
|
|
|
19
|
$self->emitter->set_writer($writer); |
236
|
6
|
|
|
|
|
22
|
my $output = $self->dump(@docs); |
237
|
5
|
|
|
|
|
26
|
return $output; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
my %_reftypes = ( |
241
|
|
|
|
|
|
|
HASH => 1, |
242
|
|
|
|
|
|
|
ARRAY => 1, |
243
|
|
|
|
|
|
|
Regexp => 1, |
244
|
|
|
|
|
|
|
REGEXP => 1, |
245
|
|
|
|
|
|
|
CODE => 1, |
246
|
|
|
|
|
|
|
SCALAR => 1, |
247
|
|
|
|
|
|
|
REF => 1, |
248
|
|
|
|
|
|
|
GLOB => 1, |
249
|
|
|
|
|
|
|
); |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub _check_references { |
252
|
1897
|
|
|
1897
|
|
3391
|
my ($self, $doc) = @_; |
253
|
1897
|
100
|
|
|
|
7098
|
my $reftype = reftype $doc or return; |
254
|
501
|
|
|
|
|
807
|
my $seen = $self->{seen}; |
255
|
|
|
|
|
|
|
# check which references are used more than once |
256
|
501
|
100
|
100
|
|
|
1184
|
if ($reftype eq 'SCALAR' and |
257
|
63
|
100
|
|
|
|
309
|
grep { ref $doc eq $_ } @{ $self->representer->schema->bool_class || [] }) { |
|
80
|
|
|
|
|
206
|
|
258
|
|
|
|
|
|
|
# JSON::PP and boolean.pm always return the same reference for booleans |
259
|
|
|
|
|
|
|
# Avoid printing *aliases in those case |
260
|
63
|
50
|
33
|
|
|
247
|
if (ref $doc eq 'boolean' or ref $doc eq 'JSON::PP::Boolean') { |
261
|
63
|
|
|
|
|
122
|
return; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
438
|
100
|
|
|
|
1696
|
if (++$seen->{ refaddr $doc } > 1) { |
265
|
|
|
|
|
|
|
# seen already |
266
|
73
|
|
|
|
|
190
|
return; |
267
|
|
|
|
|
|
|
} |
268
|
365
|
50
|
|
|
|
897
|
unless ($_reftypes{ $reftype }) { |
269
|
0
|
|
|
|
|
0
|
die sprintf "Reference %s not implemented", |
270
|
|
|
|
|
|
|
$reftype; |
271
|
|
|
|
|
|
|
} |
272
|
365
|
100
|
|
|
|
901
|
if ($reftype eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
273
|
203
|
|
|
|
|
807
|
$self->_check_references($doc->{ $_ }) for keys %$doc; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
elsif ($reftype eq 'ARRAY') { |
276
|
124
|
|
|
|
|
362
|
$self->_check_references($_) for @$doc; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
elsif ($reftype eq 'REF') { |
279
|
8
|
|
|
|
|
22
|
$self->_check_references($$doc); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
1; |