line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: YAML::PP Rendering functions |
2
|
42
|
|
|
42
|
|
274
|
use strict; |
|
42
|
|
|
|
|
78
|
|
|
42
|
|
|
|
|
1182
|
|
3
|
42
|
|
|
42
|
|
200
|
use warnings; |
|
42
|
|
|
|
|
79
|
|
|
42
|
|
|
|
|
2616
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Render; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036_001'; # TRIAL VERSION |
7
|
|
|
|
|
|
|
|
8
|
42
|
50
|
|
42
|
|
275
|
use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0; |
|
42
|
|
|
|
|
95
|
|
|
42
|
|
|
|
|
36282
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub render_quoted { |
11
|
486
|
|
|
486
|
0
|
1199
|
my ($self, $style, $lines) = @_; |
12
|
|
|
|
|
|
|
|
13
|
486
|
|
|
|
|
784
|
my $quoted = ''; |
14
|
486
|
|
|
|
|
706
|
my $addspace = 0; |
15
|
|
|
|
|
|
|
|
16
|
486
|
|
|
|
|
1488
|
for my $i (0 .. $#$lines) { |
17
|
1321
|
|
|
|
|
2008
|
my $line = $lines->[ $i ]; |
18
|
1321
|
|
|
|
|
2099
|
my $value = $line->{value}; |
19
|
1321
|
|
|
|
|
2148
|
my $last = $i == $#$lines; |
20
|
1321
|
|
|
|
|
2063
|
my $first = $i == 0; |
21
|
1321
|
100
|
|
|
|
2665
|
if ($value eq '') { |
22
|
298
|
100
|
|
|
|
811
|
if ($first) { |
|
|
100
|
|
|
|
|
|
23
|
66
|
|
|
|
|
118
|
$addspace = 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($last) { |
26
|
66
|
100
|
|
|
|
183
|
$quoted .= ' ' if $addspace; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
166
|
|
|
|
|
248
|
$addspace = 0; |
30
|
166
|
|
|
|
|
309
|
$quoted .= "\n"; |
31
|
|
|
|
|
|
|
} |
32
|
298
|
|
|
|
|
556
|
next; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1023
|
100
|
|
|
|
2245
|
$quoted .= ' ' if $addspace; |
36
|
1023
|
|
|
|
|
1496
|
$addspace = 1; |
37
|
1023
|
100
|
|
|
|
1993
|
if ($style eq '"') { |
38
|
921
|
100
|
|
|
|
2465
|
if ($line->{orig} =~ m/\\$/) { |
39
|
82
|
|
|
|
|
359
|
$line->{value} =~ s/\\$//; |
40
|
82
|
|
|
|
|
322
|
$value =~ s/\\$//; |
41
|
82
|
|
|
|
|
146
|
$addspace = 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
1023
|
|
|
|
|
2212
|
$quoted .= $value; |
45
|
|
|
|
|
|
|
} |
46
|
486
|
|
|
|
|
1463
|
return $quoted; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub render_block_scalar { |
50
|
1712
|
|
|
1712
|
0
|
4603
|
my ($self, $block_type, $chomp, $lines) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1712
|
|
|
|
|
3007
|
my ($folded, $keep, $trim); |
53
|
1712
|
100
|
|
|
|
4208
|
if ($block_type eq '>') { |
54
|
534
|
|
|
|
|
987
|
$folded = 1; |
55
|
|
|
|
|
|
|
} |
56
|
1712
|
100
|
|
|
|
5040
|
if ($chomp eq '+') { |
|
|
100
|
|
|
|
|
|
57
|
189
|
|
|
|
|
361
|
$keep = 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ($chomp eq '-') { |
60
|
305
|
|
|
|
|
516
|
$trim = 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1712
|
|
|
|
|
2668
|
my $string = ''; |
64
|
1712
|
100
|
|
|
|
3733
|
if (not $keep) { |
65
|
|
|
|
|
|
|
# remove trailing empty lines |
66
|
1523
|
|
|
|
|
3642
|
while (@$lines) { |
67
|
1715
|
100
|
|
|
|
4085
|
last if $lines->[-1] ne ''; |
68
|
222
|
|
|
|
|
502
|
pop @$lines; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
1712
|
100
|
|
|
|
3452
|
if ($folded) { |
72
|
|
|
|
|
|
|
|
73
|
534
|
|
|
|
|
857
|
my $prev = 'START'; |
74
|
534
|
|
|
|
|
949
|
my $trailing = ''; |
75
|
534
|
100
|
|
|
|
1143
|
if ($keep) { |
76
|
39
|
|
100
|
|
|
202
|
while (@$lines and $lines->[-1] eq '') { |
77
|
39
|
|
|
|
|
73
|
pop @$lines; |
78
|
39
|
|
|
|
|
125
|
$trailing .= "\n"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
534
|
|
|
|
|
1698
|
for my $i (0 .. $#$lines) { |
82
|
1190
|
|
|
|
|
1909
|
my $line = $lines->[ $i ]; |
83
|
|
|
|
|
|
|
|
84
|
1190
|
100
|
|
|
|
3368
|
my $type = $line eq '' |
|
|
100
|
|
|
|
|
|
85
|
|
|
|
|
|
|
? 'EMPTY' |
86
|
|
|
|
|
|
|
: $line =~ m/\A[ \t]/ |
87
|
|
|
|
|
|
|
? 'MORE' |
88
|
|
|
|
|
|
|
: 'CONTENT'; |
89
|
|
|
|
|
|
|
|
90
|
1190
|
100
|
100
|
|
|
6338
|
if ($prev eq 'MORE' and $type eq 'EMPTY') { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
91
|
31
|
|
|
|
|
49
|
$type = 'MORE'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ($prev eq 'CONTENT') { |
94
|
289
|
100
|
|
|
|
837
|
if ($type ne 'CONTENT') { |
|
|
50
|
|
|
|
|
|
95
|
143
|
|
|
|
|
281
|
$string .= "\n"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ($type eq 'CONTENT') { |
98
|
146
|
|
|
|
|
298
|
$string .= ' '; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ($prev eq 'START' and $type eq 'EMPTY') { |
102
|
54
|
|
|
|
|
111
|
$string .= "\n"; |
103
|
54
|
|
|
|
|
99
|
$type = 'START'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') { |
106
|
127
|
|
|
|
|
235
|
$string .= "\n"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
1190
|
|
|
|
|
2103
|
$string .= $line; |
110
|
|
|
|
|
|
|
|
111
|
1190
|
100
|
100
|
|
|
2714
|
if ($type eq 'MORE' and $i < $#$lines) { |
112
|
101
|
|
|
|
|
187
|
$string .= "\n"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
1190
|
|
|
|
|
2267
|
$prev = $type; |
116
|
|
|
|
|
|
|
} |
117
|
534
|
100
|
|
|
|
1300
|
if ($keep) { |
118
|
39
|
|
|
|
|
68
|
$string .= $trailing; |
119
|
|
|
|
|
|
|
} |
120
|
534
|
100
|
100
|
|
|
2284
|
$string .= "\n" if @$lines and not $trim; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
1178
|
|
|
|
|
3537
|
for my $i (0 .. $#$lines) { |
124
|
2092
|
|
|
|
|
4142
|
$string .= $lines->[ $i ]; |
125
|
2092
|
100
|
100
|
|
|
8464
|
$string .= "\n" if ($i != $#$lines or not $trim); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
1712
|
|
|
|
|
2747
|
TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']); |
129
|
1712
|
|
|
|
|
4781
|
return $string; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub render_multi_val { |
133
|
242
|
|
|
242
|
0
|
651
|
my ($self, $multi) = @_; |
134
|
242
|
|
|
|
|
469
|
my $string = ''; |
135
|
242
|
|
|
|
|
396
|
my $start = 1; |
136
|
242
|
|
|
|
|
631
|
for my $line (@$multi) { |
137
|
567
|
100
|
|
|
|
1063
|
if (not $start) { |
138
|
297
|
100
|
|
|
|
687
|
if ($line eq '') { |
139
|
28
|
|
|
|
|
71
|
$string .= "\n"; |
140
|
28
|
|
|
|
|
57
|
$start = 1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
269
|
|
|
|
|
702
|
$string .= " $line"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
270
|
|
|
|
|
520
|
$string .= $line; |
148
|
270
|
|
|
|
|
465
|
$start = 0; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
242
|
|
|
|
|
700
|
return $string; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |