| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
44
|
|
|
44
|
|
139181
|
use strict; |
|
|
44
|
|
|
|
|
97
|
|
|
|
44
|
|
|
|
|
1364
|
|
|
2
|
44
|
|
|
44
|
|
142
|
use warnings; |
|
|
44
|
|
|
|
|
115
|
|
|
|
44
|
|
|
|
|
2965
|
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Representer; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 'v0.40.0'; # VERSION |
|
6
|
|
|
|
|
|
|
|
|
7
|
44
|
|
|
44
|
|
205
|
use Scalar::Util qw/ reftype blessed refaddr /; |
|
|
44
|
|
|
|
|
61
|
|
|
|
44
|
|
|
|
|
3135
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
44
|
|
|
|
|
2827
|
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
|
44
|
|
|
44
|
|
599
|
/; |
|
|
44
|
|
|
|
|
70
|
|
|
18
|
44
|
|
|
44
|
|
198
|
use B; |
|
|
44
|
|
|
|
|
65
|
|
|
|
44
|
|
|
|
|
58119
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
755
|
|
|
755
|
0
|
1700
|
my ($class, %args) = @_; |
|
22
|
755
|
|
100
|
|
|
1960
|
my $preserve = delete $args{preserve} || 0; |
|
23
|
755
|
100
|
|
|
|
1364
|
if ($preserve == 1) { |
|
24
|
1
|
|
|
|
|
2
|
$preserve = PRESERVE_ORDER | PRESERVE_SCALAR_STYLE | PRESERVE_FLOW_STYLE | PRESERVE_ALIAS; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
my $self = bless { |
|
27
|
|
|
|
|
|
|
schema => delete $args{schema}, |
|
28
|
755
|
|
|
|
|
1818
|
preserve => $preserve, |
|
29
|
|
|
|
|
|
|
}, $class; |
|
30
|
755
|
50
|
|
|
|
1232
|
if (keys %args) { |
|
31
|
0
|
|
|
|
|
0
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
755
|
|
|
|
|
3814
|
return $self; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub clone { |
|
37
|
9
|
|
|
9
|
0
|
15
|
my ($self) = @_; |
|
38
|
|
|
|
|
|
|
my $clone = { |
|
39
|
|
|
|
|
|
|
schema => $self->schema, |
|
40
|
|
|
|
|
|
|
preserve => $self->{preserve}, |
|
41
|
9
|
|
|
|
|
13
|
}; |
|
42
|
9
|
|
|
|
|
26
|
return bless $clone, ref $self; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
3959
|
|
|
3959
|
0
|
10351
|
sub schema { return $_[0]->{schema} } |
|
46
|
458
|
|
|
458
|
0
|
982
|
sub preserve_order { return $_[0]->{preserve} & PRESERVE_ORDER } |
|
47
|
3817
|
|
|
3817
|
0
|
5383
|
sub preserve_scalar_style { return $_[0]->{preserve} & PRESERVE_SCALAR_STYLE } |
|
48
|
724
|
|
|
724
|
0
|
1892
|
sub preserve_flow_style { return $_[0]->{preserve} & PRESERVE_FLOW_STYLE } |
|
49
|
3888
|
|
|
3888
|
0
|
6445
|
sub preserve_alias { return $_[0]->{preserve} & PRESERVE_ALIAS } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub represent_node { |
|
52
|
3817
|
|
|
3817
|
0
|
5527
|
my ($self, $node) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
3817
|
|
|
|
|
6295
|
my $preserve_alias = $self->preserve_alias; |
|
55
|
3817
|
|
|
|
|
6942
|
my $preserve_style = $self->preserve_scalar_style; |
|
56
|
3817
|
100
|
100
|
|
|
10679
|
if ($preserve_style or $preserve_alias) { |
|
57
|
131
|
100
|
|
|
|
221
|
if (ref $node->{value} eq 'YAML::PP::Preserve::Scalar') { |
|
58
|
87
|
|
|
|
|
204
|
my $value = $node->{value}->value; |
|
59
|
87
|
100
|
|
|
|
150
|
if ($preserve_style) { |
|
60
|
21
|
|
|
|
|
34
|
$node->{style} = $node->{value}->style; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
# $node->{tag} = $node->{value}->tag; |
|
63
|
87
|
|
|
|
|
118
|
$node->{value} = $value; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
3817
|
|
|
|
|
7457
|
$node->{reftype} = reftype($node->{value}); |
|
67
|
3817
|
100
|
100
|
|
|
12380
|
if (not $node->{reftype} and reftype(\$node->{value}) eq 'GLOB') { |
|
68
|
6
|
|
|
|
|
10
|
$node->{reftype} = 'GLOB'; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
3817
|
100
|
|
|
|
7253
|
if ($node->{reftype}) { |
|
72
|
807
|
|
|
|
|
1926
|
$self->_represent_noderef($node); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
else { |
|
75
|
3010
|
|
|
|
|
6670
|
$self->_represent_node_nonref($node); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
3817
|
|
100
|
|
|
11008
|
$node->{reftype} = (reftype $node->{data}) || ''; |
|
78
|
|
|
|
|
|
|
|
|
79
|
3817
|
100
|
100
|
|
|
8189
|
if ($node->{reftype} eq 'HASH' and my $tied = tied(%{ $node->{data} })) { |
|
|
458
|
|
|
|
|
1380
|
|
|
80
|
34
|
|
|
|
|
59
|
my $representers = $self->schema->representers; |
|
81
|
34
|
|
|
|
|
58
|
$tied = ref $tied; |
|
82
|
34
|
50
|
|
|
|
83
|
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
|
|
|
|
9404
|
if ($node->{reftype} eq 'HASH') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
89
|
458
|
50
|
|
|
|
902
|
unless (defined $node->{items}) { |
|
90
|
|
|
|
|
|
|
# by default we sort hash keys |
|
91
|
458
|
|
|
|
|
630
|
my @keys; |
|
92
|
458
|
100
|
|
|
|
903
|
if ($self->preserve_order) { |
|
93
|
24
|
|
|
|
|
26
|
@keys = keys %{ $node->{data} }; |
|
|
24
|
|
|
|
|
73
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
else { |
|
96
|
434
|
|
|
|
|
526
|
@keys = sort keys %{ $node->{data} }; |
|
|
434
|
|
|
|
|
1684
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
458
|
|
|
|
|
981
|
for my $key (@keys) { |
|
99
|
876
|
|
|
|
|
948
|
push @{ $node->{items} }, $key, $node->{data}->{ $key }; |
|
|
876
|
|
|
|
|
2386
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
458
|
|
|
|
|
608
|
my %args; |
|
103
|
458
|
100
|
66
|
|
|
1036
|
if ($self->preserve_flow_style and reftype $node->{value} eq 'HASH') { |
|
104
|
19
|
100
|
|
|
|
21
|
if (my $tied = tied %{ $node->{value} } ) { |
|
|
19
|
|
|
|
|
58
|
|
|
105
|
18
|
|
|
|
|
34
|
$args{style} = $tied->{style}; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
458
|
|
|
|
|
1474
|
return [ mapping => $node, %args ]; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif ($node->{reftype} eq 'ARRAY') { |
|
111
|
266
|
50
|
|
|
|
596
|
unless (defined $node->{items}) { |
|
112
|
266
|
|
|
|
|
313
|
@{ $node->{items} } = @{ $node->{data} }; |
|
|
266
|
|
|
|
|
661
|
|
|
|
266
|
|
|
|
|
487
|
|
|
113
|
|
|
|
|
|
|
} |
|
114
|
266
|
|
|
|
|
391
|
my %args; |
|
115
|
266
|
100
|
66
|
|
|
477
|
if ($self->preserve_flow_style and reftype $node->{value} eq 'ARRAY') { |
|
116
|
10
|
50
|
|
|
|
13
|
if (my $tied = tied @{ $node->{value} } ) { |
|
|
10
|
|
|
|
|
27
|
|
|
117
|
10
|
|
|
|
|
24
|
$args{style} = $tied->{style}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
266
|
|
|
|
|
807
|
return [ sequence => $node, %args ]; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
elsif ($node->{reftype}) { |
|
123
|
1
|
|
|
|
|
12
|
die "Cannot handle reftype '$node->{reftype}' (you might want to enable YAML::PP::Schema::Perl)"; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
else { |
|
126
|
3092
|
100
|
|
|
|
5369
|
unless (defined $node->{items}) { |
|
127
|
3026
|
|
|
|
|
6204
|
$node->{items} = [$node->{data}]; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
3092
|
|
|
|
|
7380
|
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
|
|
5122
|
my ($self, $node) = @_; |
|
145
|
3010
|
|
|
|
|
5262
|
my $representers = $self->schema->representers; |
|
146
|
|
|
|
|
|
|
|
|
147
|
3010
|
100
|
|
|
|
6205
|
if (not defined $node->{value}) { |
|
148
|
110
|
50
|
|
|
|
220
|
if (my $undef = $representers->{undef}) { |
|
149
|
110
|
50
|
|
|
|
289
|
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
|
|
|
9953
|
if ($] >= 5.036000 and my $rep = $representers->{bool}) { |
|
158
|
748
|
|
66
|
15
|
|
2992
|
$is_bool ||= eval $bool_code; |
|
|
15
|
|
|
|
|
7581
|
|
|
|
15
|
|
|
|
|
19828
|
|
|
|
15
|
|
|
|
|
77
|
|
|
159
|
748
|
100
|
|
|
|
18351
|
if ($is_bool->($node->{value})) { |
|
160
|
2
|
|
|
|
|
6
|
return $rep->{code}->($self, $node); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
2898
|
|
|
|
|
3738
|
for my $rep (@{ $representers->{flags} }) { |
|
|
2898
|
|
|
|
|
6148
|
|
|
164
|
4969
|
|
|
|
|
6962
|
my $check_flags = $rep->{flags}; |
|
165
|
4969
|
|
|
|
|
14814
|
my $flags = B::svref_2object(\$node->{value})->FLAGS; |
|
166
|
4969
|
100
|
|
|
|
10886
|
if ($flags & $check_flags) { |
|
167
|
517
|
100
|
|
|
|
1535
|
return 1 if $rep->{code}->($self, $node); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
|
171
|
2392
|
100
|
|
|
|
6701
|
if (my $rep = $representers->{equals}->{ $node->{value} }) { |
|
172
|
138
|
50
|
|
|
|
508
|
return 1 if $rep->{code}->($self, $node); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
2254
|
|
|
|
|
2875
|
for my $rep (@{ $representers->{regex} }) { |
|
|
2254
|
|
|
|
|
3784
|
|
|
175
|
2050
|
100
|
|
|
|
17912
|
if ($node->{value} =~ $rep->{regex}) { |
|
176
|
101
|
100
|
|
|
|
401
|
return 1 if $rep->{code}->($self, $node); |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
2159
|
50
|
|
|
|
4538
|
unless (defined $node->{data}) { |
|
180
|
2159
|
|
|
|
|
3998
|
$node->{data} = $node->{value}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
2159
|
100
|
|
|
|
3861
|
unless (defined $node->{style}) { |
|
183
|
2143
|
|
|
|
|
3092
|
$node->{style} = YAML_ANY_SCALAR_STYLE; |
|
184
|
2143
|
|
|
|
|
4077
|
$node->{style} = ""; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub _represent_noderef { |
|
189
|
807
|
|
|
807
|
|
1173
|
my ($self, $node) = @_; |
|
190
|
807
|
|
|
|
|
1508
|
my $representers = $self->schema->representers; |
|
191
|
|
|
|
|
|
|
|
|
192
|
807
|
100
|
|
|
|
2034
|
if (my $classname = blessed($node->{value})) { |
|
193
|
112
|
100
|
|
|
|
298
|
if (my $def = $representers->{class_equals}->{ $classname }) { |
|
194
|
66
|
|
|
|
|
98
|
my $code = $def->{code}; |
|
195
|
66
|
50
|
|
|
|
176
|
return 1 if $code->($self, $node); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
46
|
|
|
|
|
91
|
for my $matches (@{ $representers->{class_matches} }) { |
|
|
46
|
|
|
|
|
109
|
|
|
198
|
43
|
|
|
|
|
96
|
my ($re, $code) = @$matches; |
|
199
|
43
|
50
|
33
|
|
|
192
|
if (ref $re and $classname =~ $re or $re) { |
|
|
|
|
33
|
|
|
|
|
|
200
|
43
|
100
|
|
|
|
133
|
return 1 if $code->($self, $node); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
} |
|
203
|
4
|
|
|
|
|
5
|
for my $isa (@{ $representers->{class_isa} }) { |
|
|
4
|
|
|
|
|
8
|
|
|
204
|
3
|
|
|
|
|
5
|
my ($class_name, $code) = @$isa; |
|
205
|
3
|
100
|
|
|
|
17
|
if ($node->{ value }->isa($class_name)) { |
|
206
|
2
|
50
|
|
|
|
6
|
return 1 if $code->($self, $node); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
} |
|
210
|
697
|
100
|
100
|
|
|
1594
|
if ($node->{reftype} eq 'SCALAR' and my $scalarref = $representers->{scalarref}) { |
|
211
|
4
|
|
|
|
|
10
|
my $code = $scalarref->{code}; |
|
212
|
4
|
50
|
|
|
|
18
|
return 1 if $code->($self, $node); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
693
|
100
|
66
|
|
|
1440
|
if ($node->{reftype} eq 'REF' and my $refref = $representers->{refref}) { |
|
215
|
4
|
|
|
|
|
9
|
my $code = $refref->{code}; |
|
216
|
4
|
50
|
|
|
|
14
|
return 1 if $code->($self, $node); |
|
217
|
|
|
|
|
|
|
} |
|
218
|
689
|
100
|
66
|
|
|
1702
|
if ($node->{reftype} eq 'CODE' and my $coderef = $representers->{coderef}) { |
|
219
|
5
|
|
|
|
|
11
|
my $code = $coderef->{code}; |
|
220
|
5
|
50
|
|
|
|
21
|
return 1 if $code->($self, $node); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
684
|
100
|
66
|
|
|
1400
|
if ($node->{reftype} eq 'GLOB' and my $glob = $representers->{glob}) { |
|
223
|
6
|
|
|
|
|
12
|
my $code = $glob->{code}; |
|
224
|
6
|
50
|
|
|
|
18
|
return 1 if $code->($self, $node); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
678
|
|
|
|
|
1344
|
$node->{data} = $node->{value}; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1; |