| 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.43.0'; # VERSION | |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 22 | 301 | ▶ | if ($first) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 23 | 66 | $addspace = 1; | |||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||
| 25 | elsif ($last) { | ||||||||||||||||||||||||||||||||||||||||
| 26 | 66 | ▶ | $quoted .= ' ' if $addspace; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 36 | 1033 | $addspace = 1; | |||||||||||||||||||||||||||||||||||||||
| 37 | 1033 | ▶ | if ($style eq '"') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 38 | 925 | ▶ | if ($line->{orig} =~ m/\\$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 54 | 532 | $folded = 1; | |||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||
| 56 | 1712 | ▶ | if ($chomp eq '+') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 65 | # remove trailing empty lines | ||||||||||||||||||||||||||||||||||||||||
| 66 | 1523 | ▶ | while (@$lines) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 67 | 1715 | ▶ | last if $lines->[-1] ne ''; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 68 | 222 | pop @$lines; | |||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||
| 71 | 1712 | ▶ | if ($folded) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||
| 73 | 532 | my $prev = 'START'; | |||||||||||||||||||||||||||||||||||||||
| 74 | 532 | my $trailing = ''; | |||||||||||||||||||||||||||||||||||||||
| 75 | 532 | ▶ | if ($keep) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 76 | 39 | ▶ | while (@$lines and $lines->[-1] eq '') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lines and $lines->[-1] eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$prev eq "MORE" and $type eq "EMPTY"
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"
| |||||||||||||||||||||||||||||||||||||||||
| 91 | 30 | $type = 'MORE'; | |||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||
| 93 | elsif ($prev eq 'CONTENT') { | ||||||||||||||||||||||||||||||||||||||||
| 94 | 288 | ▶ | if ($type ne 'CONTENT') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||
| 106 | 126 | $string .= "\n"; | |||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||
| 109 | 1183 | $string .= $line; | |||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||
| 111 | 1183 | ▶ | if ($type eq 'MORE' and $i < $#$lines) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "MORE" and $i < $lines->$#*
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->$#*
| |||||||||||||||||||||||||||||||||||||||||
| 112 | 98 | $string .= "\n"; | |||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||
| 115 | 1183 | $prev = $type; | |||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||
| 117 | 532 | ▶ | if ($keep) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 118 | 39 | $string .= $trailing; | |||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||
| 120 | 532 | ▶ | $string .= "\n" if @$lines and not $trim; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lines and not $trim
MC/DC100%2/2
@$lines and not $trim
@$lines
not $trim
Truth table100%3/3
A and not(B)
A= @$linesB= not $trim
| |||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$i != $lines->$#* or not $trim
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
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 138 | 297 | ▶ | if ($line eq '') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||