| 1 | package MARC::Validator::Plugin::Field300; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 6 | ▶ | use base qw(MARC::Validator::Abstract); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | ▶ | use Data::MARC::Validator::Report::Error 0.02; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 6 | ▶ | use Data::MARC::Validator::Report::Plugin::Errors 0.02; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 6 | ▶ | use English; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 6 | ▶ | use Error::Pure::Utils qw(clean); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 6 | ▶ | use List::Util 1.33 qw(any); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 6 | ▶ | use MARC::Leader 0.08; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 6 | ▶ | use MARC::Field008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 6 | ▶ | use MARC::Validator::Const; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 6 | our $VERSION = 0.25; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 7 | ▶ | sub module_name { | ||||||||||||
|
Subroutine
module_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 19 | 7 | my $self = shift; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 7 | return __PACKAGE__; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 8 | ▶ | sub name { | ||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 25 | 8 | my $self = shift; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 8 | return 'field_300'; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 5 | ▶ | sub process { | ||||||||||||
|
Subroutine
process: called CC=15 SCAR=27.6
Pod
documented
| |||||||||||||||
| 31 | 5 | my ($self, $marc_record) = @_; | |||||||||||||
| 32 | |||||||||||||||
| 33 | 5 | my $record_id = $self->{'cb_record_id'}->($marc_record); | |||||||||||||
| 34 | 5 | my @record_errors; | |||||||||||||
| 35 | my @record_errors_recomm; | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 5 | my $leader_string = $marc_record->leader; | |||||||||||||
| 38 | 5 | my $leader = eval { | |||||||||||||
| 39 | MARC::Leader->new( | ||||||||||||||
| 40 | 5 | 'verbose' => $self->{'verbose'}, | |||||||||||||
| 41 | )->parse($leader_string); | ||||||||||||||
| 42 | }; | ||||||||||||||
| 43 | 5 | ▶ | if ($EVAL_ERROR) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | clean(); | |||||||||||||
| 45 | 0 | return; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 5 | my $field_008_obj = $marc_record->field('008'); | |||||||||||||
| 49 | 5 | ▶ | if (! defined $field_008_obj) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | return; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | 5 | my $field_008_string = $field_008_obj->as_string; | |||||||||||||
| 53 | 5 | my $field_008 = eval { | |||||||||||||
| 54 | MARC::Field008->new( | ||||||||||||||
| 55 | 'leader' => $leader, | ||||||||||||||
| 56 | 5 | 'verbose' => $self->{'verbose'}, | |||||||||||||
| 57 | )->parse($field_008_string); | ||||||||||||||
| 58 | }; | ||||||||||||||
| 59 | 5 | ▶ | if ($EVAL_ERROR) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | clean(); | |||||||||||||
| 61 | 0 | return; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 5 | my @field_300 = $marc_record->field('300'); | |||||||||||||
| 65 | 5 | foreach my $field_300 (@field_300) { | |||||||||||||
| 66 | 5 | my $field_300a = $field_300->subfield('a'); | |||||||||||||
| 67 | 5 | ▶ | if (defined $field_300a) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 5 | my $bad_string; | |||||||||||||
| 69 | 5 | ▶ | if (any { ($bad_string) = $field_300a =~ m/($_)/ms } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||
| 70 | @MARC::Validator::Const::FIELD_300ab_BAD) { | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||||||
| 73 | 'error' => 'Bad string in field 300a.', | ||||||||||||||
| 74 | 'params' => { | ||||||||||||||
| 75 | 'bad_string' => $bad_string, | ||||||||||||||
| 76 | 'field_300_a' => $field_300a, | ||||||||||||||
| 77 | }, | ||||||||||||||
| 78 | ); | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | } | ||||||||||||||
| 81 | 5 | my $field_300b = $field_300->subfield('b'); | |||||||||||||
| 82 | 5 | ▶ | if (defined $field_300b) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 5 | my $material = $field_008->material; | |||||||||||||
| 84 | 5 | my $bad_string; | |||||||||||||
| 85 | 5 | ▶ | if (any { ($bad_string) = $field_300b =~ m/($_)/ms } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||
| 86 | @MARC::Validator::Const::FIELD_300ab_BAD) { | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||||||
| 89 | 'error' => 'Bad string in field 300b.', | ||||||||||||||
| 90 | 'params' => { | ||||||||||||||
| 91 | 'bad_string' => $bad_string, | ||||||||||||||
| 92 | 'field_300_b' => $field_300b, | ||||||||||||||
| 93 | }, | ||||||||||||||
| 94 | ); | ||||||||||||||
| 95 | |||||||||||||||
| 96 | # Continue with checks. | ||||||||||||||
| 97 | } elsif ($material->isa('Data::MARC::Field008::Book')) { | ||||||||||||||
| 98 | 4 | ▶ | if ($material->illustrations eq ' ') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 99 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||||||
| 100 | 'error' => 'Missing ilustrations in field 008.', | ||||||||||||||
| 101 | 'params' => { | ||||||||||||||
| 102 | 'field_008_illustrations' => $material->illustrations, | ||||||||||||||
| 103 | 'field_300_b' => $field_300b, | ||||||||||||||
| 104 | 'material' => 'book', | ||||||||||||||
| 105 | }, | ||||||||||||||
| 106 | ); | ||||||||||||||
| 107 | 1 | last; | |||||||||||||
| 108 | } elsif ($material->illustrations eq '||||') { | ||||||||||||||
| 109 | 2 | ▶ | if ($self->{'recommendation'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 110 | 1 | push @record_errors_recomm, Data::MARC::Validator::Report::Error->new( | |||||||||||||
| 111 | 'error' => 'Recommended ilustrations in field 008.', | ||||||||||||||
| 112 | 'params' => { | ||||||||||||||
| 113 | 'field_008_illustrations' => $material->illustrations, | ||||||||||||||
| 114 | 'field_300_b' => $field_300b, | ||||||||||||||
| 115 | 'material' => 'book', | ||||||||||||||
| 116 | }, | ||||||||||||||
| 117 | ); | ||||||||||||||
| 118 | 1 | last; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | } | ||||||||||||||
| 122 | } | ||||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 5 | ▶ | if (@record_errors) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | 3 | push @{$self->{'errors'}}, Data::MARC::Validator::Report::Plugin::Errors->new( | |||||||||||||
| 127 | 'errors' => \@record_errors, | ||||||||||||||
| 128 | 3 | 'filters' => $self->{'filters'}, | |||||||||||||
| 129 | 'record_id' => $record_id, | ||||||||||||||
| 130 | ); | ||||||||||||||
| 131 | } | ||||||||||||||
| 132 | 5 | ▶ | if (@record_errors_recomm) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | 1 | push @{$self->{'errors'}}, Data::MARC::Validator::Report::Plugin::Errors->new( | |||||||||||||
| 134 | 'errors' => \@record_errors_recomm, | ||||||||||||||
| 135 | 1 | 'filters' => [@{$self->{'filters'}}, 'recommendation'], | |||||||||||||
| 136 | 'record_id' => $record_id, | ||||||||||||||
| 137 | ); | ||||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | 5 | return; | |||||||||||||
| 141 | } | ||||||||||||||
| 142 | |||||||||||||||
| 143 | 7 | ▶ | sub version { | ||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 144 | 7 | my $self = shift; | |||||||||||||
| 145 | |||||||||||||||
| 146 | 7 | return $VERSION; | |||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 6 | 1; | |||||||||||||
| 150 | |||||||||||||||
| 151 | __END__ | ||||||||||||||