| 1 | package PICA::Schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 16 | our $VERSION = '2.12'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use List::Util qw(pairs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | our @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | = qw(field_identifier check_value clean_pica parse_subfield_schedule); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | require PICA::Data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 16 | require PICA::Error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | my ($class, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | cleanup_field_schedule($schema->{fields}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | bless $schema, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 25 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 25 | my ($self, $record, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 25 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 25 | ▶ | = clean_pica($record, error => sub {push @errors, shift}, %options) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | or return @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 24 | my @errors = map {$self->check_record($_->{record}, %options)} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | PICA::Data::pica_split($record); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 24 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 24 | return grep {not $seen{"$_"}++} @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 436 | ▶ | sub check_record { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_record: called CC=12 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 436 | my ($self, $record, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 436 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 436 | $options{counter} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 436 | my %field_identifiers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 436 | for my $field (@$record) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3065 | my $id = $self->field_identifier($field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3065 | $field_identifiers{$id} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3065 | my $error = $self->check_field($field, %options, _field_id => $id); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3065 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3047 | ▶ | push @errors, $error unless grep {$_ eq $error} @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3065 | ▶ | if ($options{annotate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $annotation = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $annotation = $error->{message} =~ /^unknown/ ? '?' : '!'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | PICA::Data::pica_annotation($field, $annotation); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # check whether required fields exist for this record level | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 436 | my $level = substr $record->[0][0], 0, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 436 | for my $id (keys %{$self->{fields}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 442 | ▶ | next if $level ne substr $id, 0, 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 379 | my $field = $self->{fields}{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 379 | ▶ | if ($field->{required} && !$field_identifiers{$id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$field->{"required"} and not $field_identifiers{$id}
MC/DC100%2/2
$field->{"required"} and not $field_identifiers{$id}
$field->{"required"}
not $field_identifiers{$id}
Truth table100%3/3
A and not(B)
A= $field->{"required"}B= not $field_identifiers{$id}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | push @errors, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | PICA::Error->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | [substr($id, 0, 4), length $id > 4 ? substr($id, 5) : undef], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | required => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 436 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3065 | ▶ | sub check_field { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_field: called CC=13 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3065 | my ($self, $field, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3065 | ▶ | my $id = $opts{_field_id} || $self->field_identifier($field); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'_field_id'} || $self->field_identifier($field)
MC/DC0%0/2
$opts{'_field_id'} || $self->field_identifier($field)
$opts{'_field_id'}
$self->field_identifier($field)
Truth table33%1/3
A || B
A= $opts{'_field_id'}B= $self->field_identifier($field)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3065 | my $spec = $self->{fields}{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3065 | ▶ | if ($opts{allow_deprecated}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $opts{allow_deprecated_fields} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $opts{allow_deprecated_subfields} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3065 | ▶ | if ($opts{ignore_unknown}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $opts{ignore_unknown_fields} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $opts{ignore_unknown_subfields} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3065 | ▶ | if (!$spec) { # field is not defined | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2687 | $spec = $self->{'deprecated-fields'}{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2687 | my $simple = [split('/', $id)]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2687 | ▶ | if ($spec) { # field is deprectaed | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | unless ($opts{allow_deprecated_fields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return PICA::Error->new($simple, deprecated => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | elsif ($opts{ignore_unknown_fields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2685 | return PICA::Error->new($simple); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 378 | ▶ | if ($opts{counter} && !$spec->{repeatable}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opts{"counter"} and not $spec->{"repeatable"}
MC/DC50%1/2
$opts{"counter"} and not $spec->{"repeatable"}
$opts{"counter"}
not $spec->{"repeatable"}
Truth table66%2/3
A and not(B)
A= $opts{"counter"}B= not $spec->{"repeatable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 376 | ▶ | if ($opts{counter}{$id}++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | return PICA::Error->new($field, repeated => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 376 | my $failed = check_annotation($field, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 376 | ▶ | return PICA::Error->new($failed) if $failed; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 376 | ▶ | if ($opts{ignore_subfields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 376 | return check_subfields($field, $spec, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 376 | ▶ | sub check_subfields { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_subfields: called CC=20 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 376 | my ($field, $spec, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 376 | my %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 376 | ▶ | if ($spec->{subfields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 366 | my $order; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | my %sfcounter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 366 | my (undef, undef, @subfields) = @$field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 366 | ▶ | pop @subfields if @subfields % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 366 | ▶ | while (@subfields) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 723 | my ($code, $value) = splice @subfields, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 723 | my $sfspec = $spec->{subfields}{$code}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 723 | ▶ | if (!$sfspec) { # subfield is not defined | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 708 | $sfspec = $spec->{'deprecated-subfields'}{$code}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 708 | ▶ | if ($sfspec) { # subfield is deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | unless ($opts{allow_deprecated_subfields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $errors{$code} = {deprecated => 1}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | elsif (!$opts{ignore_unknown_subfields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 707 | $errors{$code} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 723 | ▶ | if ($sfspec) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 15 | ▶ | if (!$sfspec->{repeatable} && $sfcounter{$code}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not $sfspec->{"repeatable"} and $sfcounter{$code}
MC/DC50%1/2
not $sfspec->{"repeatable"} and $sfcounter{$code}
not $sfspec->{"repeatable"}
$sfcounter{$code}
Truth table66%2/3
not(A) and B
A= not $sfspec->{"repeatable"}B= $sfcounter{$code}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $errors{$code} = {repeated => 1}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ▶ | elsif (!$opts{ignore_subfield_order} | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $opts{"ignore_subfield_order"} and defined $sfspec->{"order"}
MC/DC100%2/2
not $opts{"ignore_subfield_order"} and defined $sfspec->{"order"}
not $opts{"ignore_subfield_order"}
defined $sfspec->{"order"}
Truth table100%3/3
not(A) and B
A= not $opts{"ignore_subfield_order"}B= defined $sfspec->{"order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | && defined $sfspec->{order}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 8 | ▶ | if (defined $order && $order > $sfspec->{order}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $order and $order > $sfspec->{"order"}
MC/DC100%2/2
defined $order and $order > $sfspec->{"order"}
defined $order
$order > $sfspec->{"order"}
Truth table100%3/3
A and B
A= defined $orderB= $order > $sfspec->{"order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | $errors{$code} = {order => $sfspec->{order}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | $order = 1 * $sfspec->{order}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 15 | $sfcounter{$code}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 15 | $errors{$code} = $_ for check_value($value, $sfspec, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 366 | foreach my $code (keys %{$spec->{subfields}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 378 | ▶ | if (!$sfcounter{$code} && $spec->{subfields}{$code}{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $sfcounter{$code} and $spec->{"subfields"}{$code}{"required"}
MC/DC100%2/2
not $sfcounter{$code} and $spec->{"subfields"}{$code}{"required"}
not $sfcounter{$code}
$spec->{"subfields"}{$code}{"required"}
Truth table100%3/3
not(A) and B
A= not $sfcounter{$code}B= $spec->{"subfields"}{$code}{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 354 | $errors{$code} = {required => 1}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 376 | ▶ | return %errors ? PICA::Error->new($field, subfields => \%errors) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 3509 | ▶ | sub check_annotation { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_annotation: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3509 | my ($field, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3509 | my (undef, undef, @subfields) = @$field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3509 | ▶ | if (@subfields % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | return "Field annotation not allowed" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | if defined $options{check_annotation} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 14 | ▶ | && !$options{check_annotation}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $options{"check_annotation"} and not $options{"check_annotation"}
MC/DC50%1/2
defined $options{"check_annotation"} and not $options{"check_annotation"}
defined $options{"check_annotation"}
not $options{"check_annotation"}
Truth table66%2/3
A and not(B)
A= defined $options{"check_annotation"}B= not $options{"check_annotation"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 13 | ▶ | return "Annotation must not be non-alphanumeric character" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | if pop(@subfields) !~ /^[^A-Za-z0-9]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | elsif ($options{check_annotation}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | return "Missing field annotation"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 23 | ▶ | sub check_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_pattern: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 23 | my ($value, $pattern) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # TODO: check compatible with ECMA 262 (2015) regular expression grammar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 23 | ▶ | if ($pattern and $value !~ /$pattern/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pattern and not $value =~ /$pattern/u
MC/DC50%1/2
$pattern and not $value =~ /$pattern/u
$pattern
not $value =~ /$pattern/u
Truth table66%2/3
A and not(B)
A= $patternB= not $value =~ /$pattern/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | return {value => $value, pattern => $pattern}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 14 | ▶ | sub check_positions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_positions: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 14 | my ($value, $positions, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 14 | ▶ | return unless $positions; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | for my $pos (keys %$positions) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 9 | my $def = $positions->{$pos}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 9 | my @p = split '-', $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | ▶ | if (length $value < int $p[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | return {value => $value, position => $pos,}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | my $val = substr $value, $p[0] - 1, (@p > 1 ? $p[1] - $p[0] : 0) + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | ▶ | if (my $error = check_pattern($val, $def->{pattern})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return {%$error, position => $pos}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | ▶ | if (check_code($val, $def, %opts)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | return {value => $val, position => $pos}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | sub check_code { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_code: called CC=6 SCAR=21.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | my ($code, $def, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # code list only given as URI | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | return unless ref $def->{codes}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # code is defined | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | ▶ | return if exists $def->{codes}{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # code is deprecated and we allow deprecated codes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | if ($opts{allow_deprecated} || $opts{allow_deprecated_codes}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"allow_deprecated"} or $opts{"allow_deprecated_codes"}
MC/DC0%0/2
$opts{"allow_deprecated"} or $opts{"allow_deprecated_codes"}
$opts{"allow_deprecated"}
$opts{"allow_deprecated_codes"}
Truth table33%1/3
A or B
A= $opts{"allow_deprecated"}B= $opts{"allow_deprecated_codes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $deprecated = $def->{'deprecated-codes'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | return ref $deprecated && !(exists $deprecated->{$code}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $deprecated && !exists $deprecated->{$code}
MC/DC0%0/2
ref $deprecated && !exists $deprecated->{$code}
ref $deprecated
!exists $deprecated->{$code}
Truth table0%0/3
A && not(B)
A= ref $deprecatedB= !exists $deprecated->{$code}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 15 | ▶ | sub check_value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 15 | my ($value, $schedule, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 15 | ▶ | if (my $error = check_pattern($value, $schedule->{pattern})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | return $error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 14 | ▶ | if (my $error = check_positions($value, $schedule->{positions}, %opts)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | return $error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 16 | ▶ | sub cleanup_field_schedule { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanup_field_schedule: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 16 | my ($fields) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # allow ..../00 as field identifier | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 16 | for (grep {$_ =~ qr{/00$}} keys %$fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | my $tag = substr $_, 0, 4; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | if ($fields->{$tag}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | warn "duplicated field $_ is removed from schedule\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | delete $fields->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | $fields->{$tag} = delete $fields->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # TODO: detect overlap of ranges (not required by Avram specification) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 3107 | ▶ | sub field_identifier { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_identifier: called CC=21 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3107 | ▶ | $_[0]->{_ranges} = 1 if reftype $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 3107 | ▶ | my $fields = reftype $_[0] eq 'HASH' ? shift->{fields} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 3107 | my ($tag, $occ, @sf) = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3107 | my $level = substr $tag, 0, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3107 | ▶ | $occ = ($level ne '2' && $occ > 0) ? sprintf("%02d", $occ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$level ne 2 and $occ > 0
MC/DC100%2/2
$level ne 2 and $occ > 0
$level ne 2
$occ > 0
Truth table100%3/3
A and B
A= $level ne 2B= $occ > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 3107 | ▶ | if ($fields) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3079 | ▶ | return "$tag/$occ" if exists $fields->{"$tag/$occ"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Find matching occurrence range | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # (TODO: create an index to speed up this slow lookup?) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | return $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3078 | ▶ | for grep {$_ =~ /^$tag\/(..)-(..)$/ && $occ >= $1 && $occ <= $2} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$_ =~ m[^$tag/(..)-(..)$]u && $occ >= $1 && $occ <= $2
$_ =~ m[^$tag/(..)-(..)$]u and $occ >= $1
MC/DC66%2/3
$_ =~ m[^$tag/(..)-(..)$]u && $occ >= $1 && $occ <= $2
$_ =~ m[^$tag/(..)-(..)$]u
$occ >= $1
$occ <= $2
Truth table75%3/4
A and B && C
A= $_ =~ m[^$tag/(..)-(..)$]uB= $occ >= $1C= $occ <= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | sort keys %$fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 3074 | ▶ | if ($level eq '2') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # get value of first subfield $x | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2855 | my $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2855 | for my $i (0 .. $#sf) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 12664 | ▶ | if ($i % 2 && $sf[$i - 1] eq 'x') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i % 2 and $sf[$i - 1] eq "x"
MC/DC100%2/2
$i % 2 and $sf[$i - 1] eq "x"
$i % 2
$sf[$i - 1] eq "x"
Truth table100%3/3
A and B
A= $i % 2B= $sf[$i - 1] eq "x"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 790 | $x = $sf[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 790 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # find field definition with matching field counter | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2855 | ▶ | if ($x =~ /^[0-9][0-9]?$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 790 | ▶ | return "${tag}x$x" if exists $fields->{"${tag}x$x"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 789 | return $_ for grep { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 795 | ▶ | $_ =~ /^${tag}x(..?)-(..?)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$_ =~ /^${tag}x(..?)-(..?)$/u && $x >= $1 && $x <= $2 && length $1 == length $x
$_ =~ /^${tag}x(..?)-(..?)$/u and $x >= $1 and $x <= $2
$_ =~ /^${tag}x(..?)-(..?)$/u and $x >= $1
MC/DC50%2/4
$_ =~ /^${tag}x(..?)-(..?)$/u && $x >= $1 && $x <= $2 && length $1 == length $x
$_ =~ /^${tag}x(..?)-(..?)$/u
$x >= $1
$x <= $2
length $1 == length $x
Truth table60%3/5
A and B and C && D
A= $_ =~ /^${tag}x(..?)-(..?)$/uB= $x >= $1C= $x <= $2D= length $1 == length $x
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | && $x >= $1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | && $x <= $2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | && length $1 == length $x | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } sort keys %$fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 3099 | ▶ | return $occ ne '' ? "$tag/$occ" : $tag; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | ▶ | sub TO_JSON { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | return {map {$_ => $self->{$_}} keys %$self}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub abbreviated { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abbreviated: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $abbr = dclone($self->TO_JSON); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | delete $abbr->{total}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | delete $_->{records}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | for my $field (values %{$abbr->{fields} // {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$abbr->{"fields"} // {}
MC/DC0%0/1
$abbr->{"fields"} // {}
$abbr->{"fields"}
Truth table0%0/2
A
A= $abbr->{"fields"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | delete $field->{tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | delete $field->{occurrence}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | delete $field->{total}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | for my $sf (values %{$field->{subfields} // {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$field->{"subfields"} // {}
MC/DC0%0/1
$field->{"subfields"} // {}
$field->{"subfields"}
Truth table0%0/2
A
A= $field->{"subfields"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | delete $_->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | delete $_->{records}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | return $abbr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 89 | ▶ | sub clean_pica { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_pica: called CC=22 SCAR=30.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 89 | my ($record, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 89 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 89 | my $handler = $options{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | my $error = exists $options{error} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 17 | ▶ | ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 17 | ▶ | if ($handler) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 17 | ▶ | $handler->(PICA::Error->new($_[1] || [], message => $_[0])); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[1] || []
MC/DC100%1/1
$_[1] || []
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 17 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | : sub {say STDERR shift; $ok = 0}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 89 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 89 | ▶ | if (reftype $record ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | $error->('PICA record must be array reference'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ▶ | elsif (!@$record && !$options{ignore_empty_records}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@$record || $options{'ignore_empty_records'}
MC/DC100%2/2
@$record || $options{'ignore_empty_records'}
@$record
$options{'ignore_empty_records'}
Truth table100%3/3
A || B
A= @$recordB= $options{'ignore_empty_records'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | $error->('PICA record should not be empty'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 89 | ▶ | return unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 83 | my @filtered; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 83 | for my $field (@$record) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 3135 | ▶ | if (reftype $field ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | $error->('PICA field must be array reference'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3133 | my ($tag, $occ, @sf) = @$field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3133 | ▶ | if ($tag !~ /^[012.][0-9.][0-9.][A-Z@.]$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | $error->("Malformed PICA tag: $tag", $field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 3133 | ▶ | if ($occ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 2879 | ▶ | if ($occ !~ /^[0-9]{1,3}$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | $error->("Malformed occurrence: $occ", $field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ▶ | elsif (substr($tag, 0, 1) ne '2' && length $occ eq 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
substr($tag, 0, 1) ne 2 and length $occ eq 3
MC/DC100%2/2
substr($tag, 0, 1) ne 2 and length $occ eq 3
substr($tag, 0, 1) ne 2
length $occ eq 3
Truth table100%3/3
A and B
A= substr($tag, 0, 1) ne 2B= length $occ eq 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | $error->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | "Three digit occurrences only allowed on PICA level 2", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3133 | ▶ | if (my $msg = check_annotation($field, %options)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | $error->($msg, $field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3133 | ▶ | next if $options{ignore_subfields}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3133 | ▶ | pop @sf if @sf % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3133 | ▶ | while (@sf) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 6821 | my ($code, $value) = splice @sf, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6821 | ▶ | $error->("Malformed PICA subfield: $code", $field) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | if $code !~ /^[_A-Za-z0-9]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | $error->("PICA subfield \$$code must be non-empty string", $field) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 6821 | ▶ | if $value !~ /^./ && !$options{allow_empty_subfields}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$value =~ /^./u or $options{"allow_empty_subfields"}
MC/DC100%2/2
$value =~ /^./u or $options{"allow_empty_subfields"}
$value =~ /^./u
$options{"allow_empty_subfields"}
Truth table100%3/3
A or B
A= $value =~ /^./uB= $options{"allow_empty_subfields"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 81 | ▶ | return $record if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | ▶ | sub parse_subfield_schedule { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_subfield_schedule: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 5 | my %schedule; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 5 | my $order = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 5 | for (pairs split "([*+?]?)", $_[0]) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 15 | my ($code, $status) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 15 | ▶ | die "Malformed PICA subfield: $code" if $code !~ /[a-zA-Z0-9]/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | die "Invalid subfield schedule string: subfield $code given twice!" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 15 | ▶ | if $schedule{$code}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 15 | ▶ | $schedule{$code} = { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$status eq "+" or $status eq "*"
$status ne "?" and $status ne "*"
MC/DC100%2/2
$status eq "+" or $status eq "*"
$status eq "+"
$status eq "*"
MC/DC100%2/2
$status ne "?" and $status ne "*"
$status ne "?"
$status ne "*"
Truth table100%3/3
A or B
A= $status eq "+"B= $status eq "*"
Truth table100%3/3
A and B
A= $status ne "?"B= $status ne "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | repeatable => ($status eq '+' || $status eq '*' ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | required => ($status ne '?' && $status ne '*' ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | order => $order++, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | return \%schedule; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||