ValueFile/Simple/Reader.pm

filter: Statementstmt 39.9% 97 / 243 Branchbran 15.7% 23 / 146 Conditioncond 5.2% 7 / 134 MC/DCmcdc 0.0% 0 / 62 Subroutinesub 60.7% 17 / 28 Podpod 100% 8 / 8 totaltotal 24.4% 152 / 621 CC 126 SCAR 68.8
CC
126
Cov
24%
__ANON__
2756.0
read_to_cb
125.8
_handle_special
91.6
CRAP 972.0
↑ Summary ValueFile/Simple/Writer.pm »
1 # Copyright (c) 2024-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: module for reading and writing ValueFile files
6  
7 package File::ValueFile::Simple::Reader;
8  
9 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use parent qw(Data::Identifier::Interface::Userdata Data::Identifier::Interface::Subobjects);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Fcntl qw(SEEK_SET);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use Data::Identifier v0.34;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use File::ValueFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 RE_ISE => qr/^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/,
25 KEYWORD_OK => qr/^[a-zA-Z0-9\-:\._~]*$/,
26 FORMAT_ISE => '54bf8af4-b1d7-44da-af48-5278d11e8f32',
27 ASI_ISE => 'ddd60c5c-2934-404f-8f2d-fcb4da88b633',
28 TAGNAME_ISE => 'bfae7574-3dae-425d-89b1-9c087c140c23',
29 DOT_REPEAT_ISE => '2ec67bbe-4698-4a0c-921d-1f0951923ee6',
30 2 };
31  
32 2 our $VERSION = v0.11;
33  
34  
35  
36 1 ▶sub new {
Subroutine new: called CC=14 SCAR=35.7
Pod documented
37 1 my ($pkg, $in, %opts) = @_;
38 1 my $fh;
39 1 my $self = bless \%opts;
40  
41 1 ▶ if (ref $in) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in) { } 1 0 1
42 1 $fh = $in;
43 } else {
44 0 ▶ open($fh, '<', $in) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $in or croak($!) 0 0 0
45 }
46  
47 1 $self->{fh} = $fh;
48  
49 1 foreach my $key (qw(supported_formats supported_features)) {
50 2 ▶ $self->{$key} ||= 'all';
Condition50%1/2
$self->{$key} ||= "all"
l!l
02
MC/DC0%0/1
$self->{$key} ||= "all"
$self->{$key}
Truth table50%1/2
A
A= $self->{$key}
Aresult
11
00
51 2 ▶ if (ref($self->{$key}) ne 'ARRAY' && $self->{$key} ne 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key} ne "ARRAY" and $self->{$key} ne "all") 0 2 2
Condition33%1/3
ref $self->{$key} ne "ARRAY" and $self->{$key} ne "all"
!ll&&!rl&&r
020
MC/DC0%0/2
ref $self->{$key} ne "ARRAY" and $self->{$key} ne "all"
ref $self->{$key} ne "ARRAY" $self->{$key} ne "all"
Truth table33%1/3
A and B
A= ref $self->{$key} ne "ARRAY"B= $self->{$key} ne "all"
ABresult
0X0
100
111
52 0 $self->{$key} = [$self->{$key}];
53 }
54 2 ▶ if (ref($self->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key}) 0 2 2
55 0 foreach my $entry (@{$self->{$key}}) {
56 0 ▶ $entry = Data::Identifier->new(ise => $entry) unless ref $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry 0 0 0
57 }
58 }
59 }
60  
61 1 ▶ if (ref($self->{supported_features})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"supported_features"}) 0 1 1
62 0 push(@{$self->{supported_features}}, Data::Identifier->new(ise => DOT_REPEAT_ISE));
63 }
64  
65 1 ▶ $self->{utf8} = $opts{utf8} //= 'auto';
Condition50%1/2
$opts{"utf8"} //= "auto"
l!l
01
MC/DC0%0/1
$opts{"utf8"} //= "auto"
$opts{"utf8"}
Truth table50%1/2
A
A= $opts{"utf8"}
Aresult
11
00
66 1 ▶ if ($opts{utf8} && $opts{utf8} ne 'auto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'utf8'} and $opts{'utf8'} ne 'auto') { } 0 1 1
Condition33%1/3
$opts{"utf8"} and $opts{"utf8"} ne "auto"
!ll&&!rl&&r
010
MC/DC0%0/2
$opts{"utf8"} and $opts{"utf8"} ne "auto"
$opts{"utf8"} $opts{"utf8"} ne "auto"
Truth table33%1/3
A and B
A= $opts{"utf8"}B= $opts{"utf8"} ne "auto"
ABresult
0X0
100
111
67 0 $self->{unescape} = \&_unescape_utf8;
68 } else {
69 1 $self->{unescape} = \&uri_unescape;
70 }
71  
72 1 $self->{dot_repreat} = 0;
73  
74 1 return $self;
75 }
76  
77 0 ▶sub _special {
Subroutine _special: not called CC=3 SCAR=24.8
78 0 my ($str) = @_;
79  
80 0 ▶ if ($str eq '!null') {
Branch: 2 branches
BranchTrueFalseTotal
if ($str eq '!null') { } 0 0 0
elsif ($str eq '!empty') { } 0 0 0
81 0 return undef;
82 } elsif ($str eq '!empty') {
83 0 return '';
84 } else {
85 0 croak 'Invalid input';
86 }
87 }
88  
89 1 ▶sub _check_supported {
Subroutine _check_supported: called CC=4 SCAR=19.7
90 1 my ($self, $key, $value) = @_;
91 1 my $list = $self->{$key};
92 1 my $ise = $value->ise;
93  
94 1 ▶ return if $list eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $list eq "all" 1 0 1
95  
96 0 foreach my $entry (@{$list}) {
97 0 ▶ return if $entry->ise eq $ise;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->ise eq $ise 0 0 0
98 }
99  
100 0 croak 'Unsupported value for '.$key.': '.$ise;
101 }
102  
103 1 ▶sub _handle_special {
Subroutine _handle_special: called CC=18 SCAR=45.2
104 1 my ($self, $type, $marker, @args) = @_;
105 1 my $line = $self->{fh}->input_line_number;
106  
107 1 ▶ if ($marker eq 'ValueFile') {
Branch: 2 branches
BranchTrueFalseTotal
if ($marker eq 'ValueFile') { } 1 0 1
elsif ($marker eq 'Feature') { } 0 0 0
108 1 ▶ @args = @args[0,1] if scalar(@args) == 4 && !defined($args[-1]) && !defined($args[-2]);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @args == 4 and not defined $args[-1] and not defined $args[-2] 0 1 1
Condition33%2/6
scalar @args == 4 and not defined $args[-1] and not defined $args[-2]
!ll&&!rl&&r
100
scalar @args == 4 and not defined $args[-1]
!ll&&!rl&&r
100
MC/DC0%0/3
scalar @args == 4 and not defined $args[-1] and not defined $args[-2]
scalar @args == 4 not defined $args[-1] not defined $args[-2]
Truth table25%1/4
A and not(B) and not(C)
A= scalar @args == 4B= not defined $args[-1]C= not defined $args[-2]
ABCresult
0XX0
10X0
1100
1111
109 1 ▶ croak 'ValueFile (magic) marker at wrong line' unless $line == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $line == 1 0 1 1
110 1 ▶ croak 'ValueFile (magic) marker not marked required' unless $type eq '!';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "!" 0 1 1
111 1 ▶ croak 'ValueFile (magic) marker with wrong number of arguments' unless scalar(@args) && scalar(@args) <= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @args and scalar @args <= 2 0 1 1
Condition33%1/3
scalar @args and scalar @args <= 2
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @args and scalar @args <= 2
scalar @args scalar @args <= 2
Truth table33%1/3
A and B
A= scalar @argsB= scalar @args <= 2
ABresult
0X0
100
111
112 1 ▶ croak 'ValueFile (magic) marker not using supported format' unless $args[0] eq FORMAT_ISE;
Branch: 1 branch
BranchTrueFalseTotal
unless $args[0] eq "54bf8af4-b1d7-44da-af48-5278d11e8f32" 0 1 1
113  
114 1 ▶ if (scalar(@args) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 1) 1 0 1
115 1 $self->_check_supported(supported_formats => $self->{format} = Data::Identifier->new(ise => $args[1]));
116 }
117  
118 1 ▶ $self->_check_utf8($marker => $self->{format}) if $self->{utf8} eq 'auto';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"utf8"} eq "auto" 1 0 1
119  
120 1 return;
121 } elsif ($marker eq 'Feature') {
122 0 my $id;
123  
124 0 ▶ croak 'Feature marker with wrong number of arguments' unless scalar(@args) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @args == 1 0 0 0
125  
126 0 ▶ push(@{$self->{features} //= []}, $id = Data::Identifier->new(ise => $args[0]));
Condition0%0/2
$self->{"features"} //= []
l!l
00
MC/DC0%0/1
$self->{"features"} //= []
$self->{"features"}
Truth table0%0/2
A
A= $self->{"features"}
Aresult
11
00
127  
128 0 ▶ $self->_check_supported(supported_features => $id) if $type eq '!';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "!" 0 0 0
129 0 ▶ $self->_check_utf8($marker => $id) if $self->{utf8} eq 'auto';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"utf8"} eq "auto" 0 0 0
130 0 ▶ $self->{dot_repreat} ||= $id->eq(DOT_REPEAT_ISE);
Condition0%0/3
$self->{"dot_repreat"} ||= $id->eq("2ec67bbe-4698-4a0c-921d-1f0951923ee6")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dot_repreat"} ||= $id->eq("2ec67bbe-4698-4a0c-921d-1f0951923ee6")
$self->{"dot_repreat"} $id->eq("2ec67bbe-4698-4a0c-921d-1f0951923ee6")
Truth table0%0/3
A ||= B
A= $self->{"dot_repreat"}B= $id->eq("2ec67bbe-4698-4a0c-921d-1f0951923ee6")
ABresult
1X1
011
000
131  
132 0 return;
133 }
134  
135 0 croak 'Invalid marker: '.$marker;
136 }
137  
138 1 ▶sub _check_utf8 {
Subroutine _check_utf8: called CC=2 SCAR=7.0
139 1 my ($self, $marker, $id) = @_;
140 1 ▶ if (File::ValueFile->_is_utf8($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("File::ValueFile"->_is_utf8($id)) 1 0 1
141 1 $self->{unescape} = \&_unescape_utf8;
142 1 $self->{utf8} = 1;
143 }
144 }
145  
146  
147 1 ▶sub read_to_cb {
Subroutine read_to_cb: called CC=20 SCAR=48.3
Pod documented
148 1 my ($self, $cb) = @_;
149 1 my $fh = $self->{fh};
150 1 my $unescape = $self->{unescape};
151 1 my @last_line;
152  
153 1 $fh->seek(0, SEEK_SET);
154 1 $fh->input_line_number(0);
155  
156 1 delete $self->{format};
157 1 delete $self->{features};
158  
159 1 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 1 1 2
160 1 $line =~ s/\r?\n$//;
161 1 $line =~ s/#.*$//;
162 1 $line =~ s/^\xEF\xBB\xBF//; # skip BOMs.
163 1 $line =~ s/\s+/ /g;
164 1 $line =~ s/ $//;
165 1 $line =~ s/^ //;
166  
167 1 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 1 1
168  
169 1 ▶ if ($line =~ s/^\!([\!\?\&])//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\!([\!\?\&])//u) 1 0 1
170 1 my $type = $1;
171  
172 1 ▶ if ($self->{dot_repreat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dot_repreat'}) { } 0 1 1
173 0 my @line = split(/\s+/, $line);
174 0 my $x = 0;
175 0 foreach my $e (@line) {
176 0 ▶ if ($e eq '.') {
Branch: 4 branches
BranchTrueFalseTotal
if ($e eq '.') { } 0 0 0
elsif ($e =~ s/^\.\.+$//u) { } 0 0 0
elsif ($e =~ /^[a-zA-Z0-9\-:\._~]*$/u) { } 0 0 0
elsif ($e =~ /^\!/u) { } 0 0 0
177 0 $e = $last_line[$x];
178 } elsif ($e =~ s/^\.\.+$//) {
179 # done in match
180 } elsif ($e =~ KEYWORD_OK) {
181 # no-op
182 } elsif ($e =~ /^\!/) {
183 0 $e = _special($_);
184 } else {
185 0 $e = $unescape->($e);
186 }
187 0 $x++;
188 }
189  
190 0 $self->_handle_special($type, @line);
191 0 @last_line = @line;
192 } else {
193 $self->_handle_special($type, map{
194 1 ▶ $_ =~ KEYWORD_OK ? $_ :
Branch: 2 branches
BranchTrueFalseTotal
$_ =~ /^[a-zA-Z0-9\-:\._~]*$/u ? : 3 0 3
$_ =~ /^\!/u ? : 0 0 0
195 $_ =~ /^\!/ ? _special($_) : $unescape->($_)
196 }(split(/\s+/, $line)));
197 }
198  
199 # Reload:
200 1 $unescape = $self->{unescape};
201  
202 1 next;
203 }
204  
205 0 ▶ if ($self->{dot_repreat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dot_repreat'}) { } 0 0 0
206 0 my @line = split(/\s+/, $line);
207 0 my $x = 0;
208 0 foreach my $e (@line) {
209 0 ▶ if ($e eq '.') {
Branch: 4 branches
BranchTrueFalseTotal
if ($e eq '.') { } 0 0 0
elsif ($e =~ /^\.+$/u) { } 0 0 0
elsif ($e =~ /^[a-zA-Z0-9\-:\._~]*$/u) { } 0 0 0
elsif ($e =~ /^\!/u) { } 0 0 0
210 0 $e = $last_line[$x];
211 } elsif ($e =~ /^\.+$/) {
212 0 $e =~ s/^\.//;
213 } elsif ($e =~ KEYWORD_OK) {
214 # no-op
215 } elsif ($e =~ /^\!/) {
216 0 $e = _special($e);
217 } else {
218 0 $e = $unescape->($e);
219 }
220 0 $x++;
221 }
222  
223 0 $self->$cb(@line);
224 0 @last_line = @line;
225 } else {
226 $self->$cb(map{
227 0 ▶ $_ =~ KEYWORD_OK ? $_ :
Branch: 2 branches
BranchTrueFalseTotal
$_ =~ /^[a-zA-Z0-9\-:\._~]*$/u ? : 0 0 0
$_ =~ /^\!/u ? : 0 0 0
228 $_ =~ /^\!/ ? _special($_) : $unescape->($_)
229 }(split(/\s+/, $line)));
230 }
231 }
232 }
233  
234  
235 0 ▶sub read_as_hash {
Subroutine read_as_hash: not called CC=1 SCAR=6.9
Pod documented
236 0 my ($self) = @_;
237 0 my %hash;
238  
239 0 ▶ $self->read_to_cb(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
240 0 my (undef, @line) = @_;
241 0 ▶ croak 'Invalid data: Not key-value' unless scalar(@line) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @line == 2 0 0 0
242 0 ▶ croak 'Invalid data: Null key' unless defined($line[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line[0] 0 0 0
243 0 ▶ croak 'Invalid data: Duplicate key: '.$line[0] if exists $hash{$line[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash{$line[0]} 0 0 0
244 0 $hash{$line[0]} = $line[1];
245 0 });
246  
247 0 return \%hash;
248 }
249  
250  
251 0 ▶sub read_as_hash_of_arrays {
Subroutine read_as_hash_of_arrays: not called CC=1 SCAR=6.9
Pod documented
252 0 my ($self) = @_;
253 0 my %hash;
254  
255 0 ▶ $self->read_to_cb(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
256 0 my (undef, @line) = @_;
257 0 ▶ croak 'Invalid data: Not key-value' unless scalar(@line) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @line == 2 0 0 0
258 0 ▶ croak 'Invalid data: Null key' unless defined($line[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line[0] 0 0 0
259 0 ▶ push(@{$hash{$line[0]} //=[]}, $line[1]);
Condition0%0/2
$hash{$line[0]} //= []
l!l
00
MC/DC0%0/1
$hash{$line[0]} //= []
$hash{$line[0]}
Truth table0%0/2
A
A= $hash{$line[0]}
Aresult
11
00
260 0 });
261  
262 0 return \%hash;
263 }
264  
265  
266 0 ▶sub read_as_simple_tree {
Subroutine read_as_simple_tree: not called CC=1 SCAR=6.9
Pod documented
267 0 my ($self) = @_;
268 0 my $tree;
269  
270 0 ▶ $self->read_to_cb(sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
271 0 my (undef, @line) = @_;
272 0 my $root = \$tree;
273  
274 0 ▶ while (scalar(@line) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @line > 1) 0 0 0
275 0 my $el = shift(@line);
276  
277 0 ▶ if (ref(${$root})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${$root;}) { } 0 0 0
278 0 $root = \${$root}->{$el};
279 } else {
280 0 ${$root} = {
281 0 ▶ (defined(${$root}) ? (_ => ${$root}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined ${$root;} ? : 0 0 0
282 $el => undef,
283 };
284 0 $root = \${$root}->{$el};
285 }
286 }
287  
288 0 ▶ if (ref(${$root}) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref ${$root;} eq 'ARRAY') { } 0 0 0
elsif (defined ${$root;}) { } 0 0 0
289 0 push(@{${$root}}, @line);
290 0 } elsif (defined ${$root}) {
291 0 ▶ croak 'Invalid data with mixed number of levels' if ref ${$root};
Branch: 1 branch
BranchTrueFalseTotal
if ref ${$root;} 0 0 0
292 0 ${$root} = [${$root}, @line];
293 } else {
294 0 ${$root} = $line[0];
295 }
296 0 });
297  
298 0 return $tree;
299 }
300  
301  
302 0 ▶sub read_as_taglist {
Subroutine read_as_taglist: not called CC=3 SCAR=24.8
Pod documented
303 0 state $tagpool_source_format = Data::Identifier->new(uuid => 'e5da6a39-46d5-48a9-b174-5c26008e208e', displayname => 'tagpool-source-format')->register;
304 0 state $tagpool_taglist_format_v1 = Data::Identifier->new(uuid => 'afdb46f2-e13f-4419-80d7-c4b956ed85fa', displayname => 'tagpool-taglist-format-v1')->register;
305 0 state $tagpool_httpd_htdirectories_format = Data::Identifier->new(uuid => '25990339-3913-4b5a-8bcf-5042ef6d8b5e', displayname => 'tagpool-httpd-htdirectories-format')->register;
306 0 my ($self, %opts) = @_;
307 0 my $as = delete $opts{as};
308 0 my %list;
309 my $format;
310  
311 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
312  
313 0 ▶ $self->read_to_cb(sub {
Subroutine __ANON__: not called CC=52 SCAR=79.2
314 0 my (undef, @line) = @_;
315 0 my $tag;
316  
317 0 ▶ $format //= $self->format(default => undef);
Condition0%0/3
$format //= $self->format("default", undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$format //= $self->format("default", undef)
$format $self->format("default", undef)
Truth table0%0/3
A //= B
A= $formatB= $self->format("default", undef)
ABresult
1X1
011
000
318  
319 0 ▶ if ((Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1)) && scalar(@line) >= 2 && defined($line[0]) && defined($line[1])) {
Branch: 3 branches
BranchTrueFalseTotal
if (Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1) and scalar @line >= 2 and defined $line[0] and defined $line[1]) { } 0 0 0
elsif (Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0] and defined $line[1] and defined $line[2] and $line[0] eq 'directory') { } 0 0 0
elsif (not defined $format) { } 0 0 0
Condition0%0/12
Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1) and scalar @line >= 2 and defined $line[0] and defined $line[1]
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1) and scalar @line >= 2 and defined $line[0]
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1) and scalar @line >= 2
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_source_format) or Data::Identifier::eq($format, $tagpool_taglist_format_v1)
l!l&&r!l&&!r
000
MC/DC0%0/5
Data::Identifier::eq($format, $tagpool_source_format) || Data::Identifier::eq($format, $tagpool_taglist_format_v1) and scalar @line >= 2 and defined $line[0] and defined $line[1]
Data::Identifier::eq($format, $tagpool_source_format) Data::Identifier::eq($format, $tagpool_taglist_format_v1) scalar @line >= 2 defined $line[0] defined $line[1]
Truth table0%0/9
A or B and C and D and E
A= Data::Identifier::eq($format, $tagpool_source_format)B= Data::Identifier::eq($format, $tagpool_taglist_format_v1)C= scalar @line >= 2D= defined $line[0]E= defined $line[1]
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
320 0 ▶ if ($line[0] eq 'tag' && scalar(@line) == 3) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line[0] eq 'tag' and scalar @line == 3) { } 0 0 0
elsif ($line[0] eq 'tag-metadata' and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq 'ddd60c5c-2934-404f-8f2d-fcb4da88b633' and $line[4] eq 'bfae7574-3dae-425d-89b1-9c087c140c23') { } 0 0 0
elsif ($line[0] =~ /^tag(?:-.+)?$/u or $line[0] eq 'rule' or $line[0] eq 'filter' or $line[0] eq 'subject') { } 0 0 0
Condition0%0/3
$line[0] eq "tag" and scalar @line == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$line[0] eq "tag" and scalar @line == 3
$line[0] eq "tag" scalar @line == 3
Truth table0%0/3
A and B
A= $line[0] eq "tag"B= scalar @line == 3
ABresult
0X0
100
111
321 0 $tag = Data::Identifier->new(ise => $line[1], displayname => $line[2]);
322 ▶ } elsif ($line[0] eq 'tag-metadata' && scalar(@line) == 7 && defined($line[2]) && !defined($line[3]) && defined($line[4]) && !defined($line[5]) && defined($line[6]) && $line[2] eq ASI_ISE && $line[4] eq TAGNAME_ISE) {
Condition0%0/24
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" and $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633"
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7
!ll&&!rl&&r
000
MC/DC0%0/9
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" and $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
$line[0] eq "tag-metadata" scalar @line == 7 defined $line[2] not defined $line[3] defined $line[4] not defined $line[5] defined $line[6] $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
Truth table0%0/10
A and B and C and not(D) and E and not(F) and G and H and I
A= $line[0] eq "tag-metadata"B= scalar @line == 7C= defined $line[2]D= not defined $line[3]E= defined $line[4]F= not defined $line[5]G= defined $line[6]H= $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633"I= $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
111110XXX0
1111110XX0
11111110X0
1111111100
1111111111
323 0 $tag = Data::Identifier->new(ise => $line[1], displayname => $line[6]);
324 ▶ } elsif ($line[0] =~ /^tag(?:-.+)?$/ || $line[0] eq 'rule' || $line[0] eq 'filter' || $line[0] eq 'subject') {
Condition0%0/9
$line[0] =~ /^tag(?:-.+)?$/u or $line[0] eq "rule" or $line[0] eq "filter" or $line[0] eq "subject"
l!l&&r!l&&!r
000
$line[0] =~ /^tag(?:-.+)?$/u or $line[0] eq "rule" or $line[0] eq "filter"
l!l&&r!l&&!r
000
$line[0] =~ /^tag(?:-.+)?$/u or $line[0] eq "rule"
l!l&&r!l&&!r
000
MC/DC0%0/4
$line[0] =~ /^tag(?:-.+)?$/u or $line[0] eq "rule" or $line[0] eq "filter" or $line[0] eq "subject"
$line[0] =~ /^tag(?:-.+)?$/u $line[0] eq "rule" $line[0] eq "filter" $line[0] eq "subject"
Truth table0%0/5
A or B or C or D
A= $line[0] =~ /^tag(?:-.+)?$/uB= $line[0] eq "rule"C= $line[0] eq "filter"D= $line[0] eq "subject"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
325 0 $tag = Data::Identifier->new(ise => $line[1]);
326 }
327 ▶ } elsif (Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) && scalar(@line) == 3 && defined($line[0]) && defined($line[1]) && defined($line[2]) && $line[0] eq 'directory') {
Condition0%0/15
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0] and defined $line[1] and defined $line[2] and $line[0] eq "directory"
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0] and defined $line[1] and defined $line[2]
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0] and defined $line[1]
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0]
!ll&&!rl&&r
000
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3
!ll&&!rl&&r
000
MC/DC0%0/6
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) and scalar @line == 3 and defined $line[0] and defined $line[1] and defined $line[2] and $line[0] eq "directory"
Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format) scalar @line == 3 defined $line[0] defined $line[1] defined $line[2] $line[0] eq "directory"
Truth table0%0/7
A and B and C and D and E and F
A= Data::Identifier::eq($format, $tagpool_httpd_htdirectories_format)B= scalar @line == 3C= defined $line[0]D= defined $line[1]E= defined $line[2]F= $line[0] eq "directory"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
328 0 $tag = Data::Identifier->new(ise => $line[1]);
329 } elsif (!defined($format)) {
330 0 ▶ if (scalar(@line) > 1 && defined($line[0]) && defined($line[1]) && $line[0] =~ /^tag-(?:ise|metadata|relation)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @line > 1 and defined $line[0] and defined $line[1] and $line[0] =~ /^tag-(?:ise|metadata|relation)$/u) { } 0 0 0
elsif ($line[0] eq 'tag' and scalar @line == 3) { } 0 0 0
Condition0%0/9
scalar @line > 1 and defined $line[0] and defined $line[1] and $line[0] =~ /^tag-(?:ise|metadata|relation)$/u
!ll&&!rl&&r
000
scalar @line > 1 and defined $line[0] and defined $line[1]
!ll&&!rl&&r
000
scalar @line > 1 and defined $line[0]
!ll&&!rl&&r
000
MC/DC0%0/4
scalar @line > 1 and defined $line[0] and defined $line[1] and $line[0] =~ /^tag-(?:ise|metadata|relation)$/u
scalar @line > 1 defined $line[0] defined $line[1] $line[0] =~ /^tag-(?:ise|metadata|relation)$/u
Truth table0%0/5
A and B and C and D
A= scalar @line > 1B= defined $line[0]C= defined $line[1]D= $line[0] =~ /^tag-(?:ise|metadata|relation)$/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
331 0 ▶ if ($line[0] eq 'tag-metadata' && scalar(@line) == 7 && defined($line[2]) && !defined($line[3]) && defined($line[4]) && !defined($line[5]) && defined($line[6]) && $line[2] eq ASI_ISE && $line[4] eq TAGNAME_ISE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[0] eq 'tag-metadata' and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq 'ddd60c5c-2934-404f-8f2d-fcb4da88b633' and $line[4] eq 'bfae7574-3dae-425d-89b1-9c087c140c23') { } 0 0 0
Condition0%0/24
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" and $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633"
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2]
!ll&&!rl&&r
000
$line[0] eq "tag-metadata" and scalar @line == 7
!ll&&!rl&&r
000
MC/DC0%0/9
$line[0] eq "tag-metadata" and scalar @line == 7 and defined $line[2] and not defined $line[3] and defined $line[4] and not defined $line[5] and defined $line[6] and $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" and $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
$line[0] eq "tag-metadata" scalar @line == 7 defined $line[2] not defined $line[3] defined $line[4] not defined $line[5] defined $line[6] $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633" $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
Truth table0%0/10
A and B and C and not(D) and E and not(F) and G and H and I
A= $line[0] eq "tag-metadata"B= scalar @line == 7C= defined $line[2]D= not defined $line[3]E= defined $line[4]F= not defined $line[5]G= defined $line[6]H= $line[2] eq "ddd60c5c-2934-404f-8f2d-fcb4da88b633"I= $line[4] eq "bfae7574-3dae-425d-89b1-9c087c140c23"
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
111110XXX0
1111110XX0
11111110X0
1111111100
1111111111
332 0 $tag = Data::Identifier->new(ise => $line[1], displayname => $line[6]);
333 } else {
334 0 $tag = Data::Identifier->new(ise => $line[1]);
335 }
336 ▶ } elsif ($line[0] eq 'tag' && scalar(@line) == 3) {
Condition0%0/3
$line[0] eq "tag" and scalar @line == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$line[0] eq "tag" and scalar @line == 3
$line[0] eq "tag" scalar @line == 3
Truth table0%0/3
A and B
A= $line[0] eq "tag"B= scalar @line == 3
ABresult
0X0
100
111
337 0 $tag = Data::Identifier->new(ise => $line[1], displayname => $line[2]);
338 }
339  
340 0 ▶ unless (defined $tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tag) 0 0 0
341 0 foreach my $entry (@line) {
342 0 ▶ if (defined($entry) && $entry =~ RE_ISE) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry and $entry =~ /^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/u) 0 0 0
Condition0%0/3
defined $entry and $entry =~ /^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry and $entry =~ /^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/u
defined $entry $entry =~ /^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/u
Truth table0%0/3
A and B
A= defined $entryB= $entry =~ /^(?:[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+:.*)$/u
ABresult
0X0
100
111
343 0 my $tag = Data::Identifier->new(ise => $entry);
344 0 ▶ $list{$tag->ise} //= $tag;
Condition0%0/3
$list{$tag->ise} //= $tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$list{$tag->ise} //= $tag
$list{$tag->ise} $tag
Truth table0%0/3
A //= B
A= $list{$tag->ise}B= $tag
ABresult
1X1
011
000
345 }
346 }
347 }
348 }
349  
350 0 ▶ if (defined $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag) 0 0 0
351 0 my $ise = $tag->ise;
352 0 my $old = $list{$ise};
353  
354 0 ▶ if (defined $old) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) 0 0 0
355 0 ▶ $tag = $old if defined $old->displayname(default => undef, no_defaults => 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $old->displayname("default", undef, "no_defaults", 1) 0 0 0
356 }
357  
358 0 $list{$tag->ise} = $tag;
359 }
360 0 });
361  
362 0 ▶ return [map {$_->as($as, so => $self)} values %list] if defined $as;
Branch: 1 branch
BranchTrueFalseTotal
if defined $as 0 0 0
363  
364 0 return [values %list];
365 }
366  
367  
368 1 ▶sub format {
Subroutine format: called CC=4 SCAR=17.9
Pod documented
369 1 my ($self, %opts) = @_;
370  
371 1 ▶ if (defined $self->{format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"format"}) 1 0 1
372 1 ▶ return $self->{format}->as($opts{as}, so => $self) if defined $opts{as};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"as"} 0 1 1
373 1 return $self->{format};
374 }
375  
376 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
377 0 croak 'No value for format';
378 }
379  
380  
381 0 ▶sub features {
Subroutine features: not called CC=3 SCAR=24.8
Pod documented
382 0 my ($self, %opts) = @_;
383 0 ▶ return @{$self->{features}} if defined $self->{features};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"features"} 0 0 0
384 0 ▶ return @{$opts{default}} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
385 0 croak 'No value for features';
386 }
387  
388  
389 # ---- Private helpers ----
390  
391 0 ▶sub _unescape_utf8 {
Subroutine _unescape_utf8: not called CC=1 SCAR=6.9
392 0 my ($text) = @_;
393 0 state $utf8 = Encode::find_encoding('UTF-8');
394 0 return $utf8->decode(uri_unescape($text));
395 }
396  
397 2 1;
398  
399 __END__
↑ Summary ValueFile/Simple/Writer.pm »