blib/lib/YAML/PP/Render.pm

filter: Statementstmt 100% 89 / 89 Branchbran 96.7% 60 / 62 Conditioncond 100% 21 / 21 MC/DCmcdc 100% 14 / 14 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 97.4% 190 / 195 CC 43 SCAR 31.0
CC
43
Cov
99%
render_block_scalar
31.0
render_quoted
9.0
render_multi_val
4.0
CRAP 22.2
« blib/lib/YAML/PP/Emitter.pm ↑ Summary blib/lib/YAML/PP/Representer.pm »
1 # ABSTRACT: YAML::PP Rendering functions
2 52 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 52 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package YAML::PP::Render;
5  
6 52 our $VERSION = 'v0.41.1'; # TRIAL VERSION
7  
8 52 ▶use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'YAML_PP_TRACE'} ? : 0 52 52
9  
10 491 ▶sub render_quoted {
Subroutine render_quoted: called CC=9 SCAR=22.0
Pod undocumented
11 491 my ($self, $style, $lines) = @_;
12  
13 491 my $quoted = '';
14 491 my $addspace = 0;
15  
16 491 for my $i (0 .. $#$lines) {
17 1334 my $line = $lines->[ $i ];
18 1334 my $value = $line->{value};
19 1334 my $last = $i == $#$lines;
20 1334 my $first = $i == 0;
21 1334 ▶ if ($value eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "") 301 1033 1334
22 301 ▶ if ($first) {
Branch: 2 branches
BranchTrueFalseTotal
if ($first) { } 66 235 301
elsif ($last) { } 66 169 235
23 66 $addspace = 1;
24 }
25 elsif ($last) {
26 66 ▶ $quoted .= ' ' if $addspace;
Branch: 1 branch
BranchTrueFalseTotal
if $addspace 42 24 66
27 }
28 else {
29 169 $addspace = 0;
30 169 $quoted .= "\n";
31 }
32 301 next;
33 }
34  
35 1033 ▶ $quoted .= ' ' if $addspace;
Branch: 1 branch
BranchTrueFalseTotal
if $addspace 393 640 1033
36 1033 $addspace = 1;
37 1033 ▶ if ($style eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq "\"") 925 108 1033
38 925 ▶ if ($line->{orig} =~ m/\\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line->{"orig"} =~ /\\$/) 82 843 925
39 82 $line->{value} =~ s/\\$//;
40 82 $value =~ s/\\$//;
41 82 $addspace = 0;
42 }
43 }
44 1033 $quoted .= $value;
45 }
46 491 return $quoted;
47 }
48  
49 1712 ▶sub render_block_scalar {
Subroutine render_block_scalar: called CC=31 SCAR=34.3
Pod undocumented
50 1712 my ($self, $block_type, $chomp, $lines) = @_;
51  
52 1712 my ($folded, $keep, $trim);
53 1712 ▶ if ($block_type eq '>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type eq ">") 532 1180 1712
54 532 $folded = 1;
55 }
56 1712 ▶ if ($chomp eq '+') {
Branch: 2 branches
BranchTrueFalseTotal
if ($chomp eq '+') { } 189 1523 1712
elsif ($chomp eq '-') { } 305 1218 1523
57 189 $keep = 1;
58 }
59 elsif ($chomp eq '-') {
60 305 $trim = 1;
61 }
62  
63 1712 my $string = '';
64 1712 ▶ if (not $keep) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep) 1523 189 1712
65 # remove trailing empty lines
66 1523 ▶ while (@$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 1715 30 1745
67 1715 ▶ last if $lines->[-1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[-1] ne "" 1493 222 1715
68 222 pop @$lines;
69 }
70 }
71 1712 ▶ if ($folded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($folded) { } 532 1180 1712
72  
73 532 my $prev = 'START';
74 532 my $trailing = '';
75 532 ▶ if ($keep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep) 39 493 532
76 39 ▶ while (@$lines and $lines->[-1] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines and $lines->[-1] eq "") 39 39 78
Condition100%3/3
@$lines and $lines->[-1] eq ""
!ll&&!rl&&r
192039
MC/DC100%2/2
@$lines and $lines->[-1] eq ""
@$lines $lines->[-1] eq ""
Truth table100%3/3
A and B
A= @$linesB= $lines->[-1] eq ""
ABresult
0X0
100
111
77 39 pop @$lines;
78 39 $trailing .= "\n";
79 }
80 }
81 532 for my $i (0 .. $#$lines) {
82 1183 my $line = $lines->[ $i ];
83  
84 1183 ▶ my $type = $line eq ''
Branch: 2 branches
BranchTrueFalseTotal
$line eq '' ? : 332 851 1183
$line =~ /\A[ \t]/ ? : 115 736 851
85 ? 'EMPTY'
86 : $line =~ m/\A[ \t]/
87 ? 'MORE'
88 : 'CONTENT';
89  
90 1183 ▶ if ($prev eq 'MORE' and $type eq 'EMPTY') {
Branch: 4 branches
BranchTrueFalseTotal
if ($prev eq 'MORE' and $type eq 'EMPTY') { } 30 1153 1183
elsif ($prev eq 'CONTENT') { } 288 865 1153
elsif ($prev eq 'START' and $type eq 'EMPTY') { } 54 811 865
elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') { } 126 1248 1374
Condition100%3/3
$prev eq "MORE" and $type eq "EMPTY"
!ll&&!rl&&r
10856830
MC/DC100%2/2
$prev eq "MORE" and $type eq "EMPTY"
$prev eq "MORE" $type eq "EMPTY"
Truth table100%3/3
A and B
A= $prev eq "MORE"B= $type eq "EMPTY"
ABresult
0X0
100
111
91 30 $type = 'MORE';
92 }
93 elsif ($prev eq 'CONTENT') {
94 288 ▶ if ($type ne 'CONTENT') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type ne 'CONTENT') { } 142 146 288
elsif ($type eq 'CONTENT') { } 146 0 146
95 142 $string .= "\n";
96 }
97 elsif ($type eq 'CONTENT') {
98 146 $string .= ' ';
99 }
100 }
101 ▶ elsif ($prev eq 'START' and $type eq 'EMPTY') {
Condition100%3/3
$prev eq "START" and $type eq "EMPTY"
!ll&&!rl&&r
31649554
MC/DC100%2/2
$prev eq "START" and $type eq "EMPTY"
$prev eq "START" $type eq "EMPTY"
Truth table100%3/3
A and B
A= $prev eq "START"B= $type eq "EMPTY"
ABresult
0X0
100
111
102 54 $string .= "\n";
103 54 $type = 'START';
104 }
105 ▶ elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') {
Condition100%3/3
$prev eq "EMPTY" and $type ne "CONTENT"
!ll&&!rl&&r
563122126
MC/DC100%2/2
$prev eq "EMPTY" and $type ne "CONTENT"
$prev eq "EMPTY" $type ne "CONTENT"
Truth table100%3/3
A and B
A= $prev eq "EMPTY"B= $type ne "CONTENT"
ABresult
0X0
100
111
106 126 $string .= "\n";
107 }
108  
109 1183 $string .= $line;
110  
111 1183 ▶ if ($type eq 'MORE' and $i < $#$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "MORE" and $i < $lines->$#*) 98 1085 1183
Condition100%3/3
$type eq "MORE" and $i < $lines->$#*
!ll&&!rl&&r
10384798
MC/DC100%2/2
$type eq "MORE" and $i < $lines->$#*
$type eq "MORE" $i < $lines->$#*
Truth table100%3/3
A and B
A= $type eq "MORE"B= $i < $lines->$#*
ABresult
0X0
100
111
112 98 $string .= "\n";
113 }
114  
115 1183 $prev = $type;
116 }
117 532 ▶ if ($keep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep) 39 493 532
118 39 $string .= $trailing;
119 }
120 532 ▶ $string .= "\n" if @$lines and not $trim;
Branch: 1 branch
BranchTrueFalseTotal
if @$lines and not $trim 429 103 532
Condition100%3/3
@$lines and not $trim
!ll&&!rl&&r
3766429
MC/DC100%2/2
@$lines and not $trim
@$lines not $trim
Truth table100%3/3
A and not(B)
A= @$linesB= not $trim
ABresult
0X0
100
111
121 }
122 else {
123 1180 for my $i (0 .. $#$lines) {
124 2096 $string .= $lines->[ $i ];
125 2096 ▶ $string .= "\n" if ($i != $#$lines or not $trim);
Branch: 1 branch
BranchTrueFalseTotal
if $i != $lines->$#* or not $trim 1876 220 2096
Condition100%3/3
$i != $lines->$#* or not $trim
l!l&&r!l&&!r
938938220
MC/DC100%2/2
$i != $lines->$#* or not $trim
$i != $lines->$#* not $trim
Truth table100%3/3
A or not(B)
A= $i != $lines->$#*B= not $trim
ABresult
1X1
011
000
126 }
127 }
128 1712 TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']);
129 1712 return $string;
130 }
131  
132 242 ▶sub render_multi_val {
Subroutine render_multi_val: called CC=4 SCAR=13.9
Pod undocumented
133 242 my ($self, $multi) = @_;
134 242 my $string = '';
135 242 my $start = 1;
136 242 for my $line (@$multi) {
137 564 ▶ if (not $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $start) { } 297 267 564
138 297 ▶ if ($line eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq '') { } 25 272 297
139 25 $string .= "\n";
140 25 $start = 1;
141 }
142 else {
143 272 $string .= " $line";
144 }
145 }
146 else {
147 267 $string .= $line;
148 267 $start = 0;
149 }
150 }
151 242 return $string;
152 }
153  
154  
155 52 1;
« blib/lib/YAML/PP/Emitter.pm ↑ Summary blib/lib/YAML/PP/Representer.pm »