Config/IOD/Document.pm

filter: Statementstmt 89.3% 410 / 459 Branchbran 81.7% 224 / 274 Conditioncond 65.0% 41 / 63 MC/DCmcdc 45.0% 18 / 40 Subroutinesub 82.5% 33 / 40 Podpod 100% 17 / 17 totaltotal 83.2% 743 / 893 CC 172 SCAR 26.8
CC
172
Cov
85%
__ANON__
56.0
dump
36.3
insert_key
19.1
CRAP 14.5
« Config/IOD.pm ↑ Summary Test/Config/IOD.pm »
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
BranchTrueFalseTotal
unless ($attrs{"_parsed"}) 0 107 107
19 0 $attrs{_parsed} = [];
20 }
21 107 ▶ if (!$attrs{_parser}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attrs{"_parser"}) 0 107 107
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
BranchTrueFalseTotal
unless (length $name) 1 45 46
42 45 ▶ if ($name =~ /\R|\]/) { return ("Section name must not contain ] or newline") }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\R|\]/) 2 43 45
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
BranchTrueFalseTotal
unless (length $name) 1 24 25
51 24 ▶ if ($name =~ /\R|=/) { return ("Key name must not contain = or newline") }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\R|=/) 2 22 24
52 22 ▶ if ($name =~ /\A(?:;|#|\[)/) { return ("Key name must not start with ;, #, [") }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A(?:;|#|\[)/) 3 19 22
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
BranchTrueFalseTotal
if ($value =~ /\R/) 2 15 17
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
BranchTrueFalseTotal
if ($comment =~ /\R/) 1 1 2
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
BranchTrueFalseTotal
if ($value < 1) 1 4 5
72 4 ▶ if ($value > @{$self->{_parsed}}) { return ("linum must not be larger than number of document's lines") }
Branch: 1 branch
BranchTrueFalseTotal
if ($value > @{$self->{"_parsed"};}) 1 3 4
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 21 21
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
BranchTrueFalseTotal
if $cur_section eq $merge 0 2 2
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
BranchTrueFalseTotal
unless exists $res->{$merge} 0 2 2
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}
l!l&&r!l&&!r
220
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}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $parser->{"enable_expr"} 2 19 21
119 21 ▶ local $parser->{_cur_section} = $cur_section if $parser->{enable_expr};
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"enable_expr"} 2 19 21
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
BranchTrueFalseTotal
if defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"} 0 61 61
Condition33%1/3
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
!ll&&!rl&&r
6100
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"}
ABresult
0X0
100
111
124 61 ▶ next if defined($opts->{linum_end} ) && $linum > $opts->{linum_end};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"} 0 61 61
Condition33%1/3
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
!ll&&!rl&&r
6100
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"}
ABresult
0X0
100
111
125  
126 61 my $type = $line->[COL_TYPE];
127 61 ▶ if ($type eq 'D') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'D') { } 7 54 61
elsif ($type eq 'S') { } 9 45 54
elsif ($type eq 'K') { } 37 8 45
128 7 my $directive = $line->[COL_D_DIRECTIVE];
129 7 ▶ if ($directive eq 'merge') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "merge") 4 3 7
130 4 my $args = $parser->_parse_command_line(
131 $line->[COL_D_ARGS_RAW]);
132 4 ▶ if (!defined($args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args) 0 4 4
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
BranchTrueFalseTotal
@$args ? : 2 2 4
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
BranchTrueFalseTotal
if defined $merge and $num_seen_section_lines > 1 2 7 9
Condition66%2/3
defined $merge and $num_seen_section_lines > 1
!ll&&!rl&&r
702
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
ABresult
0X0
100
111
142 9 $cur_section = $line->[COL_S_SECTION];
143 9 ▶ $parser->{_cur_section} = $cur_section if $parser->{enable_expr}; #TMP HACK
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"enable_expr"} 1 8 9
144 9 ▶ $res->{$cur_section} //= {};
Condition50%1/2
$res->{$cur_section} //= {}
l!l
09
MC/DC0%0/1
$res->{$cur_section} //= {}
$res->{$cur_section}
Truth table50%1/2
A
A= $res->{$cur_section}
Aresult
11
00
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
BranchTrueFalseTotal
if ($val =~ /\A["!\\[\{]/) { } 24 13 37
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
BranchTrueFalseTotal
if $err 6 18 24
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
BranchTrueFalseTotal
if (exists $res->{$cur_section}{$key}) { } 0 31 31
161 0 ▶ if (!$parser->{allow_duplicate_key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $parser->{'allow_duplicate_key'}) { } 0 0 0
elsif ($arrayified->{$cur_section}{$key}++) { } 0 0 0
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
BranchTrueFalseTotal
if defined $merge and $num_seen_section_lines > 1 0 15 15
Condition33%1/3
defined $merge and $num_seen_section_lines > 1
!ll&&!rl&&r
1500
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 1 6 7
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
BranchTrueFalseTotal
if defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"} 0 31 31
Condition33%1/3
defined $opts->{"linum_start"} and $linum < $opts->{"linum_start"}
!ll&&!rl&&r
3100
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"}
ABresult
0X0
100
111
202 31 ▶ next if defined($opts->{linum_end} ) && $linum > $opts->{linum_end};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"} 0 31 31
Condition33%1/3
defined $opts->{"linum_end"} and $linum > $opts->{"linum_end"}
!ll&&!rl&&r
3100
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"}
ABresult
0X0
100
111
203  
204 31 my $type = $line->[COL_TYPE];
205 31 ▶ if ($type eq 'S') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'S') { } 15 16 31
elsif ($type eq 'K') { } 16 0 16
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}++
!ll&&!rl&&r
1500
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}++
ABresult
0X0
100
111
210 } elsif ($type eq 'K') {
211 16 ▶ next if $skip_section;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_section 0 16 16
212 16 my $key = $line->[COL_K_KEY];
213 16 ▶ next if $opts->{unique_key} && $seen_keys{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"unique_key"} and $seen_keys{$key}++ 0 16 16
Condition33%1/3
$opts->{"unique_key"} and $seen_keys{$key}++
!ll&&!rl&&r
1600
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}++
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $opts->{"early_exit"} and not $res 1 15 16
Condition100%3/3
$opts->{"early_exit"} and not $res
!ll&&!rl&&r
1411
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->{"_dump_cache"} 2 11 13
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
BranchTrueFalseTotal
if $found 0 0 0
240 0 ▶ return unless $args{linum} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"linum"} > 1 0 0 0
241 0 ▶ return unless $args{section} eq $section;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"section"} eq $section 0 0 0
242 0 ▶ return unless $args{key} eq $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"key"} eq $key 0 0 0
243 0 my $l = $self->{_parsed}[ $args{linum}-1-1 ];
244 0 ▶ return unless $l->[COL_TYPE] eq 'D';
Branch: 1 branch
BranchTrueFalseTotal
unless $l->[0] eq "D" 0 0 0
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]) // []
l!l
00
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])
Aresult
11
00
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 1 1 2
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
BranchTrueFalseTotal
unless $args{"section"} eq $section 0 8 8
271 8 ▶ return if $opts->{unique} && $mem{$args{key}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"unique"} and $mem{$args{"key"}}++ 1 7 8
Condition100%3/3
$opts->{"unique"} and $mem{$args{"key"}}++
!ll&&!rl&&r
431
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"}}++
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $args{"section"} eq $section 0 0 0
288 0 ▶ return 1 unless $args{key} eq $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"key"} eq $key 0 0 0
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 4 14 18
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
BranchTrueFalseTotal
unless $line->[0] eq "S" 21 24 45
312 24 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 6 18 24
313 6 ▶ next unless $line->[COL_S_SECTION] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $line->[3] eq $name 4 2 6
314 }
315 20 ▶ return $linum unless $opts->{all};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"all"} 4 16 20
316 16 push @res, $linum;
317 }
318 14 ▶ return undef unless $opts->{all}; ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"all"} 10 4 14
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 3 1 4
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
BranchTrueFalseTotal
if $opts->{"unique"} and $seen{$section}++ 1 13 14
Condition100%3/3
$opts->{"unique"} and $seen{$section}++
!ll&&!rl&&r
1031
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}++
ABresult
0X0
100
111
338  
339 13 my $linum_end = $linum;
340 13 while (1) {
341 23 ▶ last if $linum_end >= @$parsed;
Branch: 1 branch
BranchTrueFalseTotal
if $linum_end >= @$parsed 3 20 23
342 20 ▶ last if $parsed->[$linum_end][COL_TYPE] eq 'S';
Branch: 1 branch
BranchTrueFalseTotal
if $parsed->[$linum_end][0] eq "S" 10 10 20
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
BranchTrueFalseTotal
if $opts->{"early_exit"} and not $res 1 12 13
Condition100%3/3
$opts->{"early_exit"} and not $res
!ll&&!rl&&r
1111
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 1 1 2
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
BranchTrueFalseTotal
unless $args{"section"} eq $section 0 0 0
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 2 15 17
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
BranchTrueFalseTotal
if ($line->[0] eq "S") 27 35 62
414 27 $cur_section = $line->[COL_S_SECTION];
415 27 ▶ if ($cur_section eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur_section eq $name) { } 17 10 27
416 17 $start = $linum+1;
417 17 ▶ $res[-1][1] = $linum if @res && !defined $res[-1][1];
Branch: 1 branch
BranchTrueFalseTotal
if @res and not defined $res[-1][1] 2 15 17
Condition100%3/3
@res and not defined $res[-1][1]
!ll&&!rl&&r
1412
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]
ABresult
0X0
100
111
418 17 push @res, [$start, undef];
419 } else {
420 10 ▶ $res[-1][1] = $linum if @res;
Branch: 1 branch
BranchTrueFalseTotal
if @res 3 7 10
421 10 ▶ last if @res && !$opts->{all};
Branch: 1 branch
BranchTrueFalseTotal
if @res and not $opts->{"all"} 2 8 10
Condition100%3/3
@res and not $opts->{"all"}
!ll&&!rl&&r
712
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"}
ABresult
0X0
100
111
422 }
423 }
424 }
425 17 ▶ $res[-1][1] = $linum+1 if @res && !defined($res[-1][1]);
Branch: 1 branch
BranchTrueFalseTotal
if @res and not defined $res[-1][1] 12 5 17
Condition100%3/3
@res and not defined $res[-1][1]
!ll&&!rl&&r
3212
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]
ABresult
0X0
100
111
426  
427 L1:
428 17 ▶ if ($opts->{all}) { return @res } else { return $res[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'all'}) { } 2 15 17
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 3 13 16
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
BranchTrueFalseTotal
if ($line->[0] eq "S") 23 39 62
448 23 $cur_section = $line->[COL_S_SECTION];
449 23 next;
450 }
451 39 ▶ next unless $line->[COL_TYPE] eq 'K';
Branch: 1 branch
BranchTrueFalseTotal
unless $line->[0] eq "K" 1 38 39
452 38 ▶ next unless $cur_section eq $section;
Branch: 1 branch
BranchTrueFalseTotal
unless $cur_section eq $section 12 26 38
453 26 ▶ next unless $line->[COL_K_KEY] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $line->[2] eq $name 15 11 26
454 11 ▶ return $linum unless $opts->{all};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"all"} 4 7 11
455 7 push @res, $linum;
456 }
457 12 ▶ return undef unless $opts->{all}; ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"all"} 9 3 12
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 2 2
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
BranchTrueFalseTotal
if ($linum == $asked_linum) 2 4 6
478 2 return $asked_section eq $cur_section;
479 }
480 4 ▶ if ($line->[COL_TYPE] eq 'S') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line->[0] eq "S") 1 3 4
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 8 8 16
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
BranchTrueFalseTotal
if $err 3 13 16
498  
499 13 my $p = $self->{_parsed};
500  
501 13 ▶ if (defined $opts->{comment}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"comment"}) 2 11 13
502 2 ($err, $opts->{comment}) = $self->_validate_comment($opts->{comment});
503 2 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 1 1 2
504 }
505  
506 12 ▶ if ($self->_find_section($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_find_section($name)) 2 10 12
507 2 ▶ if ($opts->{ignore}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'ignore'}) { } 1 1 2
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
BranchTrueFalseTotal
if (defined $opts->{'linum'}) { } 3 7 10
elsif ($opts->{'top'}) { } 2 5 7
516 3 ($err, $opts->{linum}) = $self->_validate_linum($opts->{linum});
517 3 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 2 1 3
518 1 $linum = $opts->{linum};
519 } elsif ($opts->{top}) {
520 2 $linum = $self->_find_section;
521 2 ▶ $linum //= 1;
Condition50%1/2
$linum //= 1
l!l
20
MC/DC0%0/1
$linum //= 1
$linum
Truth table50%1/2
A
A= $linum
Aresult
11
00
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
BranchTrueFalseTotal
defined $opts->{'comment'} ? : 1 7 8
defined $opts->{'comment'} ? : 1 7 8
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 7 12 19
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
BranchTrueFalseTotal
if $err_section 0 19 19
554 19 my ($err_name, $name) = $self->_validate_key($_[1]);
555 19 ▶ die $err_name if $err_name;
Branch: 1 branch
BranchTrueFalseTotal
if $err_name 6 13 19
556 13 my ($err_value, $value) = $self->_validate_value($_[2]);
557 13 ▶ die $err_value if $err_value;
Branch: 1 branch
BranchTrueFalseTotal
if $err_value 1 12 13
558  
559 12 my $p = $self->{_parsed};
560  
561 12 my $linum;
562  
563 12 ▶ if ($opts->{replace}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"replace"}) 1 11 12
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
BranchTrueFalseTotal
unless ($line_range) 2 10 12
570 2 ▶ if ($opts->{create_section}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'create_section'}) { } 1 1 2
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
BranchTrueFalseTotal
unless (defined $linum) 10 1 11
579 10 $linum = $self->_find_key($section, $name);
580 10 ▶ if ($linum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($linum) 3 7 10
581 3 ▶ if ($opts->{ignore}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opts->{'ignore'}) { } 1 2 3
elsif ($opts->{'add'}) { } 1 1 2
elsif ($opts->{'replace'}) { } 0 1 1
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
BranchTrueFalseTotal
if ($opts->{'linum'}) { } 2 6 8
593 2 ($err, $opts->{linum}) = $self->_validate_linum($opts->{linum});
594 2 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 2 2
595 2 ▶ $self->_line_in_section($opts->{linum}, $section)
Branch: 1 branch
BranchTrueFalseTotal
$self->_line_in_section($opts->{"linum"}, $section) or die qq[Invalid linum $opts->{"linum"}: not inside section '${section}'] 1 1 2
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
BranchTrueFalseTotal
if ($opts->{'top'}) { } 1 5 6
600 1 $linum = $line_range->[0];
601 } else {
602 5 $linum = $line_range->[1];
603 5 ▶ if ($p->[$linum-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$p[$linum - 1]) 1 4 5
604 1 ▶ if ($p->[$linum-1][COL_TYPE] eq 'S') {
Branch: 1 branch
BranchTrueFalseTotal
if ($$p[$linum - 1][0] eq 'S') { } 1 0 1
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 2 3 5
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
BranchTrueFalseTotal
if $err 0 5 5
639  
640 5 my $p = $self->{_parsed};
641  
642 5 my @line_ranges;
643 5 ▶ if ($opts->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'all'}) { } 2 3 5
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
BranchTrueFalseTotal
unless defined $line_ranges[0] 1 2 3
648 }
649  
650 5 ▶ if ($opts->{cond}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"cond"}) 1 4 5
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
BranchTrueFalseTotal
unless defined $line_range 0 5 5
663 5 ▶ my $line1 = $line_range->[0] - 1; $line1 = 1 if $line1 < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $line1 < 1 0 5 5
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
BranchTrueFalseTotal
if $num_deleted 4 1 5
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 3 3 6
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
BranchTrueFalseTotal
if $err_section 0 6 6
683 6 my ($err_name, $name) = $self->_validate_key($_[1]);
684 6 ▶ die $err_name if $err_name;
Branch: 1 branch
BranchTrueFalseTotal
if $err_name 0 6 6
685  
686 6 my $p = $self->{_parsed};
687  
688 6 my @linums;
689 6 ▶ if ($opts->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'all'}) { } 3 3 6
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
BranchTrueFalseTotal
unless defined $linums[0] 2 1 3
694 }
695  
696 6 ▶ if ($opts->{cond}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"cond"}) 1 5 6
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
BranchTrueFalseTotal
if $num_deleted 4 2 6
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
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 4 4
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
BranchTrueFalseTotal
if $err_value 1 3 4
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
BranchTrueFalseTotal
if $found and not $opts->{"all"} 0 3 3
Condition33%1/3
$found and not $opts->{"all"}
!ll&&!rl&&r
300
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"}
ABresult
0X0
100
111
739 3 ▶ return unless $args{section} eq $section;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"section"} eq $section 1 2 3
740 2 ▶ return unless $args{key} eq $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"key"} eq $key 1 1 2
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
BranchTrueFalseTotal
if ($type eq 'B') { } 182 565 747
elsif ($type eq 'D') { } 12 553 565
elsif ($type eq 'C') { } 63 490 553
elsif ($type eq 'S') { } 113 377 490
elsif ($type eq 'K') { } 377 0 377
759 182 push @str, $line->[COL_B_RAW];
760 } elsif ($type eq 'D') {
761 12 ▶ push @str, join(
Branch: 1 branch
BranchTrueFalseTotal
$abo ? : 12 0 12
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] // ""
l!l
4109
$line->[6] // ""
l!l
4109
$line->[7] // ""
l!l
4109
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]
Aresult
11
00
Truth table100%2/2
A
A= $line->[6]
Aresult
11
00
Truth table100%2/2
A
A= $line->[7]
Aresult
11
00
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__
« Config/IOD.pm ↑ Summary Test/Config/IOD.pm »