| 1 | # ABSTRACT: Tidy YAML files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings FATAL => qw/ substr /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use experimental qw/ signatures /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package YAML::Tidy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | our $VERSION = '0.007'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use YAML::Tidy::Node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use YAML::Tidy::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use YAML::LibYAML::API::XS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | use YAML::PP::Common qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | YAML_PLAIN_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | YAML_DOUBLE_QUOTED_SCALAR_STYLE YAML_LITERAL_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | YAML_FOLDED_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | YAML_FLOW_SEQUENCE_STYLE YAML_FLOW_MAPPING_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use YAML::PP::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use YAML::PP::Highlight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use constant DEBUG => $ENV{YAML_TIDY_DEBUG} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ▶ | sub new($class, %args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 22 | ▶ | my $cfg = delete $args{cfg} || YAML::Tidy::Config->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $args{'cfg'} || 'YAML::Tidy::Config'->new
MC/DC0%0/2
delete $args{'cfg'} || 'YAML::Tidy::Config'->new
delete $args{'cfg'}
'YAML::Tidy::Config'->new
Truth table66%2/3
A || B
A= delete $args{'cfg'}B= 'YAML::Tidy::Config'->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | partial => delete $args{partial}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 22 | cfg => $cfg, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 67802 | ▶ | sub cfg($self) { $self->{cfg} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cfg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 22505 | ▶ | sub partial($self) { $self->{partial} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
partial: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ▶ | sub tidy($self, $yaml) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tidy: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3037 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3037 | my @lines = split /\n/, $yaml, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3037 | my $tree = $self->_tree($yaml, \@lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3037 | $self->{tree} = $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3037 | $self->{lines} = \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\@lines], ['lines']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3037 | ▶ | if (@lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3024 | my $from = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3024 | ▶ | $self->_trimspaces(\$from, $tree) if $self->cfg->trimtrailing; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3024 | $self->_process(undef, $tree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3037 | $yaml = join "\n", @{ $self->{lines} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$yaml], ['yaml']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3037 | return $yaml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ▶ | sub _process($self, $parent, $node) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process: called CC=80 SCAR=44.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 22424 | ▶ | my $type = $node->{type} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'type'} || ''
MC/DC100%1/1
$node->{'type'} || ''
$node->{'type'}
Truth table100%2/2
A
A= $node->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # warn __PACKAGE__.':'.__LINE__.": ======== _process($parent, $node) $type\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 22424 | ▶ | if ($node->{flow}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 975 | $self->_process_flow($parent, $node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 975 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 21449 | my $level = $node->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 21449 | my $indent = $self->cfg->indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 21449 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 21449 | ▶ | return unless @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 21449 | ▶ | if ($level == -1 and $type eq 'DOC') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$level == -1 and $type eq "DOC"
MC/DC100%2/2
$level == -1 and $type eq "DOC"
$level == -1
$type eq "DOC"
Truth table100%3/3
A and B
A= $level == -1B= $type eq "DOC"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3347 | $self->_process_doc($parent, $node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 21449 | my $start = $node->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 21449 | my $indenttoplevelscalar = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 21449 | my $trimtrailing = $self->cfg->trimtrailing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 21449 | my $col = $node->indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 21449 | ▶ | my $lastcol = $parent ? $parent->indent : -99; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 21449 | my $realindent = $col - $lastcol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 21449 | my $startline = $node->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 21449 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 21449 | ▶ | unless (defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | die "Line $startline not found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 21449 | my $before = substr($line, 0, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 21449 | ▶ | if ($node->is_collection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10329 | ▶ | my $ignore_firstlevel = ($self->partial and $level == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->partial && $level == 0
MC/DC100%2/2
$self->partial && $level == 0
$self->partial
$level == 0
Truth table100%3/3
A && B
A= $self->partialB= $level == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 10329 | ▶ | if ($level < 0 or $ignore_firstlevel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$level < 0 or $ignore_firstlevel
MC/DC100%2/2
$level < 0 or $ignore_firstlevel
$level < 0
$ignore_firstlevel
Truth table100%3/3
A or B
A= $level < 0B= $ignore_firstlevel
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 6372 | for my $c (@{ $node->{children} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6696 | $self->_process($node, $c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6372 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3957 | ▶ | if ($level == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2274 | $indent = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3957 | ▶ | if ($type eq 'MAP') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2492 | ▶ | if ($before =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 317 | ▶ | if ($indent == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | $indent = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($type eq 'SEQ') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1465 | ▶ | if ($before =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 247 | ▶ | if ($indent == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | $indent = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1218 | ▶ | if ($parent->{type} eq 'MAP' and not $node->{index} % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parent->{"type"} eq "MAP" and not $node->{"index"} % 2
MC/DC100%2/2
$parent->{"type"} eq "MAP" and not $node->{"index"} % 2
$parent->{"type"} eq "MAP"
not $node->{"index"} % 2
Truth table100%3/3
A and not(B)
A= $parent->{"type"} eq "MAP"B= not $node->{"index"} % 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # zero indented sequence? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 370 | $indent = $self->cfg->indent_seq_in_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3957 | my $diff = $indent - $realindent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3957 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 588 | $self->_fix_indent($node, $diff, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 588 | $node->fix_node_indent($diff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3957 | for my $c (@{ $node->{children} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 12704 | $self->_process($node, $c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3957 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 11120 | ▶ | my $ignore_firstlevel = ($self->partial and $level == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->partial && $level == 0
MC/DC100%2/2
$self->partial && $level == 0
$self->partial
$level == 0
Truth table100%3/3
A && B
A= $self->partialB= $level == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 11120 | ▶ | if ($node->empty_scalar) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 282 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 10838 | ▶ | if ($node->{name} eq 'alias_event') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 261 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10577 | ▶ | if ($parent->{type} eq 'MAP' and ($node->{index} % 2 and not $node->multiline)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$parent->{"type"} eq "MAP" and ($node->{"index"} % 2 and not $node->multiline)
$node->{"index"} % 2 and not $node->multiline
MC/DC66%2/3
$parent->{"type"} eq "MAP" and ($node->{"index"} % 2 and not $node->multiline)
$parent->{"type"} eq "MAP"
$node->{"index"} % 2
not $node->multiline
Truth table75%3/4
A and B and not(C)
A= $parent->{"type"} eq "MAP"B= $node->{"index"} % 2C= not $node->multiline
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4395 | $self->_replace_quoting($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 4395 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6182 | my $new_indent = $parent->indent + $indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6182 | my $new_spaces = ' ' x $new_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 6182 | my ($anchor, $tag, $comments, $scalar) = $self->_find_scalar_start($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6182 | my $explicit_indent = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6182 | ▶ | if ($scalar->[2] =~ m/[>|]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 901 | my $l = $lines->[ $scalar->[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 901 | my ($ind) = substr($l, $scalar->[1]) =~ m/^[|>][+-]?([0-9]*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 901 | $explicit_indent = $ind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6182 | my $skipfirst = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 6182 | my $before = substr($line, 0, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6182 | ▶ | if ($before =~ tr/ \t//c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # same line as key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5311 | my $remove = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 5311 | ▶ | $before =~ s/([\t ]+)$/ / and $remove = -1 + length $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5311 | $node->open->{column} -= $remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5311 | ▶ | unless ($node->multiline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4140 | $node->close->{column} -= $remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5311 | $line = $before . substr($line, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5311 | $lines->[ $startline ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 5311 | $skipfirst = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 6182 | my $realstart = $scalar->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 6182 | ▶ | unless ($ignore_firstlevel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 6180 | for my $i ($startline .. $realstart) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6331 | my $line = $lines->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6331 | ▶ | if ($i == $startline and $col > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i == $startline and $col > 0
MC/DC100%2/2
$i == $startline and $col > 0
$i == $startline
$col > 0
Truth table100%3/3
A and B
A= $i == $startlineB= $col > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 5591 | my $before = substr($line, 0, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 5591 | ▶ | if ($before =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5311 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1020 | ▶ | unless ($line =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1020 | my $remove = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1020 | ▶ | $line =~ s/^( *)/$new_spaces/ and $remove = length($1) - length($new_spaces); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1020 | ▶ | if ($i == $startline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 869 | $node->open->{column} -= $remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 869 | ▶ | unless ($node->multiline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 409 | $node->close->{column} -= $remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1020 | $lines->[ $i] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # leave alone explicitly indented block scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6182 | ▶ | return if $explicit_indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 6027 | $startline = $realstart; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 6027 | my $endline = $node->realendline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$startline], ['startline']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$endline], ['endline']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6027 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6027 | my $realcol = $scalar->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6027 | $col = $realcol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6027 | my $nextline = $node->{nextline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | my $block = ($node->{style} eq YAML_LITERAL_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6027 | ▶ | or $node->{style} eq YAML_FOLDED_SCALAR_STYLE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$node->{'style'} eq 4 || $node->{'style'} eq 5
MC/DC100%2/2
$node->{'style'} eq 4 || $node->{'style'} eq 5
$node->{'style'} eq 4
$node->{'style'} eq 5
Truth table100%3/3
A || B
A= $node->{'style'} eq 4B= $node->{'style'} eq 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6027 | ▶ | if ($block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 746 | $startline++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 746 | ▶ | while ($startline < $endline and $lines->[ $startline ] !~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$startline < $endline and not $lines->[$startline] =~ tr/ //c
MC/DC100%2/2
$startline < $endline and not $lines->[$startline] =~ tr/ //c
$startline < $endline
not $lines->[$startline] =~ tr/ //c
Truth table100%3/3
A and not(B)
A= $startline < $endlineB= not $lines->[$startline] =~ tr/ //c
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 73 | ▶ | if ($trimtrailing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 68 | $self->_trim($startline, $startline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 73 | $startline++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 746 | ▶ | if ($nextline > $endline + 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 68 | $endline = $nextline - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 746 | my @slice = @$lines[$startline .. $endline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 746 | my ($sp) = $lines->[ $startline ] =~ m/^( *)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 746 | ▶ | if (not $ignore_firstlevel and length($sp) != $new_indent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not $ignore_firstlevel and length $sp != $new_indent
MC/DC100%2/2
not $ignore_firstlevel and length $sp != $new_indent
not $ignore_firstlevel
length $sp != $new_indent
Truth table100%3/3
not(A) and B
A= not $ignore_firstlevelB= length $sp != $new_indent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 373 | for my $line (@slice) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1179 | ▶ | unless (length $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 274 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 905 | ▶ | if ($line !~ tr/ //c and length($line) <= length($sp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $line =~ tr/ //c and length $line <= length $sp
MC/DC100%2/2
not $line =~ tr/ //c and length $line <= length $sp
not $line =~ tr/ //c
length $line <= length $sp
Truth table100%3/3
not(A) and B
A= not $line =~ tr/ //cB= length $line <= length $sp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 132 | ▶ | if ($trimtrailing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 124 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 132 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 773 | ▶ | if ($line =~ m/^( *)\#/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 42 | my $cindent = length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 42 | my $diff = $new_indent - length $sp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 42 | $cindent += $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 42 | ▶ | if ($diff > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 31 | $line = (' ' x $diff) . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | elsif ($diff < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 11 | ▶ | if ($cindent < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $cindent = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 11 | $new_spaces = ' ' x $cindent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | $line =~ s/^ */$new_spaces/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 731 | $line =~ s/^$sp/$new_spaces/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 373 | @$lines[$startline .. $endline ] = @slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | elsif ($trimtrailing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 348 | for my $line (@slice) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 917 | ▶ | if ($line !~ tr/ //c and length($line) <= length($sp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $line =~ tr/ //c and length $line <= length $sp
MC/DC100%2/2
not $line =~ tr/ //c and length $line <= length $sp
not $line =~ tr/ //c
length $line <= length $sp
Truth table100%3/3
not(A) and B
A= not $line =~ tr/ //cB= length $line <= length $sp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 228 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 348 | @$lines[$startline .. $endline ] = @slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ▶ | elsif ($node->{style} == YAML_PLAIN_SCALAR_STYLE or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$node->{"style"} == 1 or $node->{"style"} == 2 or $node->{"style"} == 3
$node->{"style"} == 1 or $node->{"style"} == 2
MC/DC0%0/3
$node->{"style"} == 1 or $node->{"style"} == 2 or $node->{"style"} == 3
$node->{"style"} == 1
$node->{"style"} == 2
$node->{"style"} == 3
Truth table75%3/4
A or B or C
A= $node->{"style"} == 1B= $node->{"style"} == 2C= $node->{"style"} == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | $node->{style} == YAML_SINGLE_QUOTED_SCALAR_STYLE or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $node->{style} == YAML_DOUBLE_QUOTED_SCALAR_STYLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 5281 | ▶ | if ($node->empty_scalar) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 5281 | my $remove = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 5281 | ▶ | if (not $skipfirst or $node->multiline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $skipfirst or $node->multiline
MC/DC100%2/2
not $skipfirst or $node->multiline
not $skipfirst
$node->multiline
Truth table100%3/3
not(A) or B
A= not $skipfirstB= $node->multiline
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1141 | my $startline = $startline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1141 | ▶ | $startline++ if $skipfirst; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1141 | $endline = $node->close->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1141 | ▶ | return if $startline >= @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1141 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1141 | my ($sp) = $line =~ m/^( *)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1141 | ▶ | if ($ignore_firstlevel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | $new_indent = length $sp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $new_spaces = ' ' x $new_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1141 | my @slice = @$lines[$startline .. $endline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1141 | ▶ | if ($level == 0 and not $indenttoplevelscalar) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level == 0 and not $indenttoplevelscalar
MC/DC0%0/2
$level == 0 and not $indenttoplevelscalar
$level == 0
not $indenttoplevelscalar
Truth table66%2/3
A and not(B)
A= $level == 0B= not $indenttoplevelscalar
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $new_spaces = ' ' x ($new_indent - $indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1141 | for my $line (@slice) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 2048 | ▶ | if ($line =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1747 | ▶ | $line =~ s/^([\t ]*)/$new_spaces/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | and $remove = length($1) - length($new_spaces); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1141 | $node->close->{column} -= $remove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1141 | @$lines[$startline .. $endline ] = @slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 5281 | ▶ | if (not $node->multiline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4549 | $self->_replace_quoting($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | my $RE_INT_CORE = qr{^([+-]?(?:[0-9]+))$}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | my $RE_FLOAT_CORE = qr{^([+-]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][+-]?[0-9]+)?)$}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 7 | my $RE_INT_OCTAL = qr{^0o([0-7]+)$}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 7 | my $RE_INT_HEX = qr{^0x([0-9a-fA-F]+)$}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 7 | my @null = (qw/ null NULL Null ~ /, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 7 | my @true = qw/ true TRUE True /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 7 | my @false = qw/ false FALSE False /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | my @inf = qw/ .inf .Inf .INF +.inf +.Inf +.INF -.inf -.Inf -.INF /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 7 | my @nan = qw/ .nan .NaN .NAN /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | my @re = ($RE_INT_CORE, $RE_INT_OCTAL, $RE_INT_HEX, $RE_FLOAT_CORE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | my $re = join '|', @re; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 7 | my @all = (@null, @true, @false, @inf, @nan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ▶ | sub _replace_quoting($self, $node) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replace_quoting: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 11294 | ▶ | return if $node->{tag}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 10419 | my $default_style = $self->cfg->default_scalar_style; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # single line flow scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 10419 | ▶ | if (defined $default_style and $node->{style} != $default_style) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $default_style and $node->{"style"} != $default_style
MC/DC100%2/2
defined $default_style and $node->{"style"} != $default_style
defined $default_style
$node->{"style"} != $default_style
Truth table100%3/3
A and B
A= defined $default_styleB= $node->{"style"} != $default_style
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1508 | my ($changed, $new_string, $new_style) = $self->_change_style($node, $default_style); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1508 | ▶ | if ($changed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1344 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1344 | my $line = $lines->[ $node->open->{line} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1344 | my ($from, $to) = ($node->open->{column}, $node->close->{column}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1344 | ▶ | if (defined $node->{anchor} or $node->{tag}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $node->{"anchor"} or $node->{"tag"}
MC/DC50%1/2
defined $node->{"anchor"} or $node->{"tag"}
defined $node->{"anchor"}
$node->{"tag"}
Truth table66%2/3
A or B
A= defined $node->{"anchor"}B= $node->{"tag"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 58 | my ($anchor, $tag, $comments, $scalar) = $self->_find_scalar_start($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 58 | $from = $scalar->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1344 | substr($line, $from, $to - $from, $new_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1344 | my $diff = length($new_string) - ($to - $from); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1344 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1317 | $self->{tree}->_move_columns($node->open->{line}, $node->close->{column} + 1, $diff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1344 | $node->{style} = $new_style; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1344 | $node->close->{column} += $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1344 | $lines->[ $node->open->{line} ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | ▶ | sub _change_style($self, $node, $style) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_change_style: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1508 | my $value = $node->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1508 | ▶ | if (grep { $_ eq $value } @all or $value =~ m/($re)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
grep {$_ eq $value;} @all or $value =~ /($re)/u
MC/DC100%2/2
grep {$_ eq $value;} @all or $value =~ /($re)/u
grep {$_ eq $value;} @all
$value =~ /($re)/u
Truth table100%3/3
A or B
A= grep {$_ eq $value;} @allB= $value =~ /($re)/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # leave me alone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 150 | ▶ | if ($node->{style} eq YAML_PLAIN_SCALAR_STYLE or $style eq YAML_PLAIN_SCALAR_STYLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node->{"style"} eq 1 or $style eq 1
MC/DC100%2/2
$node->{"style"} eq 1 or $style eq 1
$node->{"style"} eq 1
$style eq 1
Truth table100%3/3
A or B
A= $node->{"style"} eq 1B= $style eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 149 | return (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1359 | my $emit = $self->_emit_value($value, $style); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1359 | chomp $emit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1359 | ▶ | return (0) if $emit =~ tr/\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1359 | my $first = substr($emit, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1359 | ▶ | my $new_style = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $first eq "'" ? YAML_SINGLE_QUOTED_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | : $first eq '"' ? YAML_DOUBLE_QUOTED_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | : YAML_PLAIN_SCALAR_STYLE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1359 | ▶ | if ($new_style eq $style) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1344 | return (1, $emit, $new_style); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 15 | return (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | ▶ | sub _emit_value($self, $value, $style) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1359 | my $options = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1359 | my $events = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | { name => 'stream_start_event' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | { name => 'document_start_event', implicit => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | { name => 'scalar_event', style => $style, value => $value }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { name => 'document_end_event', implicit => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | { name => 'stream_end_event' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1359 | return YAML::LibYAML::API::XS::emit_string_events($events, $options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ▶ | sub _process_doc($self, $parent, $node) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_doc: called CC=25 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3347 | DEBUG and say STDERR "_process_doc($node)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 3347 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3347 | my $open = $node->open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 3347 | my $close = $node->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3347 | ▶ | if ($node->open->{implicit} and $self->cfg->addheader and not $self->partial) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$node->open->{"implicit"} and $self->cfg->addheader and not $self->partial
$node->open->{"implicit"} and $self->cfg->addheader
MC/DC66%2/3
$node->open->{"implicit"} and $self->cfg->addheader and not $self->partial
$node->open->{"implicit"}
$self->cfg->addheader
not $self->partial
Truth table75%3/4
A and B and not(C)
A= $node->open->{"implicit"}B= $self->cfg->addheaderC= not $self->partial
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # add --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 339 | splice @$lines, $open->{start}->{line}, 0, '---'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 339 | $self->{tree}->fix_lines($open->{start}->{line}, +1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 339 | $open->{start}->{line}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 339 | $open->{end}->{line}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 339 | $open->{end}->{column} = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 339 | $open->{implicit} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 339 | DEBUG and say STDERR "$node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ▶ | elsif ($node->{index} == 1 and not $open->{implicit} and $self->cfg->removeheader and not $self->partial) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$node->{"index"} == 1 and not $open->{"implicit"} and $self->cfg->removeheader and not $self->partial
$node->{"index"} == 1 and not $open->{"implicit"} and $self->cfg->removeheader
$node->{"index"} == 1 and not $open->{"implicit"}
MC/DC75%3/4
$node->{"index"} == 1 and not $open->{"implicit"} and $self->cfg->removeheader and not $self->partial
$node->{"index"} == 1
not $open->{"implicit"}
$self->cfg->removeheader
not $self->partial
Truth table80%4/5
A and not(B) and C and not(D)
A= $node->{"index"} == 1B= not $open->{"implicit"}C= $self->cfg->removeheaderD= not $self->partial
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # remove first --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 159 | my $child = $node->{children}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 159 | ▶ | if ($open->{version_directive} or $open->{tag_directives} or not $child->is_collection and $child->empty_scalar) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$open->{"version_directive"} or $open->{"tag_directives"} or not $child->is_collection and $child->empty_scalar
$open->{"version_directive"} or $open->{"tag_directives"}
not $child->is_collection and $child->empty_scalar
MC/DC100%4/4
$open->{"version_directive"} or $open->{"tag_directives"} or not $child->is_collection and $child->empty_scalar
$open->{"version_directive"}
$open->{"tag_directives"}
not $child->is_collection
$child->empty_scalar
Truth table100%5/5
A or B or not(C) and D
A= $open->{"version_directive"}B= $open->{"tag_directives"}C= not $child->is_collectionD= $child->empty_scalar
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 138 | my $startline = $open->{start}->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 138 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 138 | ▶ | if ($line =~ m/^---[ \t]*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 99 | splice @$lines, $startline, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 99 | $self->{tree}->fix_lines($open->{start}->{line}+1, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 99 | DEBUG and say STDERR "$node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 99 | $open->{implicit} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | elsif ($line =~ s/^---[ \t]+(?=#)//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $lines->[ $startline ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | DEBUG and say STDERR "$node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $open->{implicit} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 3347 | ▶ | if ($close->{implicit} and $self->cfg->addfooter and not $self->partial) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$close->{"implicit"} and $self->cfg->addfooter and not $self->partial
$close->{"implicit"} and $self->cfg->addfooter
MC/DC66%2/3
$close->{"implicit"} and $self->cfg->addfooter and not $self->partial
$close->{"implicit"}
$self->cfg->addfooter
not $self->partial
Truth table75%3/4
A and B and not(C)
A= $close->{"implicit"}B= $self->cfg->addfooterC= not $self->partial
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # add ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 531 | splice @$lines, $close->{start}->{line}, 0, '...'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 531 | $self->{tree}->fix_lines($close->{start}->{line}, +1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 531 | $close->{end}->{column} = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 531 | $close->{implicit} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 531 | DEBUG and say STDERR "$node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ▶ | elsif (not $close->{implicit} and $self->cfg->removefooter and not $self->partial) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
not $close->{"implicit"} and $self->cfg->removefooter and not $self->partial
not $close->{"implicit"} and $self->cfg->removefooter
MC/DC66%2/3
not $close->{"implicit"} and $self->cfg->removefooter and not $self->partial
not $close->{"implicit"}
$self->cfg->removefooter
not $self->partial
Truth table75%3/4
not(A) and B and not(C)
A= not $close->{"implicit"}B= $self->cfg->removefooterC= not $self->partial
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # remove ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 27 | my $next = $parent->{children}->[ $node->{index} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 27 | ▶ | if ($next and ($next->open->{version_directive} or $next->open->{tag_directives})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$next and $next->open->{"version_directive"} || $next->open->{"tag_directives"}
$next->open->{"version_directive"} or $next->open->{"tag_directives"}
MC/DC0%0/3
$next and $next->open->{"version_directive"} || $next->open->{"tag_directives"}
$next
$next->open->{"version_directive"}
$next->open->{"tag_directives"}
Truth table25%1/4
A and B or C
A= $nextB= $next->open->{"version_directive"}C= $next->open->{"tag_directives"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | my $startline = $close->{start}->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 12 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 12 | ▶ | if ($line =~ m/^\.\.\.[ \t]*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 12 | splice @$lines, $startline, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 12 | $self->{tree}->fix_lines($close->{start}->{line}+1, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 12 | $close->{implicit} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | elsif ($line =~ s/^\.\.\.[ \t]+(?=#)//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $lines->[ $startline ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $close->{implicit} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 12 | DEBUG and say STDERR "$node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ▶ | sub _trimspaces($self, $from, $node) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trimspaces: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 24415 | ▶ | if ($node->is_collection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 11171 | my $level = $node->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 11171 | for my $c (@{ $node->{children} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 21559 | $self->_trimspaces($from, $c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 11171 | ▶ | if ($level == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 6017 | $self->_trim($$from, $node->end->{line}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | elsif (defined $node->{style}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # Only spaces in block scalars must be left alone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 12988 | ▶ | if ($node->{style} eq YAML_LITERAL_SCALAR_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node->{"style"} eq 4 or $node->{"style"} eq 5
MC/DC100%2/2
$node->{"style"} eq 4 or $node->{"style"} eq 5
$node->{"style"} eq 4
$node->{"style"} eq 5
Truth table100%3/3
A or B
A= $node->{"style"} eq 4B= $node->{"style"} eq 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | or $node->{style} eq YAML_FOLDED_SCALAR_STYLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 847 | my ($anchor, $tag, $comments, $scalar) = $self->_find_scalar_start($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 847 | $self->_trim($$from, $scalar->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 847 | $$from = $node->end->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 3996 | ▶ | sub _process_flow($self, $parent, $node, $block_indent = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_flow: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 3996 | ▶ | return unless $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3996 | my $level = $node->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3996 | ▶ | my $flow = $node->{flow} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'flow'} || 0
MC/DC0%0/1
$node->{'flow'} || 0
$node->{'flow'}
Truth table50%1/2
A
A= $node->{'flow'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 3996 | ▶ | $block_indent //= $parent->indent + $self->cfg->indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$block_indent //= $parent->indent + $self->cfg->indent
MC/DC0%0/2
$block_indent //= $parent->indent + $self->cfg->indent
$block_indent
$parent->indent + $self->cfg->indent
Truth table66%2/3
A //= B
A= $block_indentB= $parent->indent + $self->cfg->indent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 3996 | ▶ | $block_indent = 0 if $level == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 3996 | ▶ | unless ($node->is_collection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 2591 | $self->_process_flow_scalar($parent, $node, $block_indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2591 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1405 | ▶ | if ($parent->{type} eq 'MAP' and $node->{index} % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parent->{"type"} eq "MAP" and $node->{"index"} % 2
MC/DC100%2/2
$parent->{"type"} eq "MAP" and $node->{"index"} % 2
$parent->{"type"} eq "MAP"
$node->{"index"} % 2
Truth table100%3/3
A and B
A= $parent->{"type"} eq "MAP"B= $node->{"index"} % 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 97 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1308 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 1308 | my $startline = $node->start->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1308 | my $end = $node->end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1308 | my $endline = $end->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1308 | my $before = substr($lines->[ $startline ], 0, $node->start->{column}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1308 | ▶ | if ($before =~ tr/ \t//c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 919 | $startline++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1308 | my @lines = ($startline .. $node->open->{end}->{line}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 1308 | my $before_end = substr($lines->[ $endline ], 0, $end->{column} - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1308 | ▶ | unless ($before_end =~ tr/ \t//c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 294 | push @lines, $endline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1308 | for my $i (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 699 | my $new_spaces = ' ' x $block_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 699 | $lines->[ $i ] =~ s/^([ \t]*)/$new_spaces/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 699 | my $old = length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 699 | $node->_fix_flow_indent(line => $i, diff => $block_indent - $old); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1308 | for my $c (@{ $node->{children} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 3021 | $self->_process_flow($node, $c, $block_indent + $self->cfg->indent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ▶ | sub _process_flow_scalar($self, $parent, $node, $block_indent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_flow_scalar: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2591 | ▶ | if ($node->empty_scalar) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 128 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2463 | my $startline = $node->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2463 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2463 | my $line = $lines->[ $startline ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2463 | my $col = $node->start->{column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2463 | my $before = substr($line, 0, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2463 | ▶ | if ($before =~ tr/ \t//c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2101 | $startline++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2463 | my $endline = $node->end->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 2463 | for my $i ($startline .. $endline) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 466 | my $line = $lines->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 466 | my $new_spaces = ' ' x $block_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 466 | $line =~ s/^([ \t]*)/$new_spaces/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 466 | my $old = length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 466 | ▶ | if ($block_indent != $old) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 415 | $self->{tree}->_fix_flow_indent(line => $i, diff => $block_indent - $old); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 466 | $lines->[ $i ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2463 | ▶ | if (not $node->multiline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2359 | $self->_check_adjacency($node, $parent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 2359 | ▶ | if ($node->{name} eq 'scalar_event') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2350 | $self->_replace_quoting($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | ▶ | sub _check_adjacency($self, $node, $parent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_adjacency: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2359 | ▶ | return unless $node->{flow}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2359 | ▶ | return unless $node->is_mapping_value($parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # allowed: "foo":bar, "foo":*alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # not allowed: foo:bar, foo:*alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 749 | my $prev = $parent->sibling($node, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 749 | my $tidy_adjacency = $self->cfg->adjacency; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 749 | ▶ | if (not $prev->is_collection and not $prev->is_quoted) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev->is_collection or $prev->is_quoted
MC/DC100%2/2
$prev->is_collection or $prev->is_quoted
$prev->is_collection
$prev->is_quoted
Truth table100%3/3
A or B
A= $prev->is_collectionB= $prev->is_quoted
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 527 | $tidy_adjacency = 0; # adjacency would be invalid here | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 749 | my $start = $node->open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 749 | my $adjacent = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 749 | my $line = $self->{lines}->[ $start->{line} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 749 | ▶ | if ($start->{column} > 0 and substr($line, $start->{column} - 1, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$start->{"column"} > 0 and substr($line, $start->{"column"} - 1, 1) eq ":"
MC/DC50%1/2
$start->{"column"} > 0 and substr($line, $start->{"column"} - 1, 1) eq ":"
$start->{"column"} > 0
substr($line, $start->{"column"} - 1, 1) eq ":"
Truth table66%2/3
A and B
A= $start->{"column"} > 0B= substr($line, $start->{"column"} - 1, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 56 | $adjacent = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 749 | ▶ | return unless defined $tidy_adjacency; # keep as is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 527 | ▶ | if ($tidy_adjacency) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | die "Not implemented yet: enforce adjacency"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 527 | ▶ | return unless $adjacent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | substr($line, $start->{column}, 0, ' '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | $self->{tree}->_move_columns($start->{line}, $start->{column} + 1, +1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | $self->{lines}->[ $start->{line} ] = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ▶ | sub _find_scalar_start($self, $node) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_scalar_start: called CC=12 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # warn __PACKAGE__.':'.__LINE__.": ========= _find_scalar_start $node\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 7087 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 7087 | my $from = $node->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 7087 | my $to = $node->realendline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 7087 | my $col = $node->indent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 7087 | my $end = $node->end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 7087 | my $endcol = $end->{column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 7087 | my @slice = @$lines[ $from .. $to ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 7087 | my $anchor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | my $tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 7087 | my @comments; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 7087 | my $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 7087 | my $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 7087 | for my $i (0 .. $#slice) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 7253 | my $line = $slice[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 7253 | ▶ | my $f = $i == 0 ? $col : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 7253 | ▶ | my $t = $i == $#slice ? ($endcol || length($line)) : length($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$endcol or length $line
MC/DC0%0/2
$endcol or length $line
$endcol
length $line
Truth table33%1/3
A or B
A= $endcolB= length $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 7253 | my $part = substr($line, $f, $t - $f); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 7253 | ▶ | if ($part =~ m/^ *(\#.*)$/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $comment = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my $pos1 = length($line) - length($comment); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | push @comments, [$i + $from, $pos1, $comment]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 7253 | my $cur; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 7253 | ▶ | while ($part =~ m/\G\s*([&!])(\S*)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1354 | my $type = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1354 | my $name = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1354 | $cur = pos $part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1354 | my $pos = $cur - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1354 | my $pos1 = $pos - length $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1354 | my $prop = substr($part, $pos1, 1+ length $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1354 | ▶ | if ($type eq '&') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 501 | $anchor = [$i + $from, $pos1 + $f, $prop]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | elsif ($type eq '!') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 853 | $tag = [$i + $from, $pos1 + $f, $prop]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 7253 | pos($part) = $cur; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 7253 | ▶ | if ($part =~ m/\G *(\#.*)$/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $comment = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $cur = pos $part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $pos1 = length($line) - length($comment); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | push @comments, [$i + $from, $pos1, $comment]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 7253 | pos($part) = $cur; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 7253 | ▶ | if ($part =~ m/\G *(\S)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 6911 | $scalar = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 6911 | my $pos1 = (pos $part) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 6911 | $scalar = [$i + $from, $pos1 + $f, $scalar]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 6911 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 7087 | ▶ | $scalar ||= [$to, length($slice[ -1 ]), '']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$scalar ||= [$to, length $slice[-1], ""]
MC/DC100%1/1
$scalar ||= [$to, length $slice[-1], ""]
$scalar
Truth table100%2/2
A
A= $scalar
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$scalar], ['scalar']); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 7087 | return ($anchor, $tag, \@comments, $scalar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | ▶ | sub _trim($self, $from, $to) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 6932 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 6932 | for my $line (@$lines[ $from .. $to ]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 32434 | $line =~ s/[\t ]+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ▶ | sub _fix_indent($self, $node, $fix, $offset) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fix_indent: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 588 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$offset ||= 0
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 588 | my $startline = $node->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 588 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 588 | my $endline = $node->realendline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 588 | my @slice = @$lines[$startline .. $endline]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 588 | for my $line (@slice) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 1449 | ▶ | next unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 1430 | ▶ | if ($fix < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 953 | my $offset = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 953 | my $fix = -$fix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 953 | ▶ | if ($offset > length $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | $offset = -1 + length $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 953 | ▶ | if ($line =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 953 | ▶ | if ($line =~ m/^ *\#/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 18 | $line =~ s/ {1,$fix}//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 18 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | $line =~ s/ {1,$fix}//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 935 | my $before = substr($line, 0, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 935 | $before =~ s/ {$fix,$fix}$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 935 | $line = $before . substr($line, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 477 | ▶ | unless ($line =~ tr/ //c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 477 | substr($line, $offset, 0, ' ' x $fix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 588 | @$lines[$startline .. $endline] = @slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | ▶ | sub _tree($self, $yaml, $lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tree: called CC=18 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 3037 | my $events = $self->_parse($yaml); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 3037 | $self->{events} = $events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 3037 | my $first = shift @$events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 3037 | my $end = pop @$events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 3037 | $_->{level} = -1 for ($first, $end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 3037 | $first->{id} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 3037 | _pp($first) if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 3037 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 3037 | my $level = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 3037 | my $docs = YAML::Tidy::Node::Collection->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | type => 'STR', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | children => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | indent => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | line => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | level => $level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | start => YAML::Tidy::Node::Collection->new(%$first), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | end => YAML::Tidy::Node::Collection->new(%$end), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 3037 | my $ref = $docs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 3037 | my $id = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 3037 | my $flow = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 3037 | for my $i (0 .. $#$events) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 31507 | my $event = $events->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 31507 | my $name = $event->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 31507 | $id++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 31507 | my $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 31507 | ▶ | if ($name =~ m/document_start/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 3347 | $type = 'DOC'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | elsif ($name =~ m/sequence_start/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2203 | $type = 'SEQ'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | elsif ($name =~ m/mapping_start/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 3224 | $type = 'MAP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 31507 | $event->{id} = $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 31507 | ▶ | if ($name =~ m/_start_event/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 8774 | $event->{level} = $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 8774 | ▶ | if ($name eq 'sequence_start_event') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # inconsistency in libyaml events? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2203 | my $col = $event->{end}->{column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 2203 | ▶ | if ($col > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 1469 | my $line = $lines->[ $event->{end}->{line} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 1469 | my $chr = substr($line, $col - 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 1469 | ▶ | if ($chr eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 121 | $event->{end}->{column}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 8774 | ▶ | if ($flow or ($event->{style} // -1) == YAML_FLOW_SEQUENCE_STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition90%9/10
$flow or ($event->{"style"} // -1) == 2 or ($event->{"style"} // -1) == 2
$flow or ($event->{"style"} // -1) == 2
$event->{"style"} // -1
$event->{"style"} // -1
MC/DC66%2/3
$flow or ($event->{"style"} // -1) == 2 or ($event->{"style"} // -1) == 2
$flow
$event->{"style"}
$event->{"style"}
Truth table75%3/4
A or B or C
A= $flowB= $event->{"style"}C= $event->{"style"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | or ($event->{style} // -1) == YAML_FLOW_MAPPING_STYLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 1469 | $flow++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 8774 | my $node = YAML::Tidy::Node::Collection->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | children => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | level => $level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | start => $event, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | flow => $flow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 8774 | push @{ $ref->{children} }, $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 8774 | $ref->{elements}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 8774 | $node->{index} = $ref->{elements}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 8774 | push @stack, $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 8774 | $ref = $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 8774 | $level++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | elsif ($name =~ m/_end_event/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 8774 | my $last = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 8774 | $ref->{end} = $event; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 8774 | $ref = $last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 8774 | $level--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 8774 | $event->{level} = $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 8774 | ▶ | $flow-- if $flow; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 13959 | $event = YAML::Tidy::Node::Scalar->new(%$event, flow => $flow); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 13959 | $ref->{elements}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 13959 | $event->{index} = $ref->{elements}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 13959 | $event->{level} = $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 13959 | push @{ $ref->{children} }, $event; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 31507 | $event->{nextline} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 31507 | ▶ | if ($i < $#$events) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 28509 | my $next = $events->[ $i + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 28509 | my $nextline = $next->{start}->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 28509 | $event->{nextline} = $nextline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 31507 | _pp($event) if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 3037 | $end->{id} = $id + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 3037 | _pp($end) if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 3037 | $self->{tree} = $docs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 3037 | return $docs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | ▶ | sub _parse($self, $yaml) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 6071 | my @events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 6071 | YAML::LibYAML::API::XS::parse_events($yaml, \@events); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 6067 | return \@events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | ▶ | sub _pp($event) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pp: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my $name = $event->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my $level = $event->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $name =~ s/_event$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | my $fmt = '%2d %-10s) <L %2d C %2d> <L %2d C %2d> %-14s'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | my $indent = $level*2+2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | my $lstr = (' ' x $indent) . $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | my @args = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | $event->{id}, $lstr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | $event->{start}->{line}, $event->{start}->{column}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | $event->{end}->{line}, $event->{end}->{column}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | $name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | if ($name =~ m/scalar|alias/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | local $Data::Dumper::Useqq = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my $str = Data::Dumper->Dump([$event->{value}], ['value']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | chomp $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | $str =~ s/^\$value = //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | $fmt .= " %s"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | push @args, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | elsif ($name =~ m/end/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $fmt .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | printf $fmt, @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | ▶ | sub _debug_lines($self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug_lines: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | say "===================================="; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | say for @{ $self->{lines} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | say "===================================="; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 6068 | ▶ | sub highlight($self, $yaml, $type = 'ansi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
highlight: called CC=6 SCAR=19.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 6068 | my ($error, $tokens) = YAML::PP::Parser->yaml_to_tokens(string => $yaml); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 6068 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 213 | $tokens = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 213 | my @lines = split m/(?<=\n)/, $yaml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 213 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 641 | ▶ | if ($line =~ s/( +\n)//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | push @$tokens, { value => $line, name => 'PLAIN' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | push @$tokens, { value => $1, name => 'TRAILING_SPACE' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 641 | push @$tokens, { value => $line, name => 'PLAIN' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 6068 | ▶ | if ($type eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | return YAML::PP::Highlight->htmlcolored($tokens); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 6068 | return YAML::PP::Highlight->ansicolored($tokens); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||