line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YAML::Perl::Representer; |
2
|
4
|
|
|
4
|
|
664
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
158
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
117
|
|
4
|
4
|
|
|
4
|
|
22
|
use overload(); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
74
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1699
|
use YAML::Perl::Error; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
20
|
|
7
|
4
|
|
|
4
|
|
1594
|
use YAML::Perl::Nodes; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
183
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package YAML::Perl::Error::Representer; |
10
|
4
|
|
|
4
|
|
24
|
use YAML::Perl::Error::Marked -base; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
44
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package YAML::Perl::Representer; |
13
|
4
|
|
|
4
|
|
590
|
use YAML::Perl::Processor -base; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
38
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
field 'next_layer' => 'serializer'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
field 'serializer_class', -init => '"YAML::Perl::Serializer"'; |
18
|
|
|
|
|
|
|
field 'serializer', -init => '$self->create("serializer")'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
field 'default_style'; |
21
|
|
|
|
|
|
|
field 'default_flow_style'; |
22
|
|
|
|
|
|
|
field 'represented_objects' => {}; |
23
|
|
|
|
|
|
|
field 'object_keeper' => []; |
24
|
|
|
|
|
|
|
field 'alias_key'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub represent { |
27
|
6
|
|
|
6
|
0
|
13
|
my $self = shift; |
28
|
6
|
|
|
|
|
14
|
for my $data (@_) { |
29
|
6
|
|
|
|
|
18
|
$self->represent_document($data); |
30
|
|
|
|
|
|
|
} |
31
|
6
|
|
|
|
|
15
|
return ${$self->serializer->emitter->writer->stream->buffer}; |
|
6
|
|
|
|
|
156
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub represent_document { |
35
|
18
|
|
|
18
|
0
|
35
|
my $self = shift; |
36
|
18
|
|
|
|
|
36
|
my $data = shift; |
37
|
18
|
|
|
|
|
68
|
my $node = $self->represent_data($data); |
38
|
18
|
|
|
|
|
425
|
$self->serializer->serialize_document($node); |
39
|
18
|
|
|
|
|
472
|
$self->represented_objects({}); |
40
|
18
|
|
|
|
|
451
|
$self->object_keeper([]); |
41
|
18
|
|
|
|
|
447
|
$self->alias_key(undef); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_classobj_bases { |
45
|
0
|
|
|
0
|
0
|
0
|
die "get_classobj_bases"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub represent_data { |
49
|
78
|
|
|
78
|
0
|
107
|
my $self = shift; |
50
|
78
|
|
|
|
|
101
|
my $data = shift; |
51
|
|
|
|
|
|
|
|
52
|
78
|
50
|
|
|
|
207
|
if ($self->ignore_aliases($data)) { |
53
|
0
|
|
|
|
|
0
|
$self->alias_key(undef); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
78
|
|
|
|
|
2084
|
$self->alias_key("$data"); # id(data) |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
78
|
|
|
|
|
117
|
my $node; |
60
|
78
|
50
|
|
|
|
1821
|
if (defined $self->alias_key) { |
61
|
78
|
100
|
|
|
|
1836
|
if ($self->represented_objects->{$self->alias_key}) { |
62
|
3
|
|
|
|
|
75
|
$node = $self->represented_objects->{$self->alias_key}; |
63
|
|
|
|
|
|
|
#if node is None: |
64
|
|
|
|
|
|
|
# raise RepresenterError("recursive objects are not allowed: %r" % data) |
65
|
3
|
|
|
|
|
12
|
return $node; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
#self.represented_objects[alias_key] = None |
68
|
75
|
|
|
|
|
120
|
push @{$self->object_keeper}, $data; |
|
75
|
|
|
|
|
1771
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
# data_types = type(data).__mro__ |
71
|
|
|
|
|
|
|
# if type(data) is types.InstanceType: |
72
|
|
|
|
|
|
|
# data_types = self.get_classobj_bases(data.__class__)+list(data_types) |
73
|
|
|
|
|
|
|
# if data_types[0] in self.yaml_representers: |
74
|
|
|
|
|
|
|
# node = self.yaml_representers[data_types[0]](self, data) |
75
|
|
|
|
|
|
|
# else: |
76
|
|
|
|
|
|
|
# for data_type in data_types: |
77
|
|
|
|
|
|
|
# if data_type in self.yaml_multi_representers: |
78
|
|
|
|
|
|
|
# node = self.yaml_multi_representers[data_type](self, data) |
79
|
|
|
|
|
|
|
# break |
80
|
|
|
|
|
|
|
# else: |
81
|
|
|
|
|
|
|
# if None in self.yaml_multi_representers: |
82
|
|
|
|
|
|
|
# node = self.yaml_multi_representers[None](self, data) |
83
|
|
|
|
|
|
|
# elif None in self.yaml_representers: |
84
|
|
|
|
|
|
|
# node = self.yaml_representers[None](self, data) |
85
|
|
|
|
|
|
|
# else: |
86
|
|
|
|
|
|
|
# node = ScalarNode(None, unicode(data)) |
87
|
|
|
|
|
|
|
# #if alias_key is not None: |
88
|
|
|
|
|
|
|
# # self.represented_objects[alias_key] = node |
89
|
|
|
|
|
|
|
|
90
|
75
|
100
|
66
|
|
|
353
|
if (not ref($data) or overload::Method($data, '""')) { |
91
|
42
|
|
|
|
|
119
|
return $self->represent_scalar(undef, $data); |
92
|
|
|
|
|
|
|
} |
93
|
33
|
|
|
|
|
6541
|
my ($class, $type, $id) = node_info($data); |
94
|
33
|
100
|
|
|
|
147
|
if ($type eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
95
|
15
|
100
|
|
|
|
46
|
my $tag = $class |
96
|
|
|
|
|
|
|
? "tag:yaml.org,2002:perl/array:$class" |
97
|
|
|
|
|
|
|
: undef; |
98
|
15
|
|
|
|
|
76
|
$node = $self->represent_sequence($tag, $data); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif ($type eq 'HASH') { |
101
|
15
|
100
|
|
|
|
43
|
my $tag = $class |
102
|
|
|
|
|
|
|
? "tag:yaml.org,2002:perl/hash:$class" |
103
|
|
|
|
|
|
|
: undef; |
104
|
15
|
|
|
|
|
68
|
$node = $self->represent_mapping($tag, $data); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ($type eq 'SCALAR') { |
107
|
3
|
50
|
|
|
|
17
|
my $tag = $class |
108
|
|
|
|
|
|
|
? "tag:yaml.org,2002:perl/scalar:$class" |
109
|
|
|
|
|
|
|
: undef; |
110
|
3
|
|
|
|
|
19
|
$node = $self->represent_scalar($tag, $data); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
0
|
|
|
|
|
0
|
die "can't represent '$data' yet..."; |
114
|
|
|
|
|
|
|
} |
115
|
33
|
|
|
|
|
71
|
return $node; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub represent_scalar { |
119
|
45
|
|
|
45
|
0
|
66
|
my $self = shift; |
120
|
45
|
|
|
|
|
58
|
my $tag = shift; |
121
|
45
|
|
|
|
|
53
|
my $value = shift; |
122
|
45
|
50
|
|
|
|
93
|
my $style = @_ ? shift : undef; |
123
|
45
|
100
|
|
|
|
131
|
if ($tag) { |
124
|
|
|
|
|
|
|
#tag:yaml.org,2002:perl/hash:Baz |
125
|
3
|
|
|
|
|
7
|
$value = $$value; |
126
|
|
|
|
|
|
|
} |
127
|
45
|
50
|
|
|
|
104
|
if (not defined $style) { |
128
|
45
|
|
|
|
|
1070
|
$style = $self->default_style; |
129
|
|
|
|
|
|
|
} |
130
|
45
|
|
|
|
|
196
|
my $node = YAML::Perl::Node::Scalar->new( |
131
|
|
|
|
|
|
|
tag => $tag, |
132
|
|
|
|
|
|
|
value => $value, |
133
|
|
|
|
|
|
|
style => $style, |
134
|
|
|
|
|
|
|
); |
135
|
45
|
50
|
|
|
|
1020
|
if (defined $self->alias_key) { |
136
|
45
|
|
|
|
|
1053
|
$self->represented_objects->{$self->alias_key} = $node; |
137
|
|
|
|
|
|
|
} |
138
|
45
|
|
|
|
|
152
|
return $node; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub represent_sequence { |
142
|
15
|
|
|
15
|
0
|
33
|
my $self = shift; |
143
|
15
|
|
|
|
|
24
|
my $tag = shift; |
144
|
15
|
|
|
|
|
26
|
my $sequence = shift; |
145
|
15
|
50
|
|
|
|
43
|
my $flow_style = @_ ? shift : undef; |
146
|
|
|
|
|
|
|
|
147
|
15
|
|
|
|
|
27
|
my $value = []; |
148
|
15
|
50
|
|
|
|
141
|
my $node = YAML::Perl::Node::Sequence->new( |
149
|
|
|
|
|
|
|
tag => $tag, |
150
|
|
|
|
|
|
|
value => $value, |
151
|
|
|
|
|
|
|
defined($flow_style) |
152
|
|
|
|
|
|
|
? (flow_style => $flow_style) : (), |
153
|
|
|
|
|
|
|
); |
154
|
15
|
50
|
|
|
|
385
|
if (defined $self->alias_key) { |
155
|
15
|
|
|
|
|
414
|
$self->represented_objects->{$self->alias_key} = $node; |
156
|
|
|
|
|
|
|
} |
157
|
15
|
|
|
|
|
37
|
my $best_style = False; # NOTE differs from PyYaml |
158
|
15
|
|
|
|
|
36
|
for my $item (@$sequence) { |
159
|
30
|
|
|
|
|
81
|
my $node_item = $self->represent_data($item); |
160
|
30
|
50
|
66
|
|
|
451
|
if (not $node_item->isa('YAML::Perl::Node::Scalar') and |
161
|
|
|
|
|
|
|
not $node_item->style |
162
|
|
|
|
|
|
|
) { |
163
|
9
|
|
|
|
|
15
|
$best_style = False; |
164
|
|
|
|
|
|
|
} |
165
|
30
|
|
|
|
|
80
|
push @$value, $node_item; |
166
|
|
|
|
|
|
|
} |
167
|
15
|
50
|
|
|
|
98
|
if (not defined $flow_style) { |
168
|
15
|
50
|
|
|
|
432
|
if (defined $self->default_flow_style) { |
169
|
0
|
|
|
|
|
0
|
$node->flow_style($self->default_flow_style); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
15
|
|
|
|
|
383
|
$node->flow_style($best_style); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
15
|
|
|
|
|
40
|
return $node; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub represent_mapping { |
179
|
15
|
|
|
15
|
0
|
25
|
my $self = shift; |
180
|
15
|
|
|
|
|
24
|
my $tag = shift; |
181
|
15
|
|
|
|
|
32
|
my $mapping = shift; |
182
|
15
|
50
|
|
|
|
37
|
my $flow_style = @_ ? shift : undef; |
183
|
|
|
|
|
|
|
|
184
|
15
|
|
|
|
|
24
|
my $value = []; |
185
|
15
|
50
|
|
|
|
139
|
my $node = YAML::Perl::Node::Mapping->new( |
186
|
|
|
|
|
|
|
tag => $tag, |
187
|
|
|
|
|
|
|
value => $value, |
188
|
|
|
|
|
|
|
defined($flow_style) |
189
|
|
|
|
|
|
|
? (flow_style => $flow_style) : (), |
190
|
|
|
|
|
|
|
); |
191
|
15
|
50
|
|
|
|
376
|
if (defined $self->alias_key) { |
192
|
15
|
|
|
|
|
374
|
$self->represented_objects->{$self->alias_key} = $node; |
193
|
|
|
|
|
|
|
} |
194
|
15
|
|
|
|
|
40
|
my $best_style = False; # NOTE differs from PyYaml |
195
|
|
|
|
|
|
|
# if hasattr(mapping, 'items'): |
196
|
|
|
|
|
|
|
# mapping = mapping.items() |
197
|
|
|
|
|
|
|
# mapping.sort() |
198
|
15
|
|
|
|
|
93
|
for my $item_key (sort keys %$mapping) { |
199
|
15
|
|
|
|
|
26
|
my $item_value = $mapping->{$item_key}; |
200
|
15
|
|
|
|
|
81
|
my $node_key = $self->represent_data($item_key); |
201
|
15
|
|
|
|
|
35
|
my $node_value = $self->represent_data($item_value); |
202
|
15
|
50
|
33
|
|
|
486
|
if (not ( |
203
|
|
|
|
|
|
|
$node_key->isa('YAML::Perl::Node::Scalar') and |
204
|
|
|
|
|
|
|
not $node_key->style |
205
|
|
|
|
|
|
|
)) { |
206
|
0
|
|
|
|
|
0
|
$best_style = False; |
207
|
|
|
|
|
|
|
} |
208
|
15
|
100
|
66
|
|
|
281
|
if (not ( |
209
|
|
|
|
|
|
|
$node_value->isa('YAML::Perl::Node::Scalar') and |
210
|
|
|
|
|
|
|
not $node_value->style |
211
|
|
|
|
|
|
|
)) { |
212
|
6
|
|
|
|
|
52
|
$best_style = False; |
213
|
|
|
|
|
|
|
} |
214
|
15
|
|
|
|
|
388
|
push @$value, $node_key, $node_value; |
215
|
|
|
|
|
|
|
} |
216
|
15
|
50
|
|
|
|
78
|
if (not defined $flow_style) { |
217
|
15
|
50
|
|
|
|
509
|
if (defined $self->default_flow_style) { |
218
|
0
|
|
|
|
|
0
|
$node->flow_style($self->default_flow_style); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
else { |
221
|
15
|
|
|
|
|
389
|
$node->flow_style($best_style); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
} |
224
|
15
|
|
|
|
|
454
|
return $node; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub ignore_aliases { |
228
|
78
|
|
|
78
|
0
|
99
|
my $self = shift; |
229
|
78
|
|
|
|
|
96
|
my $data = shift; |
230
|
78
|
|
|
|
|
181
|
return False; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |