line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
35
|
|
|
35
|
|
138352
|
use strict; |
|
35
|
|
|
|
|
89
|
|
|
35
|
|
|
|
|
1072
|
|
2
|
35
|
|
|
35
|
|
174
|
use warnings; |
|
35
|
|
|
|
|
73
|
|
|
35
|
|
|
|
|
1841
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Dumper; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.036_001'; # TRIAL VERSION |
6
|
|
|
|
|
|
|
|
7
|
35
|
|
|
35
|
|
224
|
use Scalar::Util qw/ blessed refaddr reftype /; |
|
35
|
|
|
|
|
92
|
|
|
35
|
|
|
|
|
1813
|
|
8
|
35
|
|
|
35
|
|
1205
|
use YAML::PP; |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
912
|
|
9
|
35
|
|
|
35
|
|
17609
|
use YAML::PP::Emitter; |
|
35
|
|
|
|
|
104
|
|
|
35
|
|
|
|
|
1219
|
|
10
|
35
|
|
|
35
|
|
15280
|
use YAML::PP::Representer; |
|
35
|
|
|
|
|
104
|
|
|
35
|
|
|
|
|
1054
|
|
11
|
35
|
|
|
35
|
|
13746
|
use YAML::PP::Writer; |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
1015
|
|
12
|
35
|
|
|
35
|
|
13890
|
use YAML::PP::Writer::File; |
|
35
|
|
|
|
|
97
|
|
|
35
|
|
|
|
|
1261
|
|
13
|
35
|
|
|
|
|
60664
|
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
|
|
236
|
/; |
|
35
|
|
|
|
|
85
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
746
|
|
|
746
|
0
|
3143
|
my ($class, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
746
|
|
|
|
|
1377
|
my $header = delete $args{header}; |
26
|
746
|
100
|
|
|
|
1701
|
$header = 1 unless defined $header; |
27
|
746
|
|
|
|
|
1195
|
my $footer = delete $args{footer}; |
28
|
746
|
100
|
|
|
|
1512
|
$footer = 0 unless defined $footer; |
29
|
746
|
|
|
|
|
1230
|
my $version_directive = delete $args{version_directive}; |
30
|
746
|
|
|
|
|
1183
|
my $preserve = delete $args{preserve}; |
31
|
|
|
|
|
|
|
|
32
|
746
|
|
66
|
|
|
1853
|
my $schema = delete $args{schema} || YAML::PP->default_schema( |
33
|
|
|
|
|
|
|
boolean => 'perl', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
746
|
|
66
|
|
|
1644
|
my $emitter = delete $args{emitter} || YAML::PP::Emitter->new; |
37
|
746
|
100
|
|
|
|
2391
|
unless (blessed($emitter)) { |
38
|
745
|
|
|
|
|
3624
|
$emitter = YAML::PP::Emitter->new( |
39
|
|
|
|
|
|
|
%$emitter |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
746
|
50
|
|
|
|
1922
|
if (keys %args) { |
44
|
0
|
|
|
|
|
0
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
45
|
|
|
|
|
|
|
} |
46
|
746
|
|
|
|
|
2634
|
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
|
746
|
|
|
|
|
2089
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clone { |
63
|
9
|
|
|
9
|
0
|
16
|
my ($self) = @_; |
64
|
9
|
|
|
|
|
18
|
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
|
1542
|
|
|
1542
|
0
|
2600
|
my ($self) = @_; |
79
|
1542
|
|
|
|
|
3341
|
$self->{seen} = {}; |
80
|
1542
|
|
|
|
|
3325
|
$self->{anchors} = {}; |
81
|
1542
|
|
|
|
|
2587
|
$self->{anchor_num} = 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
16587
|
|
|
16587
|
0
|
57295
|
sub emitter { return $_[0]->{emitter} } |
85
|
3983
|
|
|
3983
|
0
|
11150
|
sub representer { return $_[0]->{representer} } |
86
|
0
|
|
|
0
|
0
|
0
|
sub set_representer { $_[0]->{representer} = $_[1] } |
87
|
1487
|
|
|
1487
|
0
|
4722
|
sub header { return $_[0]->{header} } |
88
|
1550
|
|
|
1550
|
0
|
3323
|
sub footer { return $_[0]->{footer} } |
89
|
1551
|
|
|
1551
|
0
|
3255
|
sub version_directive { return $_[0]->{version_directive} } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub dump { |
92
|
1484
|
|
|
1484
|
0
|
3089
|
my ($self, @docs) = @_; |
93
|
1484
|
|
|
|
|
2671
|
$self->emitter->init; |
94
|
|
|
|
|
|
|
|
95
|
1483
|
|
|
|
|
2850
|
$self->emitter->stream_start_event({}); |
96
|
|
|
|
|
|
|
|
97
|
1483
|
|
|
|
|
4850
|
for my $i (0 .. $#docs) { |
98
|
1542
|
|
100
|
|
|
5066
|
my $header_implicit = ($i == 0 and not $self->header); |
99
|
1542
|
|
|
|
|
4872
|
my %args = ( |
100
|
|
|
|
|
|
|
implicit => $header_implicit, |
101
|
|
|
|
|
|
|
); |
102
|
1542
|
100
|
|
|
|
3387
|
if ($self->version_directive) { |
103
|
18
|
|
|
|
|
39
|
my ($major, $minor) = split m/\./, $self->representer->schema->yaml_version; |
104
|
18
|
|
|
|
|
80
|
$args{version_directive} = { major => $major, minor => $minor }; |
105
|
|
|
|
|
|
|
} |
106
|
1542
|
|
|
|
|
2855
|
$self->emitter->document_start_event( \%args ); |
107
|
1542
|
|
|
|
|
4037
|
$self->init; |
108
|
1542
|
|
|
|
|
4703
|
$self->_check_references($docs[ $i ]); |
109
|
1542
|
|
|
|
|
4450
|
$self->_dump_node($docs[ $i ]); |
110
|
1541
|
|
|
|
|
4313
|
my $footer_implicit = (not $self->footer); |
111
|
1541
|
|
|
|
|
2948
|
$self->emitter->document_end_event({ implicit => $footer_implicit }); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
1482
|
|
|
|
|
3012
|
$self->emitter->stream_end_event({}); |
115
|
|
|
|
|
|
|
|
116
|
1482
|
|
|
|
|
3002
|
my $output = $self->emitter->writer->output; |
117
|
1482
|
|
|
|
|
3009
|
$self->emitter->finish; |
118
|
1482
|
|
|
|
|
3641
|
return $output; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dump_node { |
122
|
3880
|
|
|
3880
|
|
6936
|
my ($self, $value) = @_; |
123
|
3880
|
|
|
|
|
8605
|
my $node = { |
124
|
|
|
|
|
|
|
value => $value, |
125
|
|
|
|
|
|
|
}; |
126
|
3880
|
100
|
|
|
|
8594
|
if (ref $value) { |
127
|
|
|
|
|
|
|
|
128
|
961
|
|
|
|
|
1755
|
my $seen = $self->{seen}; |
129
|
961
|
|
|
|
|
2012
|
my $refaddr = refaddr $value; |
130
|
961
|
100
|
100
|
|
|
4100
|
if ($seen->{ $refaddr } and $seen->{ $refaddr } > 1) { |
131
|
147
|
|
|
|
|
293
|
my $anchor = $self->{anchors}->{ $refaddr }; |
132
|
147
|
100
|
|
|
|
277
|
unless (defined $anchor) { |
133
|
71
|
100
|
|
|
|
161
|
if ($self->representer->preserve_alias) { |
134
|
21
|
100
|
|
|
|
82
|
if (ref $node->{value} eq 'YAML::PP::Preserve::Scalar') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
135
|
7
|
100
|
|
|
|
21
|
if (defined $node->{value}->alias) { |
136
|
5
|
|
|
|
|
15
|
$node->{anchor} = $node->{value}->alias; |
137
|
5
|
|
|
|
|
12
|
$self->{anchors}->{ $refaddr } = $node->{value}->alias; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif (reftype $node->{value} eq 'HASH') { |
141
|
7
|
50
|
|
|
|
14
|
if (my $tied = tied %{ $node->{value} } ) { |
|
7
|
|
|
|
|
21
|
|
142
|
7
|
100
|
|
|
|
19
|
if (defined $tied->{alias}) { |
143
|
5
|
|
|
|
|
10
|
$node->{anchor} = $tied->{alias}; |
144
|
5
|
|
|
|
|
12
|
$self->{anchors}->{ $refaddr } = $node->{anchor}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
elsif (reftype $node->{value} eq 'ARRAY') { |
149
|
7
|
50
|
|
|
|
9
|
if (my $tied = tied @{ $node->{value} } ) { |
|
7
|
|
|
|
|
22
|
|
150
|
7
|
100
|
|
|
|
20
|
if (defined $tied->{alias}) { |
151
|
5
|
|
|
|
|
11
|
$node->{anchor} = $tied->{alias}; |
152
|
5
|
|
|
|
|
11
|
$self->{anchors}->{ $refaddr } = $node->{anchor}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
71
|
100
|
|
|
|
181
|
unless (defined $node->{anchor}) { |
158
|
56
|
|
|
|
|
89
|
my $num = ++$self->{anchor_num}; |
159
|
56
|
|
|
|
|
112
|
$self->{anchors}->{ $refaddr } = $num; |
160
|
56
|
|
|
|
|
154
|
$node->{anchor} = $num; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
76
|
|
|
|
|
147
|
$node->{value} = $anchor; |
165
|
76
|
|
|
|
|
235
|
$self->_emit_node([ alias => $node ]); |
166
|
76
|
|
|
|
|
222
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
3804
|
|
|
|
|
7240
|
$node = $self->representer->represent_node($node); |
172
|
3803
|
|
|
|
|
9417
|
$self->_emit_node($node); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _emit_node { |
176
|
3879
|
|
|
3879
|
|
7266
|
my ($self, $item) = @_; |
177
|
3879
|
|
|
|
|
7432
|
my ($type, $node, %args) = @$item; |
178
|
3879
|
100
|
|
|
|
7862
|
if ($type eq 'alias') { |
179
|
76
|
|
|
|
|
160
|
$self->emitter->alias_event({ value => $node->{value} }); |
180
|
76
|
|
|
|
|
185
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
3803
|
100
|
|
|
|
6919
|
if ($type eq 'mapping') { |
183
|
455
|
|
100
|
|
|
1648
|
my $style = $args{style} || YAML_BLOCK_MAPPING_STYLE; |
184
|
|
|
|
|
|
|
# TODO |
185
|
455
|
50
|
66
|
|
|
1204
|
if ($node->{items} and @{ $node->{items} } == 0) { |
|
446
|
|
|
|
|
1352
|
|
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
|
455
|
|
|
|
|
963
|
}); |
193
|
455
|
|
|
|
|
710
|
for (@{ $node->{items} }) { |
|
455
|
|
|
|
|
1088
|
|
194
|
1742
|
|
|
|
|
3882
|
$self->_dump_node($_); |
195
|
|
|
|
|
|
|
} |
196
|
454
|
|
|
|
|
1096
|
$self->emitter->mapping_end_event; |
197
|
454
|
|
|
|
|
1792
|
return; |
198
|
|
|
|
|
|
|
} |
199
|
3348
|
100
|
|
|
|
6605
|
if ($type eq 'sequence') { |
200
|
266
|
|
100
|
|
|
981
|
my $style = $args{style} || YAML_BLOCK_SEQUENCE_STYLE; |
201
|
266
|
100
|
|
|
|
372
|
if (@{ $node->{items} } == 0) { |
|
266
|
|
|
|
|
683
|
|
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
|
266
|
|
|
|
|
554
|
}); |
209
|
266
|
|
|
|
|
411
|
for (@{ $node->{items} }) { |
|
266
|
|
|
|
|
760
|
|
210
|
596
|
|
|
|
|
1375
|
$self->_dump_node($_); |
211
|
|
|
|
|
|
|
} |
212
|
266
|
|
|
|
|
816
|
$self->emitter->sequence_end_event; |
213
|
266
|
|
|
|
|
1010
|
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
|
3082
|
|
|
|
|
6189
|
}); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub dump_string { |
225
|
1477
|
|
|
1477
|
0
|
3792
|
my ($self, @docs) = @_; |
226
|
1477
|
|
|
|
|
4673
|
my $writer = YAML::PP::Writer->new; |
227
|
1477
|
|
|
|
|
3663
|
$self->emitter->set_writer($writer); |
228
|
1477
|
|
|
|
|
3688
|
my $output = $self->dump(@docs); |
229
|
1476
|
|
|
|
|
5299
|
return $output; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub dump_file { |
233
|
6
|
|
|
6
|
0
|
17
|
my ($self, $file, @docs) = @_; |
234
|
6
|
|
|
|
|
36
|
my $writer = YAML::PP::Writer::File->new(output => $file); |
235
|
6
|
|
|
|
|
16
|
$self->emitter->set_writer($writer); |
236
|
6
|
|
|
|
|
18
|
my $output = $self->dump(@docs); |
237
|
5
|
|
|
|
|
20
|
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
|
2961
|
|
|
2961
|
|
5460
|
my ($self, $doc) = @_; |
253
|
2961
|
100
|
|
|
|
10489
|
my $reftype = reftype $doc or return; |
254
|
893
|
|
|
|
|
1429
|
my $seen = $self->{seen}; |
255
|
|
|
|
|
|
|
# check which references are used more than once |
256
|
893
|
100
|
100
|
|
|
2108
|
if ($reftype eq 'SCALAR' and |
257
|
64
|
100
|
|
|
|
304
|
grep { ref $doc eq $_ } @{ $self->representer->schema->bool_class || [] }) { |
|
81
|
|
|
|
|
168
|
|
258
|
|
|
|
|
|
|
# JSON::PP and boolean.pm always return the same reference for booleans |
259
|
|
|
|
|
|
|
# Avoid printing *aliases in those case |
260
|
64
|
50
|
33
|
|
|
258
|
if (ref $doc eq 'boolean' or ref $doc eq 'JSON::PP::Boolean') { |
261
|
64
|
|
|
|
|
135
|
return; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
829
|
100
|
|
|
|
3335
|
if (++$seen->{ refaddr $doc } > 1) { |
265
|
|
|
|
|
|
|
# seen already |
266
|
76
|
|
|
|
|
195
|
return; |
267
|
|
|
|
|
|
|
} |
268
|
753
|
50
|
|
|
|
1847
|
unless ($_reftypes{ $reftype }) { |
269
|
0
|
|
|
|
|
0
|
die sprintf "Reference %s not implemented", |
270
|
|
|
|
|
|
|
$reftype; |
271
|
|
|
|
|
|
|
} |
272
|
753
|
100
|
|
|
|
1776
|
if ($reftype eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
273
|
453
|
|
|
|
|
1970
|
$self->_check_references($doc->{ $_ }) for keys %$doc; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
elsif ($reftype eq 'ARRAY') { |
276
|
262
|
|
|
|
|
778
|
$self->_check_references($_) for @$doc; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
elsif ($reftype eq 'REF') { |
279
|
8
|
|
|
|
|
23
|
$self->_check_references($$doc); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
1; |