blib/lib/Text/Table/Read/RelationOn/Tiny.pm

filter: Statementstmt 98.8% 348 / 352 Branchbran 97.2% 247 / 254 Conditioncond 90.0% 27 / 30 MC/DCmcdc 77.7% 14 / 18 Subroutinesub 100% 26 / 26 Podpod 100% 11 / 11 totaltotal 97.4% 673 / 691 CC 159 SCAR 34.9
CC
159
Cov
98%
new
62.0
__ANON__
41.1
get
14.0
CRAP 32.7
↑ Summary
1 package Text::Table::Read::RelationOn::Tiny;
2  
3 9 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # The following must be on the same line to ensure that $VERSION is read
11 # correctly by PAUSE and installer tools. See docu of 'version'.
12 9 ▶use version 0.77; our $VERSION = version->declare("v3.0.4");
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 68 ▶sub new {
Subroutine new: called CC=62 SCAR=41.3
Pod documented
16 68 my $class = shift;
17 68 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 68 68
18 68 ▶ croak("Odd number of arguments") if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 67 68
19 67 my %args = @_;
20 67 ▶ my $inc = delete $args{inc} // "X";
Condition100%2/2
delete $args{"inc"} // "X"
l!l
562
MC/DC100%1/1
delete $args{"inc"} // "X"
delete $args{"inc"}
Truth table100%2/2
A
A= delete $args{"inc"}
Aresult
11
00
21 67 ▶ my $noinc = delete $args{noinc} // "";
Condition100%2/2
delete $args{"noinc"} // ""
l!l
760
MC/DC100%1/1
delete $args{"noinc"} // ""
delete $args{"noinc"}
Truth table100%2/2
A
A= delete $args{"noinc"}
Aresult
11
00
22 67 my $set = delete $args{set};
23 67 my $eqs = delete $args{eqs};
24 67 my $ext = delete $args{ext};
25 67 my $elem_ids = delete $args{elem_ids};
26 67 ▶ croak(join(", ", sort(keys(%args))) . ": unexpected argument") if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 1 66 67
27 66 ▶ croak("inc: must be a scalar") if ref($inc);
Branch: 1 branch
BranchTrueFalseTotal
if ref $inc 1 65 66
28 65 ▶ croak("noinc: must be a scalar") if ref($noinc);
Branch: 1 branch
BranchTrueFalseTotal
if ref $noinc 1 64 65
29 64 s/^\s+// for ($inc, $noinc);
30 64 s/\s+$// for ($inc, $noinc);
31 64 ▶ croak("inc and noinc must be different") if $inc eq $noinc;
Branch: 1 branch
BranchTrueFalseTotal
if $inc eq $noinc 1 63 64
32 63 ▶ croak("'|' is not allowed for inc or noinc") if $inc eq '|' || $noinc eq '|';
Branch: 1 branch
BranchTrueFalseTotal
if $inc eq "|" or $noinc eq "|" 2 61 63
Condition100%3/3
$inc eq "|" or $noinc eq "|"
l!l&&r!l&&!r
1161
MC/DC100%2/2
$inc eq "|" or $noinc eq "|"
$inc eq "|" $noinc eq "|"
Truth table100%3/3
A or B
A= $inc eq "|"B= $noinc eq "|"
ABresult
1X1
011
000
33 61 my $self = {inc => $inc,
34 noinc => $noinc,
35 };
36 61 ▶ if (defined($set)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) { } 48 13 61
37 48 my %seen;
38 48 ▶ croak("set: must be an array reference") if ref($set) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $set ne "ARRAY" 1 47 48
39 47 my $cnt = 1;
40 47 foreach my $e (@$set) {
41 152 ▶ if (ref($e)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e) { } 21 131 152
42 21 ▶ croak("set: entry $cnt: invalid") if ref($e) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $e ne "ARRAY" 1 20 21
43 20 ▶ croak("set: entry $cnt: array not allowed if eqs is specified") if $eqs;
Branch: 1 branch
BranchTrueFalseTotal
if $eqs 1 19 20
44 19 ▶ croak("set: entry $cnt: array entry must not be empty") if !@{$e};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$e;} 2 17 19
45 17 foreach my $sub_e (@$e) {
46 35 ▶ croak("set: entry $cnt: subarray contains invalid entry")
Branch: 1 branch
BranchTrueFalseTotal
if ref $sub_e or not defined $sub_e 3 32 35
Condition100%3/3
ref $sub_e or not defined $sub_e
l!l&&r!l&&!r
2132
MC/DC100%2/2
ref $sub_e or not defined $sub_e
ref $sub_e not defined $sub_e
Truth table100%3/3
A or not(B)
A= ref $sub_eB= not defined $sub_e
ABresult
1X1
011
000
47 if ref($sub_e) || !defined($sub_e);
48 32 ▶ croak("set: '$sub_e': duplicate element") if exists($seen{$sub_e});
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen{$sub_e} 4 28 32
49 28 $seen{$sub_e} = undef;
50 }
51 } else {
52 131 ▶ croak("set: entry $cnt: invalid") if !defined($e);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 1 130 131
53 130 ▶ croak("set: '$e': duplicate element") if exists($seen{$e});
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen{$e} 1 129 130
54 129 $seen{$e} = undef;
55 }
56 139 ++$cnt;
57 }
58 34 $self->{prespec} = 1;
59 } else {
60 13 ▶ croak("eqs: not allowed without argument 'set'") if defined($eqs);
Branch: 1 branch
BranchTrueFalseTotal
if defined $eqs 1 12 13
61 12 $self->{prespec} = "";
62 }
63 46 ▶ if (defined($elem_ids)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $elem_ids) 13 33 46
64 13 ▶ croak("elem_ids: not allowed without arguments 'set' and 'ext'") if !(defined($ext) &&
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ext and defined $set 3 10 13
Condition100%3/3
defined $ext and defined $set
!ll&&!rl&&r
2110
MC/DC100%2/2
defined $ext and defined $set
defined $ext defined $set
Truth table100%3/3
A and B
A= defined $extB= defined $set
ABresult
0X0
100
111
65 defined($set));
66 10 ▶ croak("elem_ids: must be a hash ref") if ref($elem_ids) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $elem_ids ne "HASH" 1 9 10
67 }
68 42 my $elems;
69 my $tabElems; # elems to be used in table --> indes in @elems
70 42 my $eqIds;
71 42 ▶ if ($ext) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ext) { } 12 30 42
elsif (ref $set) { } 21 9 30
72 12 ▶ if ($set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set) { } 11 1 12
73 11 foreach my $e (@$set) {
74 42 ▶ croak("set: no subarray allowed if 'ext' is specified") if ref($e);
Branch: 1 branch
BranchTrueFalseTotal
if ref $e 1 41 42
75 }
76 10 ▶ if ($elem_ids) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem_ids) { } 8 2 10
77 8 ▶ croak("elem_ids: wrong number of entries") if keys(%$elem_ids) != @$set;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$elem_ids != @$set 1 7 8
78 7 foreach my $e (@$set) {
79 24 my $e_id = $elem_ids->{$e};
80 24 ▶ croak("elem_ids: '$e': missing value") if !defined($e_id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e_id 2 22 24
81 22 ▶ croak("elem_ids: '$e': entry has wrong value") if ($e_id !~ /^\d$/ ||
Branch: 1 branch
BranchTrueFalseTotal
if not $e_id =~ /^\d$/ && defined $set->[$e_id] or $set->[$e_id] ne $e 3 19 22
Condition100%6/6
not $e_id =~ /^\d$/ && defined $set->[$e_id] or $set->[$e_id] ne $e
l!l&&r!l&&!r
2119
$e_id =~ /^\d$/ && defined $set->[$e_id]
!ll&&!rl&&r
1120
MC/DC100%3/3
not $e_id =~ /^\d$/ && defined $set->[$e_id] or $set->[$e_id] ne $e
$e_id =~ /^\d$/ defined $set->[$e_id] $set->[$e_id] ne $e
Truth table100%4/4
not(A && B) or C
A= $e_id =~ /^\d$/B= defined $set->[$e_id]C= $set->[$e_id] ne $e
ABCresult
0XX1
10X1
1111
1100
82 !defined($set->[$e_id]) ||
83 $set->[$e_id] ne $e);
84 }
85 } else {
86 2 my $idx = 0;
87 2 $elem_ids = {map {$_ => $idx++} @$set};
88 }
89 4 $elems = $set;
90 } else {
91 1 croak("ext: not allowed without argument 'set'")
92 }
93 4 %$tabElems = %$elem_ids;
94 } elsif (ref($set)) {
95 21 my @elems; # elems
96 my %ids; # indices in basic elems
97 21 my @eqs_tmp;
98  
99 21 foreach my $entry (@$set) {
100 75 ▶ if (ref($entry)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry) { } 5 70 75
101 5 push(@elems, $entry->[0]);
102 5 $ids{$entry->[0]} = $#elems;
103 5 ▶ for (my $j = 1; $j < @$entry; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @$entry) 4 5 9
104 4 my $ent_j = $entry->[$j];
105 4 push(@elems, $ent_j);
106 4 $ids{$ent_j} = $#elems;
107 }
108 5 ▶ push(@eqs_tmp, $entry) if @$entry > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$entry > 1 2 3 5
109 } else {
110 70 push(@elems, $entry);
111 70 $ids{$entry} = $#elems;
112 }
113 }
114 21 ▶ croak("Internal error") if (defined($eqs) && @eqs_tmp); # Should never happen.
Branch: 1 branch
BranchTrueFalseTotal
if defined $eqs and @eqs_tmp 0 21 21
Condition66%2/3
defined $eqs and @eqs_tmp
!ll&&!rl&&r
10110
MC/DC0%0/2
defined $eqs and @eqs_tmp
defined $eqs @eqs_tmp
Truth table66%2/3
A and B
A= defined $eqsB= @eqs_tmp
ABresult
0X0
100
111
115 21 ▶ $eqs = \@eqs_tmp if @eqs_tmp;
Branch: 1 branch
BranchTrueFalseTotal
if @eqs_tmp 1 20 21
116 21 ($elems, $elem_ids, $tabElems, $eqIds) = (\@elems, \%ids, {%ids}, {});
117 }
118 34 ▶ if (defined($eqs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $eqs) 14 20 34
119 14 ▶ croak("eqs: must be an array ref") if ref($eqs) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $eqs ne "ARRAY" 1 13 14
120 13 my %eqIds; # idx => array of equivalent idxes
121 my %seen;
122 13 foreach my $eqArray (@{$eqs}) {
123 28 ▶ croak("eqs: each entry must be an array ref") if ref($eqArray) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $eqArray ne "ARRAY" 1 27 28
124 27 ▶ next if !@{$eqArray};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$eqArray;} 2 25 27
125 25 foreach my $entry (@{$eqArray}) {
126 57 ▶ croak("eqs: subentry contains a non-scalar") if ref($entry);
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry 1 56 57
127 56 ▶ croak("eqs: subentry undefined") if !defined($entry);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry 1 55 56
128 55 ▶ croak("eqs: '$entry': unknown element") if !exists($elem_ids->{$entry});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $elem_ids->{$entry} 2 53 55
129 53 ▶ croak("eqs: '$entry': duplicate element") if exists($seen{$entry});
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen{$entry} 2 51 53
130 51 $seen{$entry} = undef;
131 }
132 19 ▶ next if @{$eqArray} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$eqArray;} == 1 5 14 19
133 14 my @tmp = @{$eqArray};
134 14 my @eqArray;
135 14 $eqIds{$tabElems->{shift(@tmp)}} = \@eqArray;
136 14 foreach my $e (@tmp) {
137 27 push(@eqArray, delete $tabElems->{$e});
138 }
139 }
140 6 $eqIds = \%eqIds;
141 }
142 26 @{$self}{qw(elems elem_ids tab_elems eq_ids)} = ($elems, $elem_ids, $tabElems, $eqIds);
143 26 return bless($self, $class);
144 }
145  
146  
147 #
148 # $self->$_reset() - set (matrix elems elem_ids tab_elems eq_ids) to
149 # empty structures
150 # $self->$_reset(1) - set (matrix elems elem_ids tab_elems eq_ids) to
151 # undef
152 41 ▶my $_reset = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
153 41 ▶ @{$_[0]}{qw(matrix elems elem_ids tab_elems eq_ids)} =
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 5 36 41
154 $_[1] ? ( {}, [], {}, {}, {}) : ((undef) x 5);
155 9 };
156  
157  
158 # just a function, not a method.
159 17 ▶sub _rule_pos_array_f {
Subroutine _rule_pos_array_f: called CC=2 SCAR=6.9
160 17 my ($str) = @_;
161 17 my @rule_pos;
162 17 my $idx = index($str, '|');
163 17 ▶ while($idx != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx != -1) 84 17 101
164 84 push(@rule_pos, $idx);
165 84 $idx = index($str, '|', $idx + 1);
166 }
167 17 return \@rule_pos;
168 }
169  
170 # just a function, not a method.
171 9 ▶sub _int_array_cmp {
Subroutine _int_array_cmp: called CC=4 SCAR=13.9
172 9 my ($arr1, $arr2) = @_;
173 9 ▶ return !1 if @$arr1 != @$arr2;
Branch: 1 branch
BranchTrueFalseTotal
if @$arr1 != @$arr2 2 7 9
174 7 ▶ for (my $i = 0; $i < @$arr1; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$arr1) 36 6 42
175 36 ▶ return !1 if $arr1->[$i] != $arr2->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $arr1->[$i] != $arr2->[$i] 1 35 36
176 }
177 6 return 1;
178 }
179  
180 # just a function, not a method.
181 70 ▶sub _parse_header_f {
Subroutine _parse_header_f: called CC=8 SCAR=20.8
182 70 my ($header, $pedantic) = @_;
183 70 $header =~ s/\s+$//;
184 70 my @rule_pos;
185 70 ▶ if ($pedantic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pedantic) 9 61 70
186 9 ▶ substr($header, -1, 1) eq '|' or croak("'$header': Wrong header format");
Branch: 1 branch
BranchTrueFalseTotal
substr($header, -1, 1) eq "|" or croak("'${header}': Wrong header format") 8 1 9
187 }
188 69 ▶ $header =~ s/^\s*\|.*?\|\s*// or croak("'$header': Wrong header format");
Branch: 1 branch
BranchTrueFalseTotal
$header =~ s/^\s*\|.*?\|\s*// or croak("'${header}': Wrong header format") 68 1 69
189 68 ▶ my @elem_array = $header eq "|" ? ('') : split(/\s*\|\s*/, $header);
Branch: 1 branch
BranchTrueFalseTotal
$header eq '|' ? : 3 65 68
190 68 ▶ return ([], {}) if $header eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $header eq "" 2 66 68
191 66 my $index = 0;
192 66 my %elem_ids;
193 66 foreach my $name (@elem_array) {
194 192 ▶ croak("'$name': duplicate name in header") if exists($elem_ids{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $elem_ids{$name} 2 190 192
195 190 $elem_ids{$name} = $index++;
196 }
197 64 return (\@elem_array, \%elem_ids);
198 }
199  
200  
201  
202 #
203 # _ret_hash(HASHREF [, BOOL])
204 #
205 # Returns a duplicate of HASHREF if BOOL is true. Otherwise return HASHREF.
206 #
207 76 ▶sub _ret_hash {
Subroutine _ret_hash: called CC=3 SCAR=11.0
208 76 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 6 70 76
209 70 ▶ return $_[1] ? {%{$_[0]}} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 2 68 70
210 }
211  
212  
213  
214 163 ▶my $_parse_row = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
215 163 my $self = shift;
216 163 my $row = shift;
217 163 my ($inc, $noinc) = @{$self}{qw(inc noinc)};
218 163 ▶ $row =~ s/^\|\s*([^|]*?)\s*\|\s*// or croak("Wrong row format: '$row'");
Branch: 1 branch
BranchTrueFalseTotal
$row =~ s/^\|\s*([^|]*?)\s*\|\s*// or croak("Wrong row format: '${row}'") 159 4 163
219 159 my $rowElem = $1;
220 159 my @rowContents;
221 159 ▶ if ($row ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($row ne "") 157 2 159
222 157 $row =~ s/\s*\|\s*$//;
223 157 ▶ my @entries = $row eq "" ? ("") : split(/\s*\|\s*/, $row, -1);
Branch: 1 branch
BranchTrueFalseTotal
$row eq '' ? : 1 156 157
224 157 foreach my $entry (@entries) {
225 520 ▶ if ($entry eq $inc) {
Branch: 2 branches
BranchTrueFalseTotal
if ($entry eq $inc) { } 157 363 520
elsif ($entry eq $noinc) { } 359 4 363
226 157 push(@rowContents, 1);
227 } elsif ($entry eq $noinc) {
228 359 push(@rowContents, "");
229 } else {
230 4 croak("'$entry': unexpected entry");
231 }
232 }
233 }
234 155 return ($rowElem, \@rowContents);
235 9 };
236  
237  
238 75 ▶my $_parse_table = sub {
Subroutine __ANON__: called CC=41 SCAR=37.1
239 75 my $self = shift;
240 75 my ($lines, $allow_subset, $pedantic) = @_;
241 75 my $index = 0;
242 75 ▶ for (; $index < @$lines; ++$index) { # skip heading empty lines
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$lines) 99 5 104
243 99 ▶ last if $lines->[$index] =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$index] =~ /\S/ 70 29 99
244 }
245 75 ▶ if ($index == @$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index == @$lines) 5 70 75
246 5 $self->$_reset(1);
247 5 return;
248 }
249 70 my ($h_elems, $h_ids) = _parse_header_f($lines->[$index], $pedantic);
250 66 my ($sep_line, $rule_pos);
251 66 ▶ if ($pedantic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pedantic) 8 58 66
252 8 ($sep_line = $lines->[$index]) =~ s/\s+$//;
253 8 $rule_pos = _rule_pos_array_f($sep_line);
254 8 ▶ for (my $i = 0; $i < @$rule_pos - 1; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$rule_pos - 1) 31 8 39
255 31 my ($b, $e) = @{$rule_pos}[$i, $i + 1];
256 31 ▶ substr($sep_line, $b, 1, '+') if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 23 8 31
257 31 my $d = $e - $b;
258 31 ▶ next unless $d > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $d > 1 0 31 31
259 31 --$d;
260 31 substr($sep_line, $b + 1, $d, '-' x $d);
261 }
262 }
263 66 my $elem_ids;
264 my %rows;
265 66 my @rowElems; # To keep order of additional row elements, if any.
266 66 ▶ for (++$index; $index < @$lines; ++$index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$lines) 311 48 359
267 311 (my $line = $lines->[$index]) =~ s/\s+$//;
268 311 ▶ last if $line eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 3 308 311
269 308 ▶ if ($pedantic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pedantic) 19 289 308
270 19 $line =~ /\S/;
271 19 ▶ $-[0] == $rule_pos->[0] or croak("Wrong indentation at line " . ($index + 1));
Branch: 1 branch
BranchTrueFalseTotal
$-[0] == $rule_pos->[0] or croak('Wrong indentation at line ' . ($index + 1)) 17 2 19
272 }
273 306 ▶ if ($line =~ /^\s*\|-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*\|-/) 140 166 306
274 140 ▶ if ($pedantic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pedantic) 8 132 140
275 8 ▶ $line eq $sep_line or croak("Invalid row separator at line " . ($index + 1));
Branch: 1 branch
BranchTrueFalseTotal
$line eq $sep_line or croak('Invalid row separator at line ' . ($index + 1)) 7 1 8
276 }
277 139 next;
278 }
279 166 ▶ if ($pedantic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pedantic) 9 157 166
280 9 ▶ _int_array_cmp(_rule_pos_array_f($line), $rule_pos) or
Branch: 1 branch
BranchTrueFalseTotal
_int_array_cmp(_rule_pos_array_f($line), $rule_pos) or croak('Wrong row format at line ' . ($index + 1)) 6 3 9
281 croak("Wrong row format at line " . ($index + 1));
282 }
283 163 $line =~ s/^\s*//;
284 163 my ($rowElem, $rowContent) = $self->$_parse_row($line);
285 155 ▶ croak("'$rowElem': duplicate element in first column") if exists($rows{$rowElem});
Branch: 1 branch
BranchTrueFalseTotal
if exists $rows{$rowElem} 1 154 155
286 154 $rows{$rowElem} = $rowContent;
287 154 push(@rowElems, $rowElem);
288 }
289 51 ▶ if ($self->{prespec}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'prespec'}) { } 28 23 51
290 28 my $tab_elems = $self->{tab_elems};
291 28 $elem_ids = $self->{elem_ids};
292 28 foreach my $elem (keys(%{$h_ids})) {
293 90 ▶ croak("'$elem': unknown element in table") if !exists($tab_elems->{$elem});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tab_elems->{$elem} 2 88 90
294 }
295 26 foreach my $elem (keys(%rows)) {
296 83 ▶ croak("'$elem': unknown element in table") if !exists($tab_elems->{$elem});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tab_elems->{$elem} 2 81 83
297 }
298 24 ▶ if (!$allow_subset) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_subset) 19 5 24
299 19 foreach my $elem (keys(%{$tab_elems})) {
300 66 ▶ croak("'$elem': column missing for element") if !exists($h_ids->{$elem});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h_ids->{$elem} 1 65 66
301 65 ▶ croak("'$elem': row missing for element" ) if !exists($rows{$elem});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rows{$elem} 1 64 65
302 }
303 }
304 } else {
305 23 ▶ if ($allow_subset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_subset) { } 4 19 23
306 4 foreach my $rowElem (@rowElems) {
307 6 ▶ if (!exists($h_ids->{$rowElem})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $h_ids->{$rowElem}) 4 2 6
308 4 $h_ids->{$rowElem} = @{$h_elems};
309 4 push(@{$h_elems}, $rowElem);
310 }
311 }
312 } else {
313 croak("Number of elements in header does not match number of elemens in row")
314 19 ▶ if keys(%{$h_ids}) != keys(%rows);
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$h_ids;} != keys %rows 3 16 19
315 16 foreach my $elem (keys(%{$h_ids})) {
316 43 ▶ croak("'$elem': row missing for element") if !exists($rows{$elem});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rows{$elem} 1 42 43
317 }
318 }
319 19 my %tmp = %{$h_ids};
320 19 @{$self}{qw(elems elem_ids tab_elems eq_ids)} = ($h_elems, $h_ids, \%tmp, {});
321 19 $elem_ids = $h_ids;
322 }
323 41 my $eq_ids = $self->{eq_ids};
324 41 my %matrix;
325 41 ▶ while (my ($rowElem, $rowContents) = each(%rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %rows) 121 41 162
326 121 my %new_row;
327 121 ▶ for (my $i = 0; $i < @{$rowContents}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$rowContents;}) 418 121 539
328 418 ▶ if ($rowContents->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rowContents->[$i]) 140 278 418
329 140 my $e_id = $elem_ids->{$h_elems->[$i]};
330 140 $new_row{$e_id} = undef;
331 140 ▶ if (exists($eq_ids->{$e_id})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $eq_ids->{$e_id}) 31 109 140
332 31 foreach my $eq_id (@{$eq_ids->{$e_id}}) {
333 57 $new_row{$eq_id} = undef
334 }
335 }
336 }
337 }
338 121 ▶ if (%new_row) {
Branch: 1 branch
BranchTrueFalseTotal
if (%new_row) 89 32 121
339 89 $matrix{$elem_ids->{$rowElem}} = \%new_row;
340 89 ▶ if (exists($eq_ids->{$rowElem})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $eq_ids->{$rowElem}) 0 89 89
341 0 foreach my $eq_id (@{$eq_ids->{$rowElem}}) {
342 0 $matrix{$eq_id} = {%new_row};
343 }
344 }
345 }
346 }
347 41 $self->{matrix} = \%matrix;
348 41 return;
349 9 };
350  
351  
352 # just a function, not a method.
353 38 ▶sub _get_from_str {
Subroutine _get_from_str: called CC=2 SCAR=6.9
354 38 ▶ if (${$_[0]} !~ /\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ${$_[0];} =~ /\n/) { } 5 33 38
355 5 open(my $h, '<', ${$_[0]});
356 5 my $inputArray = [<$h>];
357 5 close($h);
358 5 return $inputArray;
359 } else {
360 33 return [split(/\n/, ${$_[0]})];
361 }
362 }
363  
364 82 ▶sub get {
Subroutine get: called CC=14 SCAR=26.4
Pod documented
365 82 my $self = shift;
366 82 ▶ croak("Odd number of arguments") if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 81 82
367 81 my %args = @_;
368 81 my $allow_subset = delete $args{allow_subset};
369 81 my $pedantic = delete $args{pedantic};
370 81 ▶ croak("Missing argument 'src'") if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 80 81
371 80 ▶ my $src = delete $args{src} // croak("Invalid value argument for 'src'");
Condition100%2/2
delete $args{"src"} // croak("Invalid value argument for 'src'")
l!l
791
MC/DC100%1/1
delete $args{"src"} // croak("Invalid value argument for 'src'")
delete $args{"src"}
Truth table100%2/2
A
A= delete $args{"src"}
Aresult
11
00
372 79 ▶ croak(join(", ", sort(keys(%args))) . ": unexpected argument") if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 2 77 79
373 77 my $inputArray;
374 77 ▶ if (my $ref_str = ref($src)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref_str = ref $src) { } 41 36 77
375 41 ▶ if ($ref_str eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref_str eq 'ARRAY') { } 38 3 41
elsif ($ref_str eq 'GLOB') { } 0 3 3
elsif ($ref_str eq 'SCALAR') { } 2 1 3
376 38 foreach my $e (@{$src}) {
377 170 ▶ croak("src: each entry must be a defined scalar") if (ref($e) || !defined($e));
Branch: 1 branch
BranchTrueFalseTotal
if ref $e or not defined $e 1 169 170
Condition66%2/3
ref $e or not defined $e
l!l&&r!l&&!r
10169
MC/DC50%1/2
ref $e or not defined $e
ref $e not defined $e
Truth table66%2/3
A or not(B)
A= ref $eB= not defined $e
ABresult
1X1
011
000
378 }
379 37 $inputArray = $src;
380 } elsif ($ref_str eq 'GLOB') {
381 0 $inputArray = [<$src>];
382 } elsif ($ref_str eq 'SCALAR') {
383 2 $inputArray = _get_from_str($src);
384 }
385 else {
386 1 croak("Invalid value argument for 'src'");
387 }
388 } else {
389 36 $inputArray = _get_from_str(\$src);
390 }
391 75 ▶ $self->$_reset() if !$self->{prespec};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"prespec"} 36 39 75
392 75 $self->$_parse_table($inputArray, $allow_subset, $pedantic);
393 46 ▶ return wantarray ? @{$self}{qw(matrix elems elem_ids)} : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 22 24 46
394 }
395  
396  
397 3 ▶sub inc {croak("Unexpected argument(s)") if @_ > 1; $_[0]->{inc};}
Subroutine inc: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 2 3
398 3 ▶sub noinc {croak("Unexpected argument(s)") if @_ > 1; $_[0]->{noinc};}
Subroutine noinc: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 2 3
399 12 ▶sub prespec {croak("Unexpected argument(s)") if @_ > 1; $_[0]->{prespec};}
Subroutine prespec: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 11 12
400  
401  
402 36 ▶sub elems {
Subroutine elems: called CC=4 SCAR=13.9
Pod documented
403 36 ▶ croak("Unexpected argument(s)") if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 1 35 36
404  
405 35 ▶ if ($_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]) { } 2 33 35
406 2 ▶ return defined($_[0]->{elems}) ? [@{$_[0]->{elems}}] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'elems'} ? : 1 1 2
407 } else {
408 33 return $_[0]->{elems};
409 }
410 }
411  
412  
413 44 ▶sub elem_ids {
Subroutine elem_ids: called CC=2 SCAR=6.9
Pod documented
414 44 ▶ croak("Unexpected argument(s)") if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 1 43 44
415 43 _ret_hash($_[0]->{elem_ids}, $_[1]);
416 }
417  
418  
419 33 ▶sub tab_elems {
Subroutine tab_elems: called CC=2 SCAR=7.2
Pod documented
420 33 ▶ croak("Unexpected argument(s)") if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 33 33
421 33 _ret_hash($_[0]->{tab_elems}, $_[1]);
422 }
423  
424  
425 #hash of array refs
426 24 ▶sub eq_ids {
Subroutine eq_ids: called CC=4 SCAR=13.9
Pod documented
427 24 ▶ croak("Unexpected argument(s)") if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 24 24
428  
429 24 my ($self, $dup) = @_;
430 24 ▶ if ($dup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dup) { } 2 22 24
431 2 ▶ return undef if !$self->{eq_ids};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"eq_ids"} 1 1 2
432 1 return {map {$_ => [@{$self->{eq_ids}{$_}}]} keys(%{$self->{eq_ids}})};
433 } else {
434 22 return $self->{eq_ids};
435 }
436 }
437  
438  
439 30 ▶sub matrix {
Subroutine matrix: called CC=7 SCAR=19.5
Pod documented
440 30 my $self = shift;
441 30 ▶ croak("Odd number of arguments") if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 29 30
442 29 my %args = @_;
443 29 my $bless = delete $args{bless};
444 29 my $dup = delete $args{dup};
445 29 ▶ croak("Unexpected argument(s)") if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 1 28 29
446 28 ▶ return if !$self->{matrix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"matrix"} 3 25 28
447 25 my $matrix;
448 25 ▶ if ($dup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dup) { } 1 24 25
449 1 ▶ while (my ($key, $value) = each(%{$self->{matrix}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"matrix"};}) 4 1 5
450 4 $matrix->{$key} = {%$value}
451 }
452 } else {
453 24 $matrix = $self->{matrix};
454 }
455 25 ▶ bless($matrix, "Text::Table::Read::RelationOn::Tiny::_Relation_Matrix") if $bless;
Branch: 1 branch
BranchTrueFalseTotal
if $bless 1 24 25
456 25 return $matrix;
457 }
458  
459  
460 11 ▶sub matrix_named {
Subroutine matrix_named: called CC=6 SCAR=17.9
Pod documented
461 11 my $self = shift;
462 11 ▶ croak("Odd number of arguments") if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 10 11
463 10 my %args = @_;
464 10 my $bless = delete $args{bless};
465 10 ▶ croak("Unexpected argument(s)") if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 1 9 10
466  
467 9 my ($matrix, $elems) = @{$self}{qw(matrix elems)};
468 9 ▶ return if !$matrix;
Branch: 1 branch
BranchTrueFalseTotal
unless $matrix 2 7 9
469 7 my $matrix_named = {};
470 7 ▶ bless($matrix_named, "Text::Table::Read::RelationOn::Tiny::_Relation_Matrix") if $bless;
Branch: 1 branch
BranchTrueFalseTotal
if $bless 2 5 7
471 7 ▶ while (my ($rowElemIdx, $rowContents) = each(%{$matrix})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$matrix;}) 18 7 25
472 18 $matrix_named->{$elems->[$rowElemIdx]} = {map {$elems->[$_] => undef} keys(%{$rowContents})};
473 }
474 7 return $matrix_named;
475 }
476  
477  
478  
479 {
480 package # hide from pause
481 Text::Table::Read::RelationOn::Tiny::_Relation_Matrix;
482  
483 4 ▶ sub related { return exists($_[0]->{$_[1]}) && exists($_[0]->{$_[1]}->{$_[2]}); }
Subroutine related: called CC=2 SCAR=7.2
Condition66%2/3
exists $_[0]{$_[1]} && exists $_[0]{$_[1]}{$_[2]}
!ll&&!rl&&r
022
MC/DC50%1/2
exists $_[0]{$_[1]} && exists $_[0]{$_[1]}{$_[2]}
exists $_[0]{$_[1]} exists $_[0]{$_[1]}{$_[2]}
Truth table66%2/3
A && B
A= exists $_[0]{$_[1]}B= exists $_[0]{$_[1]}{$_[2]}
ABresult
0X0
100
111
484 }
485  
486  
487 9 1; # End of Text::Table::Read::RelationOn::Tiny
488  
489  
490  
491 __END__
↑ Summary