| 1 | package PICA::Error; | ||||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use overload fallback => 1, '""' => \&message; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 3066 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 7 | 3066 | my $class = shift; | |||||||||||||||||||||||||||||
| 8 | 3066 | my ($tag, $occ) = @{shift(@_)}; | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 3066 | my $error = {tag => $tag, @_}; | |||||||||||||||||||||||||||||
| 11 | 3066 | ▶ | $occ = 0 if substr($tag, 0, 1) eq 2; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 12 | 3066 | ▶ | $error->{occurrence} = $occ if $occ; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | # add error messages | ||||||||||||||||||||||||||||||
| 15 | 3066 | my $id = join '/', grep {$_} $tag, $occ; | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 3066 | ▶ | while (my ($code, $sf) = each %{$error->{subfields} // {}}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$error->{"subfields"} // {}
MC/DC100%1/1
$error->{"subfields"} // {}
$error->{"subfields"}
Truth table100%2/2
A
A= $error->{"subfields"}
| |||||||||||||||||||||||||||||||
| 18 | 1066 | $sf->{code} = $code; | |||||||||||||||||||||||||||||
| 19 | 1066 | $sf->{message} = _subfield_error_message($sf, $id); | |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | $error->{message} = _field_error_message($error, $id) | ||||||||||||||||||||||||||||||
| 23 | 3066 | ▶ | unless $error->{message}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 3066 | bless $error, $class; | |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 28381 | ▶ | sub message { | ||||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 29 | 28381 | ▶ | $_[0]->{message} // ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0]{"message"} // ""
MC/DC0%0/1
$_[0]{"message"} // ""
$_[0]{"message"}
Truth table50%1/2
A
A= $_[0]{"message"}
| |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | 1066 | ▶ | sub _subfield_error_message { | ||||||||||||||||||||||||||||
|
Subroutine
_subfield_error_message: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||
| 33 | 1066 | my $error = shift; | |||||||||||||||||||||||||||||
| 34 | 1066 | ▶ | my $id = (shift // '') . '$' . $error->{code}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 1066 | ▶ | if ($error->{required}) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 37 | 354 | "missing subfield $id"; | |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||
| 39 | elsif ($error->{repeated}) { | ||||||||||||||||||||||||||||||
| 40 | 1 | "subfield $id is not repeatable"; | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||
| 42 | elsif ($error->{deprecated}) { | ||||||||||||||||||||||||||||||
| 43 | 0 | "deprecated subfield $id"; | |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||
| 45 | elsif ($error->{position}) { | ||||||||||||||||||||||||||||||
| 46 | 2 | "invalid value at position $error->{position} of subfield $id"; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | elsif ($error->{pattern}) { | ||||||||||||||||||||||||||||||
| 49 | 1 | "value of subfield $id does not match pattern $error->{pattern}"; | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | elsif (defined $error->{order}) { | ||||||||||||||||||||||||||||||
| 52 | 1 | "wrong subfield order of $id"; | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||||
| 55 | 707 | "unknown subfield $id"; | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 3049 | ▶ | sub _field_error_message { | ||||||||||||||||||||||||||||
|
Subroutine
_field_error_message: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||
| 60 | 3049 | my ($error, $id) = @_; | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | 3049 | ▶ | if ($error->{required}) { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 63 | 2 | "missing field $id"; | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||
| 65 | elsif ($error->{repeated}) { | ||||||||||||||||||||||||||||||
| 66 | 2 | "field $id is not repeatable"; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | elsif ($error->{subfields}) { | ||||||||||||||||||||||||||||||
| 69 | 360 | my %sf = %{$error->{subfields}}; | |||||||||||||||||||||||||||||
| 70 | 360 | my $invalid = grep {$_->{message} !~ /^unknown/} values %sf; | |||||||||||||||||||||||||||||
| 71 | 360 | ▶ | ($invalid ? "invalid" : "unknown") | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 72 | . " subfield" | ||||||||||||||||||||||||||||||
| 73 | . (length keys %sf > 1 ? "s" : "") | ||||||||||||||||||||||||||||||
| 74 | . " $id\$" | ||||||||||||||||||||||||||||||
| 75 | . join '', sort keys %sf; | ||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | elsif ($error->{deprecated}) { | ||||||||||||||||||||||||||||||
| 78 | 0 | "deprecated field $id"; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||
| 81 | 2685 | "unknown field $id"; | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | 16 | 1; | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||