line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: YAML::PP Rendering functions |
2
|
42
|
|
|
42
|
|
284
|
use strict; |
|
42
|
|
|
|
|
88
|
|
|
42
|
|
|
|
|
1244
|
|
3
|
42
|
|
|
42
|
|
226
|
use warnings; |
|
42
|
|
|
|
|
94
|
|
|
42
|
|
|
|
|
2512
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Render; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036_002'; # TRIAL VERSION |
7
|
|
|
|
|
|
|
|
8
|
42
|
50
|
|
42
|
|
289
|
use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0; |
|
42
|
|
|
|
|
99
|
|
|
42
|
|
|
|
|
37113
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub render_quoted { |
11
|
489
|
|
|
489
|
0
|
1323
|
my ($self, $style, $lines) = @_; |
12
|
|
|
|
|
|
|
|
13
|
489
|
|
|
|
|
832
|
my $quoted = ''; |
14
|
489
|
|
|
|
|
737
|
my $addspace = 0; |
15
|
|
|
|
|
|
|
|
16
|
489
|
|
|
|
|
1509
|
for my $i (0 .. $#$lines) { |
17
|
1330
|
|
|
|
|
2054
|
my $line = $lines->[ $i ]; |
18
|
1330
|
|
|
|
|
2109
|
my $value = $line->{value}; |
19
|
1330
|
|
|
|
|
2108
|
my $last = $i == $#$lines; |
20
|
1330
|
|
|
|
|
2006
|
my $first = $i == 0; |
21
|
1330
|
100
|
|
|
|
2645
|
if ($value eq '') { |
22
|
301
|
100
|
|
|
|
817
|
if ($first) { |
|
|
100
|
|
|
|
|
|
23
|
66
|
|
|
|
|
114
|
$addspace = 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($last) { |
26
|
66
|
100
|
|
|
|
214
|
$quoted .= ' ' if $addspace; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
169
|
|
|
|
|
276
|
$addspace = 0; |
30
|
169
|
|
|
|
|
322
|
$quoted .= "\n"; |
31
|
|
|
|
|
|
|
} |
32
|
301
|
|
|
|
|
590
|
next; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1029
|
100
|
|
|
|
2211
|
$quoted .= ' ' if $addspace; |
36
|
1029
|
|
|
|
|
1479
|
$addspace = 1; |
37
|
1029
|
100
|
|
|
|
2028
|
if ($style eq '"') { |
38
|
921
|
100
|
|
|
|
2448
|
if ($line->{orig} =~ m/\\$/) { |
39
|
82
|
|
|
|
|
374
|
$line->{value} =~ s/\\$//; |
40
|
82
|
|
|
|
|
324
|
$value =~ s/\\$//; |
41
|
82
|
|
|
|
|
140
|
$addspace = 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
1029
|
|
|
|
|
2271
|
$quoted .= $value; |
45
|
|
|
|
|
|
|
} |
46
|
489
|
|
|
|
|
1463
|
return $quoted; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub render_block_scalar { |
50
|
1710
|
|
|
1710
|
0
|
4575
|
my ($self, $block_type, $chomp, $lines) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1710
|
|
|
|
|
2781
|
my ($folded, $keep, $trim); |
53
|
1710
|
100
|
|
|
|
4092
|
if ($block_type eq '>') { |
54
|
532
|
|
|
|
|
912
|
$folded = 1; |
55
|
|
|
|
|
|
|
} |
56
|
1710
|
100
|
|
|
|
4869
|
if ($chomp eq '+') { |
|
|
100
|
|
|
|
|
|
57
|
189
|
|
|
|
|
349
|
$keep = 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ($chomp eq '-') { |
60
|
305
|
|
|
|
|
496
|
$trim = 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1710
|
|
|
|
|
2750
|
my $string = ''; |
64
|
1710
|
100
|
|
|
|
3620
|
if (not $keep) { |
65
|
|
|
|
|
|
|
# remove trailing empty lines |
66
|
1521
|
|
|
|
|
3409
|
while (@$lines) { |
67
|
1713
|
100
|
|
|
|
4364
|
last if $lines->[-1] ne ''; |
68
|
222
|
|
|
|
|
559
|
pop @$lines; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
1710
|
100
|
|
|
|
3572
|
if ($folded) { |
72
|
|
|
|
|
|
|
|
73
|
532
|
|
|
|
|
902
|
my $prev = 'START'; |
74
|
532
|
|
|
|
|
875
|
my $trailing = ''; |
75
|
532
|
100
|
|
|
|
1137
|
if ($keep) { |
76
|
39
|
|
100
|
|
|
197
|
while (@$lines and $lines->[-1] eq '') { |
77
|
39
|
|
|
|
|
66
|
pop @$lines; |
78
|
39
|
|
|
|
|
119
|
$trailing .= "\n"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
532
|
|
|
|
|
1692
|
for my $i (0 .. $#$lines) { |
82
|
1183
|
|
|
|
|
1910
|
my $line = $lines->[ $i ]; |
83
|
|
|
|
|
|
|
|
84
|
1183
|
100
|
|
|
|
3345
|
my $type = $line eq '' |
|
|
100
|
|
|
|
|
|
85
|
|
|
|
|
|
|
? 'EMPTY' |
86
|
|
|
|
|
|
|
: $line =~ m/\A[ \t]/ |
87
|
|
|
|
|
|
|
? 'MORE' |
88
|
|
|
|
|
|
|
: 'CONTENT'; |
89
|
|
|
|
|
|
|
|
90
|
1183
|
100
|
100
|
|
|
6365
|
if ($prev eq 'MORE' and $type eq 'EMPTY') { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
91
|
30
|
|
|
|
|
57
|
$type = 'MORE'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ($prev eq 'CONTENT') { |
94
|
288
|
100
|
|
|
|
790
|
if ($type ne 'CONTENT') { |
|
|
50
|
|
|
|
|
|
95
|
142
|
|
|
|
|
266
|
$string .= "\n"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ($type eq 'CONTENT') { |
98
|
146
|
|
|
|
|
316
|
$string .= ' '; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ($prev eq 'START' and $type eq 'EMPTY') { |
102
|
54
|
|
|
|
|
113
|
$string .= "\n"; |
103
|
54
|
|
|
|
|
98
|
$type = 'START'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') { |
106
|
126
|
|
|
|
|
221
|
$string .= "\n"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
1183
|
|
|
|
|
2189
|
$string .= $line; |
110
|
|
|
|
|
|
|
|
111
|
1183
|
100
|
100
|
|
|
2911
|
if ($type eq 'MORE' and $i < $#$lines) { |
112
|
98
|
|
|
|
|
181
|
$string .= "\n"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
1183
|
|
|
|
|
2245
|
$prev = $type; |
116
|
|
|
|
|
|
|
} |
117
|
532
|
100
|
|
|
|
1354
|
if ($keep) { |
118
|
39
|
|
|
|
|
81
|
$string .= $trailing; |
119
|
|
|
|
|
|
|
} |
120
|
532
|
100
|
100
|
|
|
2257
|
$string .= "\n" if @$lines and not $trim; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
1178
|
|
|
|
|
3600
|
for my $i (0 .. $#$lines) { |
124
|
2092
|
|
|
|
|
4376
|
$string .= $lines->[ $i ]; |
125
|
2092
|
100
|
100
|
|
|
8355
|
$string .= "\n" if ($i != $#$lines or not $trim); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
1710
|
|
|
|
|
2767
|
TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']); |
129
|
1710
|
|
|
|
|
4823
|
return $string; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub render_multi_val { |
133
|
239
|
|
|
239
|
0
|
662
|
my ($self, $multi) = @_; |
134
|
239
|
|
|
|
|
471
|
my $string = ''; |
135
|
239
|
|
|
|
|
421
|
my $start = 1; |
136
|
239
|
|
|
|
|
629
|
for my $line (@$multi) { |
137
|
558
|
100
|
|
|
|
1061
|
if (not $start) { |
138
|
294
|
100
|
|
|
|
710
|
if ($line eq '') { |
139
|
25
|
|
|
|
|
61
|
$string .= "\n"; |
140
|
25
|
|
|
|
|
53
|
$start = 1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
269
|
|
|
|
|
752
|
$string .= " $line"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
264
|
|
|
|
|
499
|
$string .= $line; |
148
|
264
|
|
|
|
|
481
|
$start = 0; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
239
|
|
|
|
|
744
|
return $string; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |