| 1 | package PICA::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use overload '""' => \&stringify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 131 | ▶ | my ($class, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 131 | ▶ | confess "invalid pica path" if $path !~ / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ([012.][0-9.][0-9.][A-Z@.]) # tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | (\[([0-9.]{2,3})\])? # occurence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | (\$?([_A-Za-z0-9]+))? # subfields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | (\/(\d+)?(-(\d+)?)?)? # position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | /x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 122 | my $field = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 122 | my $occurrence = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 122 | ▶ | my $subfield = defined $5 ? "[$5]" : "[_A-Za-z0-9]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 122 | my @position; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 122 | ▶ | if (defined $6) { # from, to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 26 | my ($from, $dash, $to, $length) = ($7, $8, $9, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 26 | ▶ | if ($dash) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 14 | ▶ | confess "invalid pica path" unless defined($from // $to); # /- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$from // $to
MC/DC100%2/2
$from // $to
$from
$to
Truth table100%3/3
A // B
A= $fromB= $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | if (defined $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | if (!$from and $dash) { # /-X | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $from and $dash
MC/DC50%1/2
not $from and $dash
not $from
$dash
Truth table66%2/3
not(A) and B
A= not $fromB= $dash
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | $from = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | $length = $to - $from + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 18 | ▶ | if ($8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | $length = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | $length = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | ▶ | if (!defined $length or $length >= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $length or $length >= 1
MC/DC0%0/2
not defined $length or $length >= 1
not defined $length
$length >= 1
Truth table66%2/3
not(A) or B
A= not defined $lengthB= $length >= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | ▶ | unless (!$from and !defined $length) { # /0- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$from or defined $length
MC/DC100%2/2
$from or defined $length
$from
defined $length
Truth table100%3/3
A or B
A= $fromB= defined $length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 22 | @position = ($from, $length); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 121 | $field = qr{$field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 121 | ▶ | if (defined $occurrence) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $occurrence = qr{$occurrence}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 121 | $subfield = qr{$subfield}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 121 | bless [$field, $occurrence, $subfield, @position], $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | sub match_record { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 54 | ▶ | my ($self, $record, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_record: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # my $subfield_regex = $self->[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 54 | my %default_args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | force_array => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | join => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | nested_arrays => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | pluck => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | split => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | value => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 54 | %args = (%default_args, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 54 | ▶ | if ($args{nested_arrays}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 11 | $args{split} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # check if path exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 54 | ▶ | if ($args{value}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my $value = $self->record_subfields($record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | return $value ? $args{value} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # gather values from matched subfields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 51 | my @matches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 51 | for my $field (@{$self->record_fields($record)}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 122 | ▶ | next unless defined $field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my @matched_subfields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | = $args{pluck} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 122 | ▶ | ? $self->match_subfields($field, pluck => 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | : $self->match_subfields($field); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 122 | ▶ | next unless defined $matched_subfields[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 104 | ▶ | if ($args{split}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 65 | ▶ | if ($args{nested_arrays}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | push @matches, \@matched_subfields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 32 | push @matches, @matched_subfields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 39 | push @matches, join($args{join}, @matched_subfields); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 51 | ▶ | if (@matches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # return matched fields as array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 49 | ▶ | if ($args{split}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | ▶ | return $args{force_array} ? [\@matches] : \@matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # ... or string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | return $args{force_array} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ? \@matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 23 | ▶ | : join($args{join}, @matches); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub match_field { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 789 | ▶ | my ($self, $field) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_field: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 789 | ▶ | if ($field->[0] =~ $self->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$field->[0] =~ /$self->[0]/u and !$self->[1] || defined $field->[1] && $field->[1] =~ /$self->[1]/u
not $self->[1] or defined $field->[1] and $field->[1] =~ /$self->[1]/u
defined $field->[1] and $field->[1] =~ /$self->[1]/u
MC/DC50%2/4
$field->[0] =~ /$self->[0]/u and !$self->[1] || defined $field->[1] && $field->[1] =~ /$self->[1]/u
$field->[0] =~ /$self->[0]/u
not $self->[1]
defined $field->[1]
$field->[1] =~ /$self->[1]/u
Truth table60%3/5
A and not(B) or C and D
A= $field->[0] =~ /$self->[0]/uB= not $self->[1]C= defined $field->[1]D= $field->[1] =~ /$self->[1]/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | && (!$self->[1] || (defined $field->[1] && $field->[1] =~ $self->[1])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 155 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 634 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub match_subfields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 917 | ▶ | my ($self, $field, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_subfields: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 917 | my $subfield_regex = $self->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 917 | my $from = $self->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 917 | my $length = $self->[4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 917 | my @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 917 | ▶ | if ($args{pluck}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Treat the subfields as a hash index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | my $subfield_href = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | for (my $i = 2; $i < @{$field}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | push @{$subfield_href->{$field->[$i]}}, $field->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my $subfields = $self->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | $subfields =~ s{.*\[(.+)\].*}{\1}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | for my $subfield (split('', $subfields)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | my $value = $subfield_href->{$subfield} // [undef]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$subfield_href->{$subfield} // [undef]
MC/DC0%0/1
$subfield_href->{$subfield} // [undef]
$subfield_href->{$subfield}
Truth table50%1/2
A
A= $subfield_href->{$subfield}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | ▶ | if (defined $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | push @values, map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | $length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ? substr($_, $from, $length) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | : substr($_, $from) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | } @{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | push @values, @{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 913 | ▶ | for (my $i = 2; $i < @$field; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1161 | ▶ | if ($field->[$i] =~ $subfield_regex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 958 | my $value = $field->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 958 | ▶ | if (defined $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | ▶ | $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | = $length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ? substr($value, $from, $length) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | : substr($value, $from); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 9 | ▶ | next if '' eq ($value // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 957 | push @values, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 917 | return @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | sub record_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 51 | ▶ | my ($self, $record) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
record_fields: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 51 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 51 | return [grep {$self->match_field($_)} @$record]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub record_subfields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 12 | ▶ | my ($self, $record) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
record_subfields: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | my @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | foreach my $field (grep {$self->match_field($_)} @$record) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 16 | push @values, $self->match_subfields($field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 12 | return @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | sub unescape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 33 | ▶ | my $exp = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unescape: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 33 | ▶ | $exp =~ s/^\(\?[^:]*:(.*)\)$/$1/ if defined $exp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 33 | return $exp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 9 | ▶ | my ($self, $short) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | my $str = $self->fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | my $occurrence = $self->occurrences; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | ▶ | $str .= "[$occurrence]" if defined $occurrence; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 9 | my $subfields = $self->subfields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 9 | ▶ | if (defined $subfields) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | ▶ | unless ($short and $subfields !~ /^\$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$short and not $subfields =~ /^\$/u
MC/DC50%1/2
$short and not $subfields =~ /^\$/u
$short
not $subfields =~ /^\$/u
Truth table66%2/3
A and not(B)
A= $shortB= not $subfields =~ /^\$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | $str .= '$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | $str .= $subfields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | my $pos = $self->positions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 9 | ▶ | $str .= "/$pos" if defined $pos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 9 | $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | sub fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 11 | ▶ | return unescape($_[0]->[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | sub occurrences { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 11 | ▶ | return unescape($_[0]->[1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occurrences: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | sub subfields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 11 | ▶ | my $subfields = unescape($_[0]->[2]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subfields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 11 | ▶ | if (defined $subfields and $subfields ne '[_A-Za-z0-9]') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $subfields and $subfields ne "[_A-Za-z0-9]"
MC/DC50%1/2
defined $subfields and $subfields ne "[_A-Za-z0-9]"
defined $subfields
$subfields ne "[_A-Za-z0-9]"
Truth table66%2/3
A and B
A= defined $subfieldsB= $subfields ne "[_A-Za-z0-9]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | $subfields =~ s/\[|\]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | return $subfields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | sub positions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 11 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
positions: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 11 | my ($from, $length, $pos) = ($self->[3], $self->[4]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 11 | ▶ | if (defined $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | ▶ | if ($from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | $pos = $from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | ▶ | if (!defined $length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | if ($from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | $pos = "$from-"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | elsif ($length > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | $pos .= '-' . ($from + $length - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | ▶ | elsif ($length == 1 && !$from) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$length == 1 and not $from
MC/DC50%1/2
$length == 1 and not $from
$length == 1
not $from
Truth table66%2/3
A and not(B)
A= $length == 1B= not $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 11 | return $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||