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