| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
49
|
|
|
49
|
|
138361
|
use strict; |
|
|
49
|
|
|
|
|
102
|
|
|
|
49
|
|
|
|
|
1514
|
|
|
2
|
49
|
|
|
49
|
|
170
|
use warnings; |
|
|
49
|
|
|
|
|
67
|
|
|
|
49
|
|
|
|
|
3340
|
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Representer; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 'v0.41.0'; # VERSION |
|
6
|
|
|
|
|
|
|
|
|
7
|
49
|
|
|
49
|
|
213
|
use Scalar::Util qw/ reftype blessed refaddr /; |
|
|
49
|
|
|
|
|
67
|
|
|
|
49
|
|
|
|
|
3688
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
49
|
|
|
|
|
3232
|
use YAML::PP::Common qw/ |
|
10
|
|
|
|
|
|
|
YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE |
|
11
|
|
|
|
|
|
|
YAML_DOUBLE_QUOTED_SCALAR_STYLE |
|
12
|
|
|
|
|
|
|
YAML_ANY_SCALAR_STYLE |
|
13
|
|
|
|
|
|
|
YAML_LITERAL_SCALAR_STYLE YAML_FOLDED_SCALAR_STYLE |
|
14
|
|
|
|
|
|
|
YAML_FLOW_SEQUENCE_STYLE YAML_FLOW_MAPPING_STYLE |
|
15
|
|
|
|
|
|
|
YAML_BLOCK_MAPPING_STYLE YAML_BLOCK_SEQUENCE_STYLE |
|
16
|
|
|
|
|
|
|
PRESERVE_ORDER PRESERVE_SCALAR_STYLE PRESERVE_FLOW_STYLE PRESERVE_ALIAS |
|
17
|
49
|
|
|
49
|
|
745
|
/; |
|
|
49
|
|
|
|
|
68
|
|
|
18
|
49
|
|
|
49
|
|
240
|
use B; |
|
|
49
|
|
|
|
|
112
|
|
|
|
49
|
|
|
|
|
66912
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
764
|
|
|
764
|
0
|
1535
|
my ($class, %args) = @_; |
|
22
|
764
|
|
100
|
|
|
2111
|
my $preserve = delete $args{preserve} || 0; |
|
23
|
764
|
100
|
|
|
|
1379
|
if ($preserve == 1) { |
|
24
|
1
|
|
|
|
|
3
|
$preserve = PRESERVE_ORDER | PRESERVE_SCALAR_STYLE | PRESERVE_FLOW_STYLE | PRESERVE_ALIAS; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
my $self = bless { |
|
27
|
|
|
|
|
|
|
schema => delete $args{schema}, |
|
28
|
764
|
|
|
|
|
1694
|
preserve => $preserve, |
|
29
|
|
|
|
|
|
|
}, $class; |
|
30
|
764
|
50
|
|
|
|
1261
|
if (keys %args) { |
|
31
|
0
|
|
|
|
|
0
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
764
|
|
|
|
|
3757
|
return $self; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub clone { |
|
37
|
9
|
|
|
9
|
0
|
12
|
my ($self) = @_; |
|
38
|
|
|
|
|
|
|
my $clone = { |
|
39
|
|
|
|
|
|
|
schema => $self->schema, |
|
40
|
|
|
|
|
|
|
preserve => $self->{preserve}, |
|
41
|
9
|
|
|
|
|
16
|
}; |
|
42
|
9
|
|
|
|
|
28
|
return bless $clone, ref $self; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
3959
|
|
|
3959
|
0
|
11874
|
sub schema { return $_[0]->{schema} } |
|
46
|
458
|
|
|
458
|
0
|
949
|
sub preserve_order { return $_[0]->{preserve} & PRESERVE_ORDER } |
|
47
|
3817
|
|
|
3817
|
0
|
5207
|
sub preserve_scalar_style { return $_[0]->{preserve} & PRESERVE_SCALAR_STYLE } |
|
48
|
724
|
|
|
724
|
0
|
1730
|
sub preserve_flow_style { return $_[0]->{preserve} & PRESERVE_FLOW_STYLE } |
|
49
|
3888
|
|
|
3888
|
0
|
6719
|
sub preserve_alias { return $_[0]->{preserve} & PRESERVE_ALIAS } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub represent_node { |
|
52
|
3817
|
|
|
3817
|
0
|
5569
|
my ($self, $node) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
3817
|
|
|
|
|
6200
|
my $preserve_alias = $self->preserve_alias; |
|
55
|
3817
|
|
|
|
|
6441
|
my $preserve_style = $self->preserve_scalar_style; |
|
56
|
3817
|
100
|
100
|
|
|
11045
|
if ($preserve_style or $preserve_alias) { |
|
57
|
131
|
100
|
|
|
|
274
|
if (ref $node->{value} eq 'YAML::PP::Preserve::Scalar') { |
|
58
|
87
|
|
|
|
|
164
|
my $value = $node->{value}->value; |
|
59
|
87
|
100
|
|
|
|
139
|
if ($preserve_style) { |
|
60
|
21
|
|
|
|
|
36
|
$node->{style} = $node->{value}->style; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
# $node->{tag} = $node->{value}->tag; |
|
63
|
87
|
|
|
|
|
114
|
$node->{value} = $value; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
3817
|
|
|
|
|
7523
|
$node->{reftype} = reftype($node->{value}); |
|
67
|
3817
|
100
|
100
|
|
|
12328
|
if (not $node->{reftype} and reftype(\$node->{value}) eq 'GLOB') { |
|
68
|
6
|
|
|
|
|
11
|
$node->{reftype} = 'GLOB'; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
3817
|
100
|
|
|
|
6427
|
if ($node->{reftype}) { |
|
72
|
807
|
|
|
|
|
1835
|
$self->_represent_noderef($node); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
else { |
|
75
|
3010
|
|
|
|
|
6210
|
$self->_represent_node_nonref($node); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
3817
|
|
100
|
|
|
10568
|
$node->{reftype} = (reftype $node->{data}) || ''; |
|
78
|
|
|
|
|
|
|
|
|
79
|
3817
|
100
|
100
|
|
|
7728
|
if ($node->{reftype} eq 'HASH' and my $tied = tied(%{ $node->{data} })) { |
|
|
458
|
|
|
|
|
1370
|
|
|
80
|
34
|
|
|
|
|
44
|
my $representers = $self->schema->representers; |
|
81
|
34
|
|
|
|
|
47
|
$tied = ref $tied; |
|
82
|
34
|
50
|
|
|
|
75
|
if (my $def = $representers->{tied_equals}->{ $tied }) { |
|
83
|
0
|
|
|
|
|
0
|
my $code = $def->{code}; |
|
84
|
0
|
|
|
|
|
0
|
my $done = $code->($self, $node); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
3817
|
100
|
|
|
|
9313
|
if ($node->{reftype} eq 'HASH') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
89
|
458
|
50
|
|
|
|
900
|
unless (defined $node->{items}) { |
|
90
|
|
|
|
|
|
|
# by default we sort hash keys |
|
91
|
458
|
|
|
|
|
535
|
my @keys; |
|
92
|
458
|
100
|
|
|
|
789
|
if ($self->preserve_order) { |
|
93
|
24
|
|
|
|
|
28
|
@keys = keys %{ $node->{data} }; |
|
|
24
|
|
|
|
|
75
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
else { |
|
96
|
434
|
|
|
|
|
587
|
@keys = sort keys %{ $node->{data} }; |
|
|
434
|
|
|
|
|
1681
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
458
|
|
|
|
|
913
|
for my $key (@keys) { |
|
99
|
876
|
|
|
|
|
853
|
push @{ $node->{items} }, $key, $node->{data}->{ $key }; |
|
|
876
|
|
|
|
|
2355
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
458
|
|
|
|
|
600
|
my %args; |
|
103
|
458
|
100
|
66
|
|
|
819
|
if ($self->preserve_flow_style and reftype $node->{value} eq 'HASH') { |
|
104
|
19
|
100
|
|
|
|
20
|
if (my $tied = tied %{ $node->{value} } ) { |
|
|
19
|
|
|
|
|
38
|
|
|
105
|
18
|
|
|
|
|
32
|
$args{style} = $tied->{style}; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
458
|
|
|
|
|
1468
|
return [ mapping => $node, %args ]; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif ($node->{reftype} eq 'ARRAY') { |
|
111
|
266
|
50
|
|
|
|
530
|
unless (defined $node->{items}) { |
|
112
|
266
|
|
|
|
|
304
|
@{ $node->{items} } = @{ $node->{data} }; |
|
|
266
|
|
|
|
|
660
|
|
|
|
266
|
|
|
|
|
497
|
|
|
113
|
|
|
|
|
|
|
} |
|
114
|
266
|
|
|
|
|
453
|
my %args; |
|
115
|
266
|
100
|
66
|
|
|
464
|
if ($self->preserve_flow_style and reftype $node->{value} eq 'ARRAY') { |
|
116
|
10
|
50
|
|
|
|
12
|
if (my $tied = tied @{ $node->{value} } ) { |
|
|
10
|
|
|
|
|
26
|
|
|
117
|
10
|
|
|
|
|
21
|
$args{style} = $tied->{style}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
266
|
|
|
|
|
757
|
return [ sequence => $node, %args ]; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
elsif ($node->{reftype}) { |
|
123
|
1
|
|
|
|
|
13
|
die "Cannot handle reftype '$node->{reftype}' (you might want to enable YAML::PP::Schema::Perl)"; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
else { |
|
126
|
3092
|
100
|
|
|
|
5010
|
unless (defined $node->{items}) { |
|
127
|
3026
|
|
|
|
|
5922
|
$node->{items} = [$node->{data}]; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
3092
|
|
|
|
|
7323
|
return [ scalar => $node ]; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $bool_code = <<'EOM'; |
|
135
|
|
|
|
|
|
|
sub { |
|
136
|
|
|
|
|
|
|
my ($x) = @_; |
|
137
|
|
|
|
|
|
|
use experimental qw/ builtin /; |
|
138
|
|
|
|
|
|
|
builtin::is_bool($x); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
EOM |
|
141
|
|
|
|
|
|
|
my $is_bool; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _represent_node_nonref { |
|
144
|
3010
|
|
|
3010
|
|
4276
|
my ($self, $node) = @_; |
|
145
|
3010
|
|
|
|
|
4835
|
my $representers = $self->schema->representers; |
|
146
|
|
|
|
|
|
|
|
|
147
|
3010
|
100
|
|
|
|
5844
|
if (not defined $node->{value}) { |
|
148
|
110
|
50
|
|
|
|
281
|
if (my $undef = $representers->{undef}) { |
|
149
|
110
|
50
|
|
|
|
292
|
return 1 if $undef->($self, $node); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
else { |
|
152
|
0
|
|
|
|
|
0
|
$node->{style} = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
|
153
|
0
|
|
|
|
|
0
|
$node->{data} = ''; |
|
154
|
0
|
|
|
|
|
0
|
return 1; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
2900
|
100
|
66
|
|
|
9951
|
if ($] >= 5.036000 and my $rep = $representers->{bool}) { |
|
158
|
748
|
|
66
|
15
|
|
2816
|
$is_bool ||= eval $bool_code; |
|
|
15
|
|
|
|
|
7145
|
|
|
|
15
|
|
|
|
|
22229
|
|
|
|
15
|
|
|
|
|
77
|
|
|
159
|
748
|
100
|
|
|
|
16121
|
if ($is_bool->($node->{value})) { |
|
160
|
2
|
|
|
|
|
11
|
return $rep->{code}->($self, $node); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
2898
|
|
|
|
|
4022
|
for my $rep (@{ $representers->{flags} }) { |
|
|
2898
|
|
|
|
|
5861
|
|
|
164
|
4969
|
|
|
|
|
6980
|
my $check_flags = $rep->{flags}; |
|
165
|
4969
|
|
|
|
|
14315
|
my $flags = B::svref_2object(\$node->{value})->FLAGS; |
|
166
|
4969
|
100
|
|
|
|
10233
|
if ($flags & $check_flags) { |
|
167
|
517
|
100
|
|
|
|
1620
|
return 1 if $rep->{code}->($self, $node); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
|
171
|
2392
|
100
|
|
|
|
6773
|
if (my $rep = $representers->{equals}->{ $node->{value} }) { |
|
172
|
138
|
50
|
|
|
|
518
|
return 1 if $rep->{code}->($self, $node); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
2254
|
|
|
|
|
2651
|
for my $rep (@{ $representers->{regex} }) { |
|
|
2254
|
|
|
|
|
3704
|
|
|
175
|
2050
|
100
|
|
|
|
17114
|
if ($node->{value} =~ $rep->{regex}) { |
|
176
|
101
|
100
|
|
|
|
436
|
return 1 if $rep->{code}->($self, $node); |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
2159
|
50
|
|
|
|
4721
|
unless (defined $node->{data}) { |
|
180
|
2159
|
|
|
|
|
3803
|
$node->{data} = $node->{value}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
2159
|
100
|
|
|
|
3803
|
unless (defined $node->{style}) { |
|
183
|
2143
|
|
|
|
|
3011
|
$node->{style} = YAML_ANY_SCALAR_STYLE; |
|
184
|
2143
|
|
|
|
|
3899
|
$node->{style} = ""; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub _represent_noderef { |
|
189
|
807
|
|
|
807
|
|
1157
|
my ($self, $node) = @_; |
|
190
|
807
|
|
|
|
|
1413
|
my $representers = $self->schema->representers; |
|
191
|
|
|
|
|
|
|
|
|
192
|
807
|
100
|
|
|
|
1973
|
if (my $classname = blessed($node->{value})) { |
|
193
|
112
|
100
|
|
|
|
333
|
if (my $def = $representers->{class_equals}->{ $classname }) { |
|
194
|
66
|
|
|
|
|
123
|
my $code = $def->{code}; |
|
195
|
66
|
50
|
|
|
|
226
|
return 1 if $code->($self, $node); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
46
|
|
|
|
|
71
|
for my $matches (@{ $representers->{class_matches} }) { |
|
|
46
|
|
|
|
|
88
|
|
|
198
|
43
|
|
|
|
|
86
|
my ($re, $code) = @$matches; |
|
199
|
43
|
50
|
33
|
|
|
136
|
if (ref $re and $classname =~ $re or $re) { |
|
|
|
|
33
|
|
|
|
|
|
200
|
43
|
100
|
|
|
|
156
|
return 1 if $code->($self, $node); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
} |
|
203
|
4
|
|
|
|
|
13
|
for my $isa (@{ $representers->{class_isa} }) { |
|
|
4
|
|
|
|
|
7
|
|
|
204
|
3
|
|
|
|
|
5
|
my ($class_name, $code) = @$isa; |
|
205
|
3
|
100
|
|
|
|
15
|
if ($node->{ value }->isa($class_name)) { |
|
206
|
2
|
50
|
|
|
|
5
|
return 1 if $code->($self, $node); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
} |
|
210
|
697
|
100
|
100
|
|
|
1561
|
if ($node->{reftype} eq 'SCALAR' and my $scalarref = $representers->{scalarref}) { |
|
211
|
4
|
|
|
|
|
9
|
my $code = $scalarref->{code}; |
|
212
|
4
|
50
|
|
|
|
14
|
return 1 if $code->($self, $node); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
693
|
100
|
66
|
|
|
1586
|
if ($node->{reftype} eq 'REF' and my $refref = $representers->{refref}) { |
|
215
|
4
|
|
|
|
|
6
|
my $code = $refref->{code}; |
|
216
|
4
|
50
|
|
|
|
13
|
return 1 if $code->($self, $node); |
|
217
|
|
|
|
|
|
|
} |
|
218
|
689
|
100
|
66
|
|
|
1540
|
if ($node->{reftype} eq 'CODE' and my $coderef = $representers->{coderef}) { |
|
219
|
5
|
|
|
|
|
11
|
my $code = $coderef->{code}; |
|
220
|
5
|
50
|
|
|
|
19
|
return 1 if $code->($self, $node); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
684
|
100
|
66
|
|
|
1465
|
if ($node->{reftype} eq 'GLOB' and my $glob = $representers->{glob}) { |
|
223
|
6
|
|
|
|
|
13
|
my $code = $glob->{code}; |
|
224
|
6
|
50
|
|
|
|
22
|
return 1 if $code->($self, $node); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
678
|
|
|
|
|
1304
|
$node->{data} = $node->{value}; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1; |