| 1 | package Config::IOD::Document; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | #use Carp; # avoided to shave a bit of startup time | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use Config::IOD::Constants qw(:ALL); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 16 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 11 | 16 | our $DATE = '2022-05-02'; # DATE | |||||||||||||||||||||||||||||||
| 12 | 16 | our $DIST = 'Config-IOD'; # DIST | |||||||||||||||||||||||||||||||
| 13 | 16 | our $VERSION = '0.353'; # VERSION | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 107 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=13.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 16 | 107 | my ($class, %attrs) = @_; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 107 | ▶ | if (!$attrs{_parsed}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 19 | 0 | $attrs{_parsed} = []; | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | 107 | ▶ | if (!$attrs{_parser}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 22 | 0 | require Config::IOD; | |||||||||||||||||||||||||||||||
| 23 | 0 | $attrs{_parser} = Config::IOD->new; | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 107 | bless \%attrs, $class; | |||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub empty { | ||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 31 | 1 | $self->_discard_cache; | |||||||||||||||||||||||||||||||
| 32 | 1 | $self->{_parsed} = []; | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | # all _validate_*() methods return ($err_msg, $validated_val) | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 46 | ▶ | sub _validate_section { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_section: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 38 | 46 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 39 | 46 | $name =~ s/\A\s+//; | |||||||||||||||||||||||||||||||
| 40 | 46 | $name =~ s/\s+\z//; | |||||||||||||||||||||||||||||||
| 41 | 46 | ▶ | if (!length($name)) { return ("Section name must be non-zero string") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 45 | ▶ | if ($name =~ /\R|\]/) { return ("Section name must not contain ] or newline") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 43 | return ("", $name); | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 25 | ▶ | sub _validate_key { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_key: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 47 | 25 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 48 | 25 | $name =~ s/\A\s+//; | |||||||||||||||||||||||||||||||
| 49 | 25 | $name =~ s/\s+\z//; | |||||||||||||||||||||||||||||||
| 50 | 25 | ▶ | if (!length($name)) { return ("Key name must be non-zero string") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 24 | ▶ | if ($name =~ /\R|=/) { return ("Key name must not contain = or newline") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 22 | ▶ | if ($name =~ /\A(?:;|#|\[)/) { return ("Key name must not start with ;, #, [") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 19 | return ("", $name); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 17 | ▶ | sub _validate_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 57 | 17 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||
| 58 | 17 | $value =~ s/\s+\z//; | |||||||||||||||||||||||||||||||
| 59 | 17 | ▶ | if ($value =~ /\R/) { return ("Value must not contain newline") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 15 | return ("", $value); | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | sub _validate_comment { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_comment: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 64 | 2 | my ($self, $comment) = @_; | |||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | if ($comment =~ /\R/) { return ("Comment must not contain newline") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 1 | return ("", $comment); | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | sub _validate_linum { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_linum: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 70 | 5 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | if ($value < 1) { return ("linum must be at least 1") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | if ($value > @{$self->{_parsed}}) { return ("linum must not be larger than number of document's lines") } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 3 | return ("", $value); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _blank_line { | ||||||||||||||||||||||||||||||
|
Subroutine
_blank_line: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 77 | 0 | ["B", "\n"]; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | # cache is used for get_value() and get_raw_value() to avoid re-scanning the | ||||||||||||||||||||||||||||||||
| 81 | # files on every invocation. but whenever one of document-modifying methods is | ||||||||||||||||||||||||||||||||
| 82 | # called, we discard the cache | ||||||||||||||||||||||||||||||||
| 83 | 25 | ▶ | sub _discard_cache { | ||||||||||||||||||||||||||||||
|
Subroutine
_discard_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 84 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||
| 85 | 25 | delete $self->{_dump_cache}; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 21 | ▶ | sub dump { | ||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=26 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 89 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||
| 90 | 21 | my $opts; | |||||||||||||||||||||||||||||||
| 91 | 21 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 0 | $opts = shift; | |||||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||||||
| 94 | 21 | $opts = {}; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 21 | my $parser = $self->{_parser}; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 21 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 100 | 21 | my $merge; | |||||||||||||||||||||||||||||||
| 101 | 21 | my $cur_section = $parser->{default_section}; | |||||||||||||||||||||||||||||||
| 102 | 21 | my $res = {}; | |||||||||||||||||||||||||||||||
| 103 | 21 | my $arrayified = {}; | |||||||||||||||||||||||||||||||
| 104 | 21 | my $num_seen_section_lines = 0; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | my $_merge = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | return if $cur_section eq $merge; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | die "IOD document:$linum: Can't merge section '$merge' to ". | ||||||||||||||||||||||||||||||||
| 109 | "'$cur_section': Section '$merge' not seen yet" | ||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | unless exists $res->{$merge}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 2 | for my $k (keys %{ $res->{$merge} }) { | |||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | $res->{$cur_section}{$k} //= $res->{$merge}{$k}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$res->{$cur_section}{$k} //= $res->{$merge}{$k}
MC/DC0%0/2
$res->{$cur_section}{$k} //= $res->{$merge}{$k}
$res->{$cur_section}{$k}
$res->{$merge}{$k}
Truth table66%2/3
A //= B
A= $res->{$cur_section}{$k}B= $res->{$merge}{$k}
| |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | 21 | }; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | # TMP HACK. for _decode_expr, this is currently rather hackish because | ||||||||||||||||||||||||||||||||
| 117 | # Config::IOD::Base expects some state in $parser | ||||||||||||||||||||||||||||||||
| 118 | 21 | ▶ | local $parser->{_res} = $res if $parser->{enable_expr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 119 | 21 | ▶ | local $parser->{_cur_section} = $cur_section if $parser->{enable_expr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 21 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 122 | 61 | $linum++; | |||||||||||||||||||||||||||||||
| 123 | 61 | ▶ | next if defined($opts->{linum_start}) && $linum < $opts->{linum_start}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
MC/DC0%0/2
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
defined $opts->{"linum_start"}
$linum < $opts->{"linum_start"}
Truth table33%1/3
A and B
A= defined $opts->{"linum_start"}B= $linum < $opts->{"linum_start"}
| |||||||||||||||||||||||||||||||||
| 124 | 61 | ▶ | next if defined($opts->{linum_end} ) && $linum > $opts->{linum_end}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
MC/DC0%0/2
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
defined $opts->{"linum_end"}
$linum > $opts->{"linum_end"}
Truth table33%1/3
A and B
A= defined $opts->{"linum_end"}B= $linum > $opts->{"linum_end"}
| |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 61 | my $type = $line->[COL_TYPE]; | |||||||||||||||||||||||||||||||
| 127 | 61 | ▶ | if ($type eq 'D') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 128 | 7 | my $directive = $line->[COL_D_DIRECTIVE]; | |||||||||||||||||||||||||||||||
| 129 | 7 | ▶ | if ($directive eq 'merge') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 4 | my $args = $parser->_parse_command_line( | |||||||||||||||||||||||||||||||
| 131 | $line->[COL_D_ARGS_RAW]); | ||||||||||||||||||||||||||||||||
| 132 | 4 | ▶ | if (!defined($args)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | die "IOD document:$linum: Invalid arguments syntax '". | |||||||||||||||||||||||||||||||
| 134 | $line->[COL_D_ARGS_RAW]."'"; | ||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | $merge = @$args ? $args->[0] : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | } # ignore the other directives | ||||||||||||||||||||||||||||||||
| 138 | } elsif ($type eq 'S') { | ||||||||||||||||||||||||||||||||
| 139 | 9 | $num_seen_section_lines++; | |||||||||||||||||||||||||||||||
| 140 | # merge previous section | ||||||||||||||||||||||||||||||||
| 141 | 9 | ▶ | $_merge->() if defined($merge) && $num_seen_section_lines > 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $merge and $num_seen_section_lines > 1
MC/DC50%1/2
defined $merge and $num_seen_section_lines > 1
defined $merge
$num_seen_section_lines > 1
Truth table66%2/3
A and B
A= defined $mergeB= $num_seen_section_lines > 1
| |||||||||||||||||||||||||||||||||
| 142 | 9 | $cur_section = $line->[COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | $parser->{_cur_section} = $cur_section if $parser->{enable_expr}; #TMP HACK | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | 9 | ▶ | $res->{$cur_section} //= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->{$cur_section} //= {}
MC/DC0%0/1
$res->{$cur_section} //= {}
$res->{$cur_section}
Truth table50%1/2
A
A= $res->{$cur_section}
| |||||||||||||||||||||||||||||||||
| 145 | } elsif ($type eq 'K') { | ||||||||||||||||||||||||||||||||
| 146 | # the common case is that value are not decoded or | ||||||||||||||||||||||||||||||||
| 147 | # quoted/bracketed/braced, so we avoid calling _parse_raw_value here | ||||||||||||||||||||||||||||||||
| 148 | # to avoid overhead | ||||||||||||||||||||||||||||||||
| 149 | 37 | my $key = $line->[COL_K_KEY]; | |||||||||||||||||||||||||||||||
| 150 | 37 | my $val = $line->[COL_K_VALUE_RAW]; | |||||||||||||||||||||||||||||||
| 151 | 37 | ▶ | if ($val =~ /\A["!\\[\{]/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | 24 | my ($err, $parse_res, $decoded_val) = | |||||||||||||||||||||||||||||||
| 153 | $parser->_parse_raw_value($val); | ||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | die "IOD document:$linum: Invalid value: $err" if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 18 | $val = $decoded_val; | |||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||
| 157 | 13 | $val =~ s/\s*[#;].*//; # strip comment | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 31 | ▶ | if (exists $res->{$cur_section}{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if (!$parser->{allow_duplicate_key}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 162 | 0 | die "IOD document:$linum: Duplicate key: $key ". | |||||||||||||||||||||||||||||||
| 163 | "(section $cur_section)"; | ||||||||||||||||||||||||||||||||
| 164 | } elsif ($arrayified->{$cur_section}{$key}++) { | ||||||||||||||||||||||||||||||||
| 165 | 0 | push @{ $res->{$cur_section}{$key} }, $val; | |||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||
| 167 | $res->{$cur_section}{$key} = [ | ||||||||||||||||||||||||||||||||
| 168 | 0 | $res->{$cur_section}{$key}, $val]; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||
| 171 | 31 | $res->{$cur_section}{$key} = $val; | |||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||
| 173 | } # ignore the other line types | ||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 15 | ▶ | $_merge->() if defined($merge) && $num_seen_section_lines > 1;; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $merge and $num_seen_section_lines > 1
MC/DC0%0/2
defined $merge and $num_seen_section_lines > 1
defined $merge
$num_seen_section_lines > 1
Truth table33%1/3
A and B
A= defined $mergeB= $num_seen_section_lines > 1
| |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 15 | $res; | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | 7 | ▶ | sub each_key { | ||||||||||||||||||||||||||||||
|
Subroutine
each_key: called CC=15 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 182 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||
| 183 | 7 | my $opts; | |||||||||||||||||||||||||||||||
| 184 | 7 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 185 | 1 | $opts = shift; | |||||||||||||||||||||||||||||||
| 186 | } else { | ||||||||||||||||||||||||||||||||
| 187 | 6 | $opts = {}; | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | 7 | my ($code) = @_; | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 7 | my $parser = $self->{_parser}; | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 7 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 194 | 7 | my $cur_section = $parser->{default_section}; | |||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 7 | my $skip_section; | |||||||||||||||||||||||||||||||
| 197 | my %seen_sections; | ||||||||||||||||||||||||||||||||
| 198 | 7 | my %seen_keys; | |||||||||||||||||||||||||||||||
| 199 | 7 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 200 | 31 | $linum++; | |||||||||||||||||||||||||||||||
| 201 | 31 | ▶ | next if defined($opts->{linum_start}) && $linum < $opts->{linum_start}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
MC/DC0%0/2
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
defined $opts->{"linum_start"}
$linum < $opts->{"linum_start"}
Truth table33%1/3
A and B
A= defined $opts->{"linum_start"}B= $linum < $opts->{"linum_start"}
| |||||||||||||||||||||||||||||||||
| 202 | 31 | ▶ | next if defined($opts->{linum_end} ) && $linum > $opts->{linum_end}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
MC/DC0%0/2
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
defined $opts->{"linum_end"}
$linum > $opts->{"linum_end"}
Truth table33%1/3
A and B
A= defined $opts->{"linum_end"}B= $linum > $opts->{"linum_end"}
| |||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | 31 | my $type = $line->[COL_TYPE]; | |||||||||||||||||||||||||||||||
| 205 | 31 | ▶ | if ($type eq 'S') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 206 | 15 | $cur_section = $line->[COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 207 | 15 | %seen_keys = (); | |||||||||||||||||||||||||||||||
| 208 | $skip_section = $opts->{unique_section} && | ||||||||||||||||||||||||||||||||
| 209 | 15 | ▶ | $seen_sections{$cur_section}++; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{'unique_section'} && $seen_sections{$cur_section}++
MC/DC0%0/2
$opts->{'unique_section'} && $seen_sections{$cur_section}++
$opts->{'unique_section'}
$seen_sections{$cur_section}++
Truth table33%1/3
A && B
A= $opts->{'unique_section'}B= $seen_sections{$cur_section}++
| |||||||||||||||||||||||||||||||||
| 210 | } elsif ($type eq 'K') { | ||||||||||||||||||||||||||||||||
| 211 | 16 | ▶ | next if $skip_section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | 16 | my $key = $line->[COL_K_KEY]; | |||||||||||||||||||||||||||||||
| 213 | 16 | ▶ | next if $opts->{unique_key} && $seen_keys{$key}++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts->{"unique_key"} and $seen_keys{$key}++
MC/DC0%0/2
$opts->{"unique_key"} and $seen_keys{$key}++
$opts->{"unique_key"}
$seen_keys{$key}++
Truth table33%1/3
A and B
A= $opts->{"unique_key"}B= $seen_keys{$key}++
| |||||||||||||||||||||||||||||||||
| 214 | 16 | my $res = $code->( | |||||||||||||||||||||||||||||||
| 215 | $self, | ||||||||||||||||||||||||||||||||
| 216 | linum => $linum, | ||||||||||||||||||||||||||||||||
| 217 | section => $cur_section, | ||||||||||||||||||||||||||||||||
| 218 | key => $key, | ||||||||||||||||||||||||||||||||
| 219 | raw_value => $line->[COL_K_VALUE_RAW], | ||||||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||||||
| 221 | 16 | ▶ | return if $opts->{early_exit} && !$res; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"early_exit"} and not $res
MC/DC100%2/2
$opts->{"early_exit"} and not $res
$opts->{"early_exit"}
not $res
Truth table100%3/3
A and not(B)
A= $opts->{"early_exit"}B= not $res
| |||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 13 | ▶ | sub get_value { | ||||||||||||||||||||||||||||||
|
Subroutine
get_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 227 | 13 | my ($self, $section, $key) = @_; | |||||||||||||||||||||||||||||||
| 228 | 13 | ▶ | $self->{_dump_cache} = $self->dump unless $self->{_dump_cache}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 13 | $self->{_dump_cache}{$section}{$key}; | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub get_directive_before_key { | ||||||||||||||||||||||||||||||
|
Subroutine
get_directive_before_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 233 | 0 | my ($self, $section, $key) = @_; | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 0 | my $found; | |||||||||||||||||||||||||||||||
| 236 | $self->each_key( | ||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 238 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | return if $found; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return unless $args{linum} > 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return unless $args{section} eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return unless $args{key} eq $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 243 | 0 | my $l = $self->{_parsed}[ $args{linum}-1-1 ]; | |||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | return unless $l->[COL_TYPE] eq 'D'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 245 | 0 | my $p = $self->{_parser}; | |||||||||||||||||||||||||||||||
| 246 | $found = [ | ||||||||||||||||||||||||||||||||
| 247 | $l->[COL_D_DIRECTIVE], | ||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | @{ $p->_parse_command_line($l->[COL_D_ARGS_RAW]) // [] }, | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$p->_parse_command_line($l->[6]) // []
MC/DC0%0/1
$p->_parse_command_line($l->[6]) // []
$p->_parse_command_line($l->[6])
Truth table0%0/2
A
A= $p->_parse_command_line($l->[6])
| |||||||||||||||||||||||||||||||||
| 249 | ]; | ||||||||||||||||||||||||||||||||
| 250 | }, | ||||||||||||||||||||||||||||||||
| 251 | 0 | ); | |||||||||||||||||||||||||||||||
| 252 | 0 | $found; | |||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | sub list_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
list_keys: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 256 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 257 | 2 | my $opts; | |||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 259 | 1 | $opts = shift; | |||||||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||||||
| 261 | 1 | $opts = {}; | |||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | 2 | my ($section) = @_; | |||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | 2 | my @res; | |||||||||||||||||||||||||||||||
| 266 | my %mem; | ||||||||||||||||||||||||||||||||
| 267 | $self->each_key( | ||||||||||||||||||||||||||||||||
| 268 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 269 | 8 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 270 | 8 | ▶ | return unless $args{section} eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 271 | 8 | ▶ | return if $opts->{unique} && $mem{$args{key}}++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"unique"} and $mem{$args{"key"}}++
MC/DC100%2/2
$opts->{"unique"} and $mem{$args{"key"}}++
$opts->{"unique"}
$mem{$args{"key"}}++
Truth table100%3/3
A and B
A= $opts->{"unique"}B= $mem{$args{"key"}}++
| |||||||||||||||||||||||||||||||||
| 272 | 7 | push @res, $args{key}; | |||||||||||||||||||||||||||||||
| 273 | }, | ||||||||||||||||||||||||||||||||
| 274 | 2 | ); | |||||||||||||||||||||||||||||||
| 275 | 2 | @res; | |||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub key_exists { | ||||||||||||||||||||||||||||||
|
Subroutine
key_exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 279 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 280 | 0 | my ($section, $key) = @_; | |||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | 0 | my $found; | |||||||||||||||||||||||||||||||
| 283 | $self->each_key( | ||||||||||||||||||||||||||||||||
| 284 | {early_exit=>1}, | ||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 286 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return 1 unless $args{section} eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return 1 unless $args{key} eq $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 289 | 0 | $found++; | |||||||||||||||||||||||||||||||
| 290 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 291 | }, | ||||||||||||||||||||||||||||||||
| 292 | 0 | ); | |||||||||||||||||||||||||||||||
| 293 | 0 | $found; | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 18 | ▶ | sub _find_section { | ||||||||||||||||||||||||||||||
|
Subroutine
_find_section: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 297 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||
| 298 | 18 | my $opts; | |||||||||||||||||||||||||||||||
| 299 | 18 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 300 | 4 | $opts = shift; | |||||||||||||||||||||||||||||||
| 301 | } else { | ||||||||||||||||||||||||||||||||
| 302 | 14 | $opts = {}; | |||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||
| 304 | 18 | my ($name) = @_; | |||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 18 | my @res; | |||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 18 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 309 | 18 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 310 | 45 | $linum++; | |||||||||||||||||||||||||||||||
| 311 | 45 | ▶ | next unless $line->[COL_TYPE] eq 'S'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | 24 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | 6 | ▶ | next unless $line->[COL_S_SECTION] eq $name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||
| 315 | 20 | ▶ | return $linum unless $opts->{all}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 316 | 16 | push @res, $linum; | |||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | 14 | ▶ | return undef unless $opts->{all}; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 319 | 4 | return @res; | |||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 4 | ▶ | sub each_section { | ||||||||||||||||||||||||||||||
|
Subroutine
each_section: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 323 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 324 | 4 | my $opts; | |||||||||||||||||||||||||||||||
| 325 | 4 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 326 | 3 | $opts = shift; | |||||||||||||||||||||||||||||||
| 327 | } else { | ||||||||||||||||||||||||||||||||
| 328 | 1 | $opts = {}; | |||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||
| 330 | 4 | my ($code) = @_; | |||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | 4 | my $parsed = $self->{_parsed}; | |||||||||||||||||||||||||||||||
| 333 | 4 | my @linums = $self->_find_section({all=>1}); | |||||||||||||||||||||||||||||||
| 334 | 4 | my %seen; | |||||||||||||||||||||||||||||||
| 335 | 4 | for my $linum (@linums) { | |||||||||||||||||||||||||||||||
| 336 | 14 | my $section = $parsed->[$linum-1][COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 337 | 14 | ▶ | next if $opts->{unique} && $seen{$section}++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"unique"} and $seen{$section}++
MC/DC100%2/2
$opts->{"unique"} and $seen{$section}++
$opts->{"unique"}
$seen{$section}++
Truth table100%3/3
A and B
A= $opts->{"unique"}B= $seen{$section}++
| |||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | 13 | my $linum_end = $linum; | |||||||||||||||||||||||||||||||
| 340 | 13 | while (1) { | |||||||||||||||||||||||||||||||
| 341 | 23 | ▶ | last if $linum_end >= @$parsed; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 342 | 20 | ▶ | last if $parsed->[$linum_end][COL_TYPE] eq 'S'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 343 | 10 | $linum_end++; | |||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | 13 | my $res = $code->( | |||||||||||||||||||||||||||||||
| 347 | $self, | ||||||||||||||||||||||||||||||||
| 348 | linum => $linum, | ||||||||||||||||||||||||||||||||
| 349 | linum_start => $linum, | ||||||||||||||||||||||||||||||||
| 350 | linum_end => $linum_end, | ||||||||||||||||||||||||||||||||
| 351 | parsed => $parsed->[$linum-1], | ||||||||||||||||||||||||||||||||
| 352 | section => $section, | ||||||||||||||||||||||||||||||||
| 353 | ); | ||||||||||||||||||||||||||||||||
| 354 | 13 | ▶ | return if $opts->{early_exit} && !$res; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"early_exit"} and not $res
MC/DC100%2/2
$opts->{"early_exit"} and not $res
$opts->{"early_exit"}
not $res
Truth table100%3/3
A and not(B)
A= $opts->{"early_exit"}B= not $res
| |||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 2 | ▶ | sub list_sections { | ||||||||||||||||||||||||||||||
|
Subroutine
list_sections: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 359 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 360 | 2 | my $opts; | |||||||||||||||||||||||||||||||
| 361 | 2 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | 1 | $opts = shift; | |||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||
| 364 | 1 | $opts = {}; | |||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||
| 367 | 2 | my @res; | |||||||||||||||||||||||||||||||
| 368 | $self->each_section( | ||||||||||||||||||||||||||||||||
| 369 | $opts, | ||||||||||||||||||||||||||||||||
| 370 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 371 | 7 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 372 | 7 | push @res, $args{section}; | |||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||
| 374 | 2 | ); | |||||||||||||||||||||||||||||||
| 375 | 2 | @res; | |||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub section_exists { | ||||||||||||||||||||||||||||||
|
Subroutine
section_exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 379 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 380 | 0 | my ($section) = @_; | |||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | 0 | my $found; | |||||||||||||||||||||||||||||||
| 383 | $self->each_section( | ||||||||||||||||||||||||||||||||
| 384 | {early_exit=>1}, | ||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 386 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | return 1 unless $args{section} eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 0 | $found++; | |||||||||||||||||||||||||||||||
| 389 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 390 | }, | ||||||||||||||||||||||||||||||||
| 391 | 0 | ); | |||||||||||||||||||||||||||||||
| 392 | 0 | $found; | |||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | 17 | ▶ | sub _get_section_line_range { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_section_line_range: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||
| 396 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||
| 397 | 17 | my $opts; | |||||||||||||||||||||||||||||||
| 398 | 17 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 399 | 2 | $opts = shift; | |||||||||||||||||||||||||||||||
| 400 | } else { | ||||||||||||||||||||||||||||||||
| 401 | 15 | $opts = {}; | |||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||
| 403 | 17 | my ($name) = @_; | |||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | 17 | my @res; | |||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | 17 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 408 | 17 | my $cur_section = $self->{_parser}{default_section}; | |||||||||||||||||||||||||||||||
| 409 | 17 | my $prev_section; | |||||||||||||||||||||||||||||||
| 410 | my $start; | ||||||||||||||||||||||||||||||||
| 411 | 17 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 412 | 62 | $linum++; | |||||||||||||||||||||||||||||||
| 413 | 62 | ▶ | if ($line->[COL_TYPE] eq 'S') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 414 | 27 | $cur_section = $line->[COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 415 | 27 | ▶ | if ($cur_section eq $name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 416 | 17 | $start = $linum+1; | |||||||||||||||||||||||||||||||
| 417 | 17 | ▶ | $res[-1][1] = $linum if @res && !defined $res[-1][1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@res and not defined $res[-1][1]
MC/DC100%2/2
@res and not defined $res[-1][1]
@res
not defined $res[-1][1]
Truth table100%3/3
A and not(B)
A= @resB= not defined $res[-1][1]
| |||||||||||||||||||||||||||||||||
| 418 | 17 | push @res, [$start, undef]; | |||||||||||||||||||||||||||||||
| 419 | } else { | ||||||||||||||||||||||||||||||||
| 420 | 10 | ▶ | $res[-1][1] = $linum if @res; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | 10 | ▶ | last if @res && !$opts->{all}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@res and not $opts->{"all"}
MC/DC100%2/2
@res and not $opts->{"all"}
@res
not $opts->{"all"}
Truth table100%3/3
A and not(B)
A= @resB= not $opts->{"all"}
| |||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||
| 425 | 17 | ▶ | $res[-1][1] = $linum+1 if @res && !defined($res[-1][1]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@res and not defined $res[-1][1]
MC/DC100%2/2
@res and not defined $res[-1][1]
@res
not defined $res[-1][1]
Truth table100%3/3
A and not(B)
A= @resB= not defined $res[-1][1]
| |||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||
| 427 | L1: | ||||||||||||||||||||||||||||||||
| 428 | 17 | ▶ | if ($opts->{all}) { return @res } else { return $res[0] } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 16 | ▶ | sub _find_key { | ||||||||||||||||||||||||||||||
|
Subroutine
_find_key: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 432 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||
| 433 | 16 | my $opts; | |||||||||||||||||||||||||||||||
| 434 | 16 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 435 | 3 | $opts = shift; | |||||||||||||||||||||||||||||||
| 436 | } else { | ||||||||||||||||||||||||||||||||
| 437 | 13 | $opts = {}; | |||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | 16 | my ($section, $name) = @_; | |||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | 16 | my @res; | |||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | 16 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 444 | 16 | my $cur_section = $self->{_parser}{default_section}; | |||||||||||||||||||||||||||||||
| 445 | 16 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 446 | 62 | $linum++; | |||||||||||||||||||||||||||||||
| 447 | 62 | ▶ | if ($line->[COL_TYPE] eq 'S') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 448 | 23 | $cur_section = $line->[COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 449 | 23 | next; | |||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||
| 451 | 39 | ▶ | next unless $line->[COL_TYPE] eq 'K'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 452 | 38 | ▶ | next unless $cur_section eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 453 | 26 | ▶ | next unless $line->[COL_K_KEY] eq $name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 454 | 11 | ▶ | return $linum unless $opts->{all}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 455 | 7 | push @res, $linum; | |||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||
| 457 | 12 | ▶ | return undef unless $opts->{all}; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 458 | 3 | return @res; | |||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | 2 | ▶ | sub _line_in_section { | ||||||||||||||||||||||||||||||
|
Subroutine
_line_in_section: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 462 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 463 | 2 | my $opts; | |||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 465 | 0 | $opts = shift; | |||||||||||||||||||||||||||||||
| 466 | } else { | ||||||||||||||||||||||||||||||||
| 467 | 2 | $opts = {}; | |||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||
| 469 | 2 | my ($asked_linum, $asked_section) = @_; | |||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | 2 | my @res; | |||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 2 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 474 | 2 | my $cur_section = $self->{_parser}{default_section}; | |||||||||||||||||||||||||||||||
| 475 | 2 | for my $line (@{ $self->{_parsed} }) { | |||||||||||||||||||||||||||||||
| 476 | 6 | $linum++; | |||||||||||||||||||||||||||||||
| 477 | 6 | ▶ | if ($linum == $asked_linum) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 478 | 2 | return $asked_section eq $cur_section; | |||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||
| 480 | 4 | ▶ | if ($line->[COL_TYPE] eq 'S') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 481 | 1 | $cur_section = $line->[COL_S_SECTION]; | |||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||
| 484 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | 16 | ▶ | sub insert_section { | ||||||||||||||||||||||||||||||
|
Subroutine
insert_section: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 488 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||
| 489 | 16 | my $opts; | |||||||||||||||||||||||||||||||
| 490 | 16 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 491 | 8 | $opts = shift; | |||||||||||||||||||||||||||||||
| 492 | } else { | ||||||||||||||||||||||||||||||||
| 493 | 8 | $opts = {}; | |||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 16 | my ($err, $name) = $self->_validate_section($_[0]); | |||||||||||||||||||||||||||||||
| 497 | 16 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | 13 | my $p = $self->{_parsed}; | |||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||
| 501 | 13 | ▶ | if (defined $opts->{comment}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 502 | 2 | ($err, $opts->{comment}) = $self->_validate_comment($opts->{comment}); | |||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||
| 506 | 12 | ▶ | if ($self->_find_section($name)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 507 | 2 | ▶ | if ($opts->{ignore}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 508 | 1 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||
| 509 | } else { | ||||||||||||||||||||||||||||||||
| 510 | 1 | die "Can't insert section '$name': already exists"; | |||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | 10 | my $linum; | |||||||||||||||||||||||||||||||
| 515 | 10 | ▶ | if (defined $opts->{linum}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 516 | 3 | ($err, $opts->{linum}) = $self->_validate_linum($opts->{linum}); | |||||||||||||||||||||||||||||||
| 517 | 3 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 518 | 1 | $linum = $opts->{linum}; | |||||||||||||||||||||||||||||||
| 519 | } elsif ($opts->{top}) { | ||||||||||||||||||||||||||||||||
| 520 | 2 | $linum = $self->_find_section; | |||||||||||||||||||||||||||||||
| 521 | 2 | ▶ | $linum //= 1; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$linum //= 1
MC/DC0%0/1
$linum //= 1
$linum
Truth table50%1/2
A
A= $linum
| |||||||||||||||||||||||||||||||||
| 522 | } else { | ||||||||||||||||||||||||||||||||
| 523 | 5 | $linum = @$p + 1; | |||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | splice @$p, $linum-1, 0, [ | ||||||||||||||||||||||||||||||||
| 527 | 'S', | ||||||||||||||||||||||||||||||||
| 528 | '', # COL_S_WS1 | ||||||||||||||||||||||||||||||||
| 529 | '', # COL_S_WS2 | ||||||||||||||||||||||||||||||||
| 530 | $name, # COL_S_SECTION | ||||||||||||||||||||||||||||||||
| 531 | '', # COL_S_WS3 | ||||||||||||||||||||||||||||||||
| 532 | defined($opts->{comment}) ? ' ' : undef, # COL_S_WS4 | ||||||||||||||||||||||||||||||||
| 533 | defined($opts->{comment}) ? ';' : undef, # COL_S_COMMENT_CHAR | ||||||||||||||||||||||||||||||||
| 534 | $opts->{comment}, # COL_S_COMMENT | ||||||||||||||||||||||||||||||||
| 535 | 8 | ▶ | "\n", # COL_S_NL | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 536 | ]; | ||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||
| 538 | 8 | $self->_discard_cache; | |||||||||||||||||||||||||||||||
| 539 | 8 | $linum; | |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||
| 542 | 19 | ▶ | sub insert_key { | ||||||||||||||||||||||||||||||
|
Subroutine
insert_key: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 543 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||
| 544 | 19 | my $opts; | |||||||||||||||||||||||||||||||
| 545 | 19 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 546 | 7 | $opts = shift; | |||||||||||||||||||||||||||||||
| 547 | } else { | ||||||||||||||||||||||||||||||||
| 548 | 12 | $opts = {}; | |||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||
| 551 | 19 | my $err; | |||||||||||||||||||||||||||||||
| 552 | 19 | my ($err_section, $section) = $self->_validate_section($_[0]); | |||||||||||||||||||||||||||||||
| 553 | 19 | ▶ | die $err_section if $err_section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 554 | 19 | my ($err_name, $name) = $self->_validate_key($_[1]); | |||||||||||||||||||||||||||||||
| 555 | 19 | ▶ | die $err_name if $err_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 556 | 13 | my ($err_value, $value) = $self->_validate_value($_[2]); | |||||||||||||||||||||||||||||||
| 557 | 13 | ▶ | die $err_value if $err_value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||
| 559 | 12 | my $p = $self->{_parsed}; | |||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||
| 561 | 12 | my $linum; | |||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||
| 563 | 12 | ▶ | if ($opts->{replace}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 564 | 1 | $self->delete_key({all=>1}, $section, $name); | |||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||
| 567 | # find section | ||||||||||||||||||||||||||||||||
| 568 | 12 | my $line_range = $self->_get_section_line_range($section); | |||||||||||||||||||||||||||||||
| 569 | 12 | ▶ | if (!$line_range) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 570 | 2 | ▶ | if ($opts->{create_section}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 571 | 1 | $linum = $self->insert_section($section) + 1; | |||||||||||||||||||||||||||||||
| 572 | 1 | $line_range = [$linum, $linum]; | |||||||||||||||||||||||||||||||
| 573 | } else { | ||||||||||||||||||||||||||||||||
| 574 | 1 | die "Can't insert key '$name': unknown section '$section'"; | |||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 11 | ▶ | unless (defined $linum) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 579 | 10 | $linum = $self->_find_key($section, $name); | |||||||||||||||||||||||||||||||
| 580 | 10 | ▶ | if ($linum) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 581 | 3 | ▶ | if ($opts->{ignore}) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 582 | 1 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||
| 583 | } elsif ($opts->{add}) { | ||||||||||||||||||||||||||||||||
| 584 | # | ||||||||||||||||||||||||||||||||
| 585 | } elsif ($opts->{replace}) { | ||||||||||||||||||||||||||||||||
| 586 | # delete already done above | ||||||||||||||||||||||||||||||||
| 587 | } else { | ||||||||||||||||||||||||||||||||
| 588 | 1 | die "Can't insert key '$name': already exists"; | |||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||
| 592 | 8 | ▶ | if ($opts->{linum}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 593 | 2 | ($err, $opts->{linum}) = $self->_validate_linum($opts->{linum}); | |||||||||||||||||||||||||||||||
| 594 | 2 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 595 | 2 | ▶ | $self->_line_in_section($opts->{linum}, $section) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 596 | or die "Invalid linum $opts->{linum}: not inside section '$section'"; | ||||||||||||||||||||||||||||||||
| 597 | 1 | $linum = $opts->{linum}; | |||||||||||||||||||||||||||||||
| 598 | } else { | ||||||||||||||||||||||||||||||||
| 599 | 6 | ▶ | if ($opts->{top}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 600 | 1 | $linum = $line_range->[0]; | |||||||||||||||||||||||||||||||
| 601 | } else { | ||||||||||||||||||||||||||||||||
| 602 | 5 | $linum = $line_range->[1]; | |||||||||||||||||||||||||||||||
| 603 | 5 | ▶ | if ($p->[$linum-1]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 604 | 1 | ▶ | if ($p->[$linum-1][COL_TYPE] eq 'S') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 605 | } else { | ||||||||||||||||||||||||||||||||
| 606 | 0 | $linum++; | |||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||
| 613 | #XXX implement option: replace | ||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||
| 615 | 8 | splice @$p, $linum-1, 0, [ | |||||||||||||||||||||||||||||||
| 616 | 'K', | ||||||||||||||||||||||||||||||||
| 617 | '', # COL_K_WS1 | ||||||||||||||||||||||||||||||||
| 618 | $name, # COL_K_KEY | ||||||||||||||||||||||||||||||||
| 619 | '', # COL_K_WS2 | ||||||||||||||||||||||||||||||||
| 620 | '', # COL_K_WS3 | ||||||||||||||||||||||||||||||||
| 621 | $value, # COL_K_VALUE_RAW | ||||||||||||||||||||||||||||||||
| 622 | "\n", # COL_K_NL | ||||||||||||||||||||||||||||||||
| 623 | ]; | ||||||||||||||||||||||||||||||||
| 624 | 8 | $self->_discard_cache; | |||||||||||||||||||||||||||||||
| 625 | 8 | $linum; | |||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||
| 628 | 5 | ▶ | sub delete_section { | ||||||||||||||||||||||||||||||
|
Subroutine
delete_section: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 629 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 630 | 5 | my $opts; | |||||||||||||||||||||||||||||||
| 631 | 5 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 632 | 2 | $opts = shift; | |||||||||||||||||||||||||||||||
| 633 | } else { | ||||||||||||||||||||||||||||||||
| 634 | 3 | $opts = {}; | |||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||
| 637 | 5 | my ($err, $section) = $self->_validate_section($_[0]); | |||||||||||||||||||||||||||||||
| 638 | 5 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||
| 640 | 5 | my $p = $self->{_parsed}; | |||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||
| 642 | 5 | my @line_ranges; | |||||||||||||||||||||||||||||||
| 643 | 5 | ▶ | if ($opts->{all}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 644 | 2 | @line_ranges = $self->_get_section_line_range({all=>1}, $section); | |||||||||||||||||||||||||||||||
| 645 | } else { | ||||||||||||||||||||||||||||||||
| 646 | 3 | @line_ranges = ($self->_get_section_line_range($section)); | |||||||||||||||||||||||||||||||
| 647 | 3 | ▶ | @line_ranges = () if !defined($line_ranges[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||
| 650 | 5 | ▶ | if ($opts->{cond}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 651 | @line_ranges = grep { | ||||||||||||||||||||||||||||||||
| 652 | 1 | $opts->{cond}->( | |||||||||||||||||||||||||||||||
| 653 | $self, | ||||||||||||||||||||||||||||||||
| 654 | linum_start => $_->[0], | ||||||||||||||||||||||||||||||||
| 655 | linum_end => $_->[1], | ||||||||||||||||||||||||||||||||
| 656 | ); | ||||||||||||||||||||||||||||||||
| 657 | } @line_ranges; | ||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||
| 660 | 5 | my $num_deleted = 0; | |||||||||||||||||||||||||||||||
| 661 | 5 | for my $line_range (reverse @line_ranges) { | |||||||||||||||||||||||||||||||
| 662 | 5 | ▶ | next unless defined $line_range; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 663 | 5 | ▶ | my $line1 = $line_range->[0] - 1; $line1 = 1 if $line1 < 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 664 | 5 | my $line2 = $line_range->[1] - 1; | |||||||||||||||||||||||||||||||
| 665 | 5 | splice @$p, $line1-1, ($line2-$line1+1); | |||||||||||||||||||||||||||||||
| 666 | 5 | $num_deleted++; | |||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||
| 668 | 5 | ▶ | $self->_discard_cache if $num_deleted; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 669 | 5 | $num_deleted; | |||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||
| 672 | 6 | ▶ | sub delete_key { | ||||||||||||||||||||||||||||||
|
Subroutine
delete_key: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 673 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 674 | 6 | my $opts; | |||||||||||||||||||||||||||||||
| 675 | 6 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 676 | 3 | $opts = shift; | |||||||||||||||||||||||||||||||
| 677 | } else { | ||||||||||||||||||||||||||||||||
| 678 | 3 | $opts = {}; | |||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||
| 681 | 6 | my ($err_section, $section) = $self->_validate_section($_[0]); | |||||||||||||||||||||||||||||||
| 682 | 6 | ▶ | die $err_section if $err_section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 683 | 6 | my ($err_name, $name) = $self->_validate_key($_[1]); | |||||||||||||||||||||||||||||||
| 684 | 6 | ▶ | die $err_name if $err_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||
| 686 | 6 | my $p = $self->{_parsed}; | |||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||
| 688 | 6 | my @linums; | |||||||||||||||||||||||||||||||
| 689 | 6 | ▶ | if ($opts->{all}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 690 | 3 | @linums = $self->_find_key({all=>1}, $section, $name); | |||||||||||||||||||||||||||||||
| 691 | } else { | ||||||||||||||||||||||||||||||||
| 692 | 3 | @linums = ($self->_find_key($section, $name)); | |||||||||||||||||||||||||||||||
| 693 | 3 | ▶ | @linums = () if !defined($linums[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||
| 696 | 6 | ▶ | if ($opts->{cond}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 697 | @linums = grep { | ||||||||||||||||||||||||||||||||
| 698 | 1 | my $line = $self->{_parsed}[$_-1]; | |||||||||||||||||||||||||||||||
| 699 | 4 | $opts->{cond}->( | |||||||||||||||||||||||||||||||
| 700 | $self, | ||||||||||||||||||||||||||||||||
| 701 | linum => $_, | ||||||||||||||||||||||||||||||||
| 702 | parsed => $line, | ||||||||||||||||||||||||||||||||
| 703 | key => $line->[COL_K_KEY], | ||||||||||||||||||||||||||||||||
| 704 | raw_value => $line->[COL_K_VALUE_RAW], | ||||||||||||||||||||||||||||||||
| 705 | # XXX value | ||||||||||||||||||||||||||||||||
| 706 | ); | ||||||||||||||||||||||||||||||||
| 707 | } @linums; | ||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||
| 710 | 6 | my $num_deleted = 0; | |||||||||||||||||||||||||||||||
| 711 | 6 | for my $linum (reverse @linums) { | |||||||||||||||||||||||||||||||
| 712 | 6 | splice @$p, $linum-1, 1; | |||||||||||||||||||||||||||||||
| 713 | 6 | $num_deleted++; | |||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||
| 716 | 6 | ▶ | $self->_discard_cache if $num_deleted; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 717 | 6 | $num_deleted; | |||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||
| 720 | 4 | ▶ | sub set_value { | ||||||||||||||||||||||||||||||
|
Subroutine
set_value: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 721 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 722 | 4 | my $opts; | |||||||||||||||||||||||||||||||
| 723 | 4 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 724 | 0 | $opts = shift; | |||||||||||||||||||||||||||||||
| 725 | } else { | ||||||||||||||||||||||||||||||||
| 726 | 4 | $opts = {}; | |||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||
| 729 | 4 | my $section = $_[0]; | |||||||||||||||||||||||||||||||
| 730 | 4 | my $key = $_[1]; | |||||||||||||||||||||||||||||||
| 731 | 4 | my ($err_value, $value) = $self->_validate_value($_[2]); | |||||||||||||||||||||||||||||||
| 732 | 4 | ▶ | die $err_value if $err_value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||
| 734 | 3 | my $found; | |||||||||||||||||||||||||||||||
| 735 | $self->each_key( | ||||||||||||||||||||||||||||||||
| 736 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||
| 737 | 3 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 738 | 3 | ▶ | return if $found && !$opts->{all}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$found and not $opts->{"all"}
MC/DC0%0/2
$found and not $opts->{"all"}
$found
not $opts->{"all"}
Truth table33%1/3
A and not(B)
A= $foundB= not $opts->{"all"}
| |||||||||||||||||||||||||||||||||
| 739 | 3 | ▶ | return unless $args{section} eq $section; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 740 | 2 | ▶ | return unless $args{key} eq $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 741 | 1 | $found++; | |||||||||||||||||||||||||||||||
| 742 | 1 | my $l = $self->{_parsed}[ $args{linum}-1 ]; | |||||||||||||||||||||||||||||||
| 743 | 1 | $l->[COL_K_VALUE_RAW] = $value; | |||||||||||||||||||||||||||||||
| 744 | }, | ||||||||||||||||||||||||||||||||
| 745 | 3 | ); | |||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | 60 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 749 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||
| 751 | 60 | my $abo = $self->{_parser}{allow_bang_only}; | |||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||
| 753 | 60 | my @str; | |||||||||||||||||||||||||||||||
| 754 | 60 | my $linum = 0; | |||||||||||||||||||||||||||||||
| 755 | 60 | for my $line (@{$self->{_parsed}}) { | |||||||||||||||||||||||||||||||
| 756 | 747 | $linum++; | |||||||||||||||||||||||||||||||
| 757 | 747 | my $type = $line->[COL_TYPE]; | |||||||||||||||||||||||||||||||
| 758 | 747 | ▶ | if ($type eq 'B') { | ||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||
| 759 | 182 | push @str, $line->[COL_B_RAW]; | |||||||||||||||||||||||||||||||
| 760 | } elsif ($type eq 'D') { | ||||||||||||||||||||||||||||||||
| 761 | 12 | ▶ | push @str, join( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 762 | "", | ||||||||||||||||||||||||||||||||
| 763 | ($abo ? $line->[COL_D_COMMENT_CHAR] : ";"), | ||||||||||||||||||||||||||||||||
| 764 | $line->[COL_D_WS1], "!", | ||||||||||||||||||||||||||||||||
| 765 | $line->[COL_D_WS2], | ||||||||||||||||||||||||||||||||
| 766 | $line->[COL_D_DIRECTIVE], | ||||||||||||||||||||||||||||||||
| 767 | $line->[COL_D_WS3], | ||||||||||||||||||||||||||||||||
| 768 | $line->[COL_D_ARGS_RAW], | ||||||||||||||||||||||||||||||||
| 769 | $line->[COL_D_NL], | ||||||||||||||||||||||||||||||||
| 770 | ); | ||||||||||||||||||||||||||||||||
| 771 | } elsif ($type eq 'C') { | ||||||||||||||||||||||||||||||||
| 772 | 63 | push @str, join( | |||||||||||||||||||||||||||||||
| 773 | "", | ||||||||||||||||||||||||||||||||
| 774 | $line->[COL_C_WS1], | ||||||||||||||||||||||||||||||||
| 775 | $line->[COL_C_COMMENT_CHAR], | ||||||||||||||||||||||||||||||||
| 776 | $line->[COL_C_COMMENT], | ||||||||||||||||||||||||||||||||
| 777 | $line->[COL_C_NL], | ||||||||||||||||||||||||||||||||
| 778 | ); | ||||||||||||||||||||||||||||||||
| 779 | } elsif ($type eq 'S') { | ||||||||||||||||||||||||||||||||
| 780 | 113 | ▶ | push @str, join( | ||||||||||||||||||||||||||||||
|
Condition100%6/6
$line->[5] // ""
$line->[6] // ""
$line->[7] // ""
MC/DC100%1/1
$line->[5] // ""
$line->[5]
MC/DC100%1/1
$line->[6] // ""
$line->[6]
MC/DC100%1/1
$line->[7] // ""
$line->[7]
Truth table100%2/2
A
A= $line->[5]
Truth table100%2/2
A
A= $line->[6]
Truth table100%2/2
A
A= $line->[7]
| |||||||||||||||||||||||||||||||||
| 781 | "", | ||||||||||||||||||||||||||||||||
| 782 | $line->[COL_S_WS1], "[", | ||||||||||||||||||||||||||||||||
| 783 | $line->[COL_S_WS2], | ||||||||||||||||||||||||||||||||
| 784 | $line->[COL_S_SECTION], | ||||||||||||||||||||||||||||||||
| 785 | $line->[COL_S_WS3], "]", | ||||||||||||||||||||||||||||||||
| 786 | $line->[COL_S_WS4] // '', | ||||||||||||||||||||||||||||||||
| 787 | $line->[COL_S_COMMENT_CHAR] // '', | ||||||||||||||||||||||||||||||||
| 788 | $line->[COL_S_COMMENT] // '', | ||||||||||||||||||||||||||||||||
| 789 | $line->[COL_S_NL], | ||||||||||||||||||||||||||||||||
| 790 | ); | ||||||||||||||||||||||||||||||||
| 791 | } elsif ($type eq 'K') { | ||||||||||||||||||||||||||||||||
| 792 | 377 | push @str, join( | |||||||||||||||||||||||||||||||
| 793 | "", | ||||||||||||||||||||||||||||||||
| 794 | $line->[COL_K_WS1], | ||||||||||||||||||||||||||||||||
| 795 | $line->[COL_K_KEY], | ||||||||||||||||||||||||||||||||
| 796 | $line->[COL_K_WS2], "=", | ||||||||||||||||||||||||||||||||
| 797 | $line->[COL_K_WS3], | ||||||||||||||||||||||||||||||||
| 798 | $line->[COL_K_VALUE_RAW], | ||||||||||||||||||||||||||||||||
| 799 | $line->[COL_K_NL], | ||||||||||||||||||||||||||||||||
| 800 | ); | ||||||||||||||||||||||||||||||||
| 801 | } else { | ||||||||||||||||||||||||||||||||
| 802 | 0 | die "BUG: Unknown type '$type' in line $linum"; | |||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||
| 806 | 60 | join "", @str; | |||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||
| 809 | 16 | ▶ | use overload '""' => \&as_string; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||
| 811 | 16 | 1; | |||||||||||||||||||||||||||||||
| 812 | # ABSTRACT: Represent IOD document | ||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||
| 814 | __END__ | ||||||||||||||||||||||||||||||||