| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 68 | ▶ | croak("Odd number of arguments") if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 67 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 67 | ▶ | my $inc = delete $args{inc} // "X"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{"inc"} // "X"
MC/DC100%1/1
delete $args{"inc"} // "X"
delete $args{"inc"}
Truth table100%2/2
A
A= delete $args{"inc"}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 67 | ▶ | my $noinc = delete $args{noinc} // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{"noinc"} // ""
MC/DC100%1/1
delete $args{"noinc"} // ""
delete $args{"noinc"}
Truth table100%2/2
A
A= delete $args{"noinc"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 66 | ▶ | croak("inc: must be a scalar") if ref($inc); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 65 | ▶ | croak("noinc: must be a scalar") if ref($noinc); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 63 | ▶ | croak("'|' is not allowed for inc or noinc") if $inc eq '|' || $noinc eq '|'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inc eq "|" or $noinc eq "|"
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 "|"
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 61 | my $self = {inc => $inc, | |||||||||||||||||||||||||||||||||||||||||
| 34 | noinc => $noinc, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 61 | ▶ | if (defined($set)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 48 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 48 | ▶ | croak("set: must be an array reference") if ref($set) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 47 | my $cnt = 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 47 | foreach my $e (@$set) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 152 | ▶ | if (ref($e)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | ▶ | croak("set: entry $cnt: invalid") if ref($e) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | ▶ | croak("set: entry $cnt: array not allowed if eqs is specified") if $eqs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 19 | ▶ | croak("set: entry $cnt: array entry must not be empty") if !@{$e}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 17 | foreach my $sub_e (@$e) { | |||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | ▶ | croak("set: entry $cnt: subarray contains invalid entry") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $sub_e or not defined $sub_e
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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if ref($sub_e) || !defined($sub_e); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 32 | ▶ | croak("set: '$sub_e': duplicate element") if exists($seen{$sub_e}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 28 | $seen{$sub_e} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 131 | ▶ | croak("set: entry $cnt: invalid") if !defined($e); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 130 | ▶ | croak("set: '$e': duplicate element") if exists($seen{$e}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | $self->{prespec} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 46 | ▶ | if (defined($elem_ids)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | ▶ | croak("elem_ids: not allowed without arguments 'set' and 'ext'") if !(defined($ext) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ext and defined $set
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
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | defined($set)); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | ▶ | croak("elem_ids: must be a hash ref") if ref($elem_ids) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | ▶ | if ($set) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | foreach my $e (@$set) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 42 | ▶ | croak("set: no subarray allowed if 'ext' is specified") if ref($e); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | if ($elem_ids) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | ▶ | croak("elem_ids: wrong number of entries") if keys(%$elem_ids) != @$set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 22 | ▶ | croak("elem_ids: '$e': entry has wrong value") if ($e_id !~ /^\d$/ || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $e_id =~ /^\d$/ && defined $set->[$e_id] or $set->[$e_id] ne $e
$e_id =~ /^\d$/ && defined $set->[$e_id]
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | push(@elems, $entry->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | $ids{$entry->[0]} = $#elems; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | for (my $j = 1; $j < @$entry; ++$j) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $eqs and @eqs_tmp
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
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 21 | ▶ | $eqs = \@eqs_tmp if @eqs_tmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 21 | ($elems, $elem_ids, $tabElems, $eqIds) = (\@elems, \%ids, {%ids}, {}); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 34 | ▶ | if (defined($eqs)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 14 | ▶ | croak("eqs: must be an array ref") if ref($eqs) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 27 | ▶ | next if !@{$eqArray}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 25 | foreach my $entry (@{$eqArray}) { | |||||||||||||||||||||||||||||||||||||||||
| 126 | 57 | ▶ | croak("eqs: subentry contains a non-scalar") if ref($entry); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 56 | ▶ | croak("eqs: subentry undefined") if !defined($entry); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 55 | ▶ | croak("eqs: '$entry': unknown element") if !exists($elem_ids->{$entry}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 53 | ▶ | croak("eqs: '$entry': duplicate element") if exists($seen{$entry}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 51 | $seen{$entry} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | ▶ | next if @{$eqArray} == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | ▶ | for (my $i = 0; $i < @$arr1; ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 36 | ▶ | return !1 if $arr1->[$i] != $arr2->[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | ▶ | substr($header, -1, 1) eq '|' or croak("'$header': Wrong header format"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 69 | ▶ | $header =~ s/^\s*\|.*?\|\s*// or croak("'$header': Wrong header format"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 68 | ▶ | my @elem_array = $header eq "|" ? ('') : split(/\s*\|\s*/, $header); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 68 | ▶ | return ([], {}) if $header eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 70 | ▶ | return $_[1] ? {%{$_[0]}} : $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 159 | my $rowElem = $1; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 159 | my @rowContents; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 159 | ▶ | if ($row ne "") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 157 | $row =~ s/\s*\|\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 157 | ▶ | my @entries = $row eq "" ? ("") : split(/\s*\|\s*/, $row, -1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 157 | foreach my $entry (@entries) { | |||||||||||||||||||||||||||||||||||||||||
| 225 | 520 | ▶ | if ($entry eq $inc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 99 | ▶ | last if $lines->[$index] =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 75 | ▶ | if ($index == @$lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 31 | my ($b, $e) = @{$rule_pos}[$i, $i + 1]; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 31 | ▶ | substr($sep_line, $b, 1, '+') if $i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 31 | my $d = $e - $b; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 31 | ▶ | next unless $d > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 311 | (my $line = $lines->[$index]) =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 311 | ▶ | last if $line eq q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 308 | ▶ | if ($pedantic) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 19 | $line =~ /\S/; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 19 | ▶ | $-[0] == $rule_pos->[0] or croak("Wrong indentation at line " . ($index + 1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 306 | ▶ | if ($line =~ /^\s*\|-/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 140 | ▶ | if ($pedantic) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 8 | ▶ | $line eq $sep_line or croak("Invalid row separator at line " . ($index + 1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 139 | next; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 166 | ▶ | if ($pedantic) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 9 | ▶ | _int_array_cmp(_rule_pos_array_f($line), $rule_pos) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 154 | $rows{$rowElem} = $rowContent; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 154 | push(@rowElems, $rowElem); | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 51 | ▶ | if ($self->{prespec}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 26 | foreach my $elem (keys(%rows)) { | |||||||||||||||||||||||||||||||||||||||||
| 296 | 83 | ▶ | croak("'$elem': unknown element in table") if !exists($tab_elems->{$elem}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 24 | ▶ | if (!$allow_subset) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 19 | foreach my $elem (keys(%{$tab_elems})) { | |||||||||||||||||||||||||||||||||||||||||
| 300 | 66 | ▶ | croak("'$elem': column missing for element") if !exists($h_ids->{$elem}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 65 | ▶ | croak("'$elem': row missing for element" ) if !exists($rows{$elem}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 23 | ▶ | if ($allow_subset) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | foreach my $rowElem (@rowElems) { | |||||||||||||||||||||||||||||||||||||||||
| 307 | 6 | ▶ | if (!exists($h_ids->{$rowElem})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 16 | foreach my $elem (keys(%{$h_ids})) { | |||||||||||||||||||||||||||||||||||||||||
| 316 | 43 | ▶ | croak("'$elem': row missing for element") if !exists($rows{$elem}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 121 | my %new_row; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 121 | ▶ | for (my $i = 0; $i < @{$rowContents}; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 418 | ▶ | if ($rowContents->[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 89 | $matrix{$elem_ids->{$rowElem}} = \%new_row; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 89 | ▶ | if (exists($eq_ids->{$rowElem})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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'")
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 79 | ▶ | croak(join(", ", sort(keys(%args))) . ": unexpected argument") if %args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 77 | my $inputArray; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 77 | ▶ | if (my $ref_str = ref($src)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 41 | ▶ | if ($ref_str eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $e or not defined $e
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 75 | $self->$_parse_table($inputArray, $allow_subset, $pedantic); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 46 | ▶ | return wantarray ? @{$self}{qw(matrix elems elem_ids)} : $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 35 | ▶ | if ($_[1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | return defined($_[0]->{elems}) ? [@{$_[0]->{elems}}] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 24 | my ($self, $dup) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 24 | ▶ | if ($dup) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | ▶ | return undef if !$self->{eq_ids}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 28 | ▶ | return if !$self->{matrix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 25 | my $matrix; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 25 | ▶ | if ($dup) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | ▶ | while (my ($key, $value) = each(%{$self->{matrix}})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 10 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 10 | my $bless = delete $args{bless}; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 10 | ▶ | croak("Unexpected argument(s)") if %args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 9 | my ($matrix, $elems) = @{$self}{qw(matrix elems)}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 9 | ▶ | return if !$matrix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 7 | my $matrix_named = {}; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 7 | ▶ | bless($matrix_named, "Text::Table::Read::RelationOn::Tiny::_Relation_Matrix") if $bless; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 7 | ▶ | while (my ($rowElemIdx, $rowContents) = each(%{$matrix})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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]}
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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 9 | 1; # End of Text::Table::Read::RelationOn::Tiny | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | __END__ | ||||||||||||||||||||||||||||||||||||||||||