line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: YAML::PP Rendering functions |
2
|
42
|
|
|
42
|
|
272
|
use strict; |
|
42
|
|
|
|
|
86
|
|
|
42
|
|
|
|
|
1186
|
|
3
|
42
|
|
|
42
|
|
206
|
use warnings; |
|
42
|
|
|
|
|
77
|
|
|
42
|
|
|
|
|
2555
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Render; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
42
|
50
|
|
42
|
|
268
|
use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0; |
|
42
|
|
|
|
|
102
|
|
|
42
|
|
|
|
|
37151
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub render_quoted { |
11
|
112
|
|
|
112
|
0
|
241
|
my ($self, $style, $lines) = @_; |
12
|
|
|
|
|
|
|
|
13
|
112
|
|
|
|
|
171
|
my $quoted = ''; |
14
|
112
|
|
|
|
|
166
|
my $addspace = 0; |
15
|
|
|
|
|
|
|
|
16
|
112
|
|
|
|
|
313
|
for my $i (0 .. $#$lines) { |
17
|
230
|
|
|
|
|
340
|
my $line = $lines->[ $i ]; |
18
|
230
|
|
|
|
|
360
|
my $value = $line->{value}; |
19
|
230
|
|
|
|
|
366
|
my $last = $i == $#$lines; |
20
|
230
|
|
|
|
|
326
|
my $first = $i == 0; |
21
|
230
|
50
|
|
|
|
429
|
if ($value eq '') { |
22
|
0
|
0
|
|
|
|
0
|
if ($first) { |
|
|
0
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
$addspace = 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($last) { |
26
|
0
|
0
|
|
|
|
0
|
$quoted .= ' ' if $addspace; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
0
|
|
|
|
|
0
|
$addspace = 0; |
30
|
0
|
|
|
|
|
0
|
$quoted .= "\n"; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
0
|
next; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
230
|
100
|
|
|
|
455
|
$quoted .= ' ' if $addspace; |
36
|
230
|
|
|
|
|
315
|
$addspace = 1; |
37
|
230
|
50
|
|
|
|
423
|
if ($style eq '"') { |
38
|
230
|
100
|
|
|
|
616
|
if ($line->{orig} =~ m/\\$/) { |
39
|
8
|
|
|
|
|
24
|
$line->{value} =~ s/\\$//; |
40
|
8
|
|
|
|
|
19
|
$value =~ s/\\$//; |
41
|
8
|
|
|
|
|
14
|
$addspace = 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
230
|
|
|
|
|
473
|
$quoted .= $value; |
45
|
|
|
|
|
|
|
} |
46
|
112
|
|
|
|
|
313
|
return $quoted; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub render_block_scalar { |
50
|
192
|
|
|
192
|
0
|
521
|
my ($self, $block_type, $chomp, $lines) = @_; |
51
|
|
|
|
|
|
|
|
52
|
192
|
|
|
|
|
335
|
my ($folded, $keep, $trim); |
53
|
192
|
100
|
|
|
|
432
|
if ($block_type eq '>') { |
54
|
76
|
|
|
|
|
126
|
$folded = 1; |
55
|
|
|
|
|
|
|
} |
56
|
192
|
100
|
|
|
|
473
|
if ($chomp eq '+') { |
|
|
100
|
|
|
|
|
|
57
|
49
|
|
|
|
|
82
|
$keep = 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ($chomp eq '-') { |
60
|
33
|
|
|
|
|
47
|
$trim = 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
192
|
|
|
|
|
308
|
my $string = ''; |
64
|
192
|
100
|
|
|
|
376
|
if (not $keep) { |
65
|
|
|
|
|
|
|
# remove trailing empty lines |
66
|
143
|
|
|
|
|
429
|
while (@$lines) { |
67
|
142
|
50
|
|
|
|
411
|
last if $lines->[-1] ne ''; |
68
|
0
|
|
|
|
|
0
|
pop @$lines; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
192
|
100
|
|
|
|
377
|
if ($folded) { |
72
|
|
|
|
|
|
|
|
73
|
76
|
|
|
|
|
118
|
my $prev = 'START'; |
74
|
76
|
|
|
|
|
113
|
my $trailing = ''; |
75
|
76
|
100
|
|
|
|
173
|
if ($keep) { |
76
|
39
|
|
100
|
|
|
173
|
while (@$lines and $lines->[-1] eq '') { |
77
|
39
|
|
|
|
|
63
|
pop @$lines; |
78
|
39
|
|
|
|
|
117
|
$trailing .= "\n"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
76
|
|
|
|
|
247
|
for my $i (0 .. $#$lines) { |
82
|
76
|
|
|
|
|
143
|
my $line = $lines->[ $i ]; |
83
|
|
|
|
|
|
|
|
84
|
76
|
100
|
|
|
|
301
|
my $type = $line eq '' |
|
|
100
|
|
|
|
|
|
85
|
|
|
|
|
|
|
? 'EMPTY' |
86
|
|
|
|
|
|
|
: $line =~ m/\A[ \t]/ |
87
|
|
|
|
|
|
|
? 'MORE' |
88
|
|
|
|
|
|
|
: 'CONTENT'; |
89
|
|
|
|
|
|
|
|
90
|
76
|
100
|
100
|
|
|
581
|
if ($prev eq 'MORE' and $type eq 'EMPTY') { |
|
|
50
|
100
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
91
|
2
|
|
|
|
|
4
|
$type = 'MORE'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ($prev eq 'CONTENT') { |
94
|
0
|
0
|
|
|
|
0
|
if ($type ne 'CONTENT') { |
|
|
0
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
$string .= "\n"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ($type eq 'CONTENT') { |
98
|
0
|
|
|
|
|
0
|
$string .= ' '; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ($prev eq 'START' and $type eq 'EMPTY') { |
102
|
10
|
|
|
|
|
29
|
$string .= "\n"; |
103
|
10
|
|
|
|
|
13
|
$type = 'START'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') { |
106
|
0
|
|
|
|
|
0
|
$string .= "\n"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
76
|
|
|
|
|
143
|
$string .= $line; |
110
|
|
|
|
|
|
|
|
111
|
76
|
100
|
100
|
|
|
205
|
if ($type eq 'MORE' and $i < $#$lines) { |
112
|
9
|
|
|
|
|
12
|
$string .= "\n"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
76
|
|
|
|
|
170
|
$prev = $type; |
116
|
|
|
|
|
|
|
} |
117
|
76
|
100
|
|
|
|
193
|
if ($keep) { |
118
|
39
|
|
|
|
|
66
|
$string .= $trailing; |
119
|
|
|
|
|
|
|
} |
120
|
76
|
100
|
100
|
|
|
358
|
$string .= "\n" if @$lines and not $trim; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
116
|
|
|
|
|
370
|
for my $i (0 .. $#$lines) { |
124
|
213
|
|
|
|
|
392
|
$string .= $lines->[ $i ]; |
125
|
213
|
100
|
100
|
|
|
842
|
$string .= "\n" if ($i != $#$lines or not $trim); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
192
|
|
|
|
|
298
|
TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']); |
129
|
192
|
|
|
|
|
523
|
return $string; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub render_multi_val { |
133
|
0
|
|
|
0
|
0
|
|
my ($self, $multi) = @_; |
134
|
0
|
|
|
|
|
|
my $string = ''; |
135
|
0
|
|
|
|
|
|
my $start = 1; |
136
|
0
|
|
|
|
|
|
for my $line (@$multi) { |
137
|
0
|
0
|
|
|
|
|
if (not $start) { |
138
|
0
|
0
|
|
|
|
|
if ($line eq '') { |
139
|
0
|
|
|
|
|
|
$string .= "\n"; |
140
|
0
|
|
|
|
|
|
$start = 1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
0
|
|
|
|
|
|
$string .= " $line"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
0
|
|
|
|
|
|
$string .= $line; |
148
|
0
|
|
|
|
|
|
$start = 0; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
return $string; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |