| 1 | package MARC::Validator::Plugin::Field008; | ||||||||||
| 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(err_get); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 6 | ▶ | use MARC::Leader 0.08; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 6 | ▶ | use MARC::Field008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 6 | our $VERSION = 0.25; | |||||||||
| 15 | |||||||||||
| 16 | 8 | ▶ | sub module_name { | ||||||||
|
Subroutine
module_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 17 | 8 | my $self = shift; | |||||||||
| 18 | |||||||||||
| 19 | 8 | return __PACKAGE__; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 9 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | 9 | my $self = shift; | |||||||||
| 24 | |||||||||||
| 25 | 9 | return 'field_008'; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 6 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||
| 29 | 6 | my ($self, $marc_record) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 6 | my $record_id = $self->{'cb_record_id'}->($marc_record); | |||||||||
| 32 | 6 | my @record_errors; | |||||||||
| 33 | |||||||||||
| 34 | 6 | my $leader_string = $marc_record->leader; | |||||||||
| 35 | 6 | my $leader = eval { | |||||||||
| 36 | MARC::Leader->new( | ||||||||||
| 37 | 6 | 'verbose' => $self->{'verbose'}, | |||||||||
| 38 | )->parse($leader_string); | ||||||||||
| 39 | }; | ||||||||||
| 40 | 6 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 1 | my @errors = err_get(1); | |||||||||
| 42 | 1 | foreach my $error (@errors) { | |||||||||
| 43 | 2 | my %err_params = @{$error->{'msg'}}[1 .. $#{$error->{'msg'}}]; | |||||||||
| 44 | push @record_errors, Data::MARC::Validator::Report::Error->new( | ||||||||||
| 45 | 2 | 'error' => $error->{'msg'}->[0], | |||||||||
| 46 | 'params' => \%err_params, | ||||||||||
| 47 | ); | ||||||||||
| 48 | } | ||||||||||
| 49 | 1 | $self->_process_errors($record_id, @record_errors); | |||||||||
| 50 | 1 | return; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 5 | my $field_008_obj = $marc_record->field('008'); | |||||||||
| 54 | 5 | ▶ | if (! defined $field_008_obj) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||
| 56 | 'error' => 'Field 008 is not present.', | ||||||||||
| 57 | ); | ||||||||||
| 58 | 1 | $self->_process_errors($record_id, @record_errors); | |||||||||
| 59 | 1 | return; | |||||||||
| 60 | } | ||||||||||
| 61 | 4 | my $field_008_string = $field_008_obj->as_string; | |||||||||
| 62 | 4 | my $field_008 = eval { | |||||||||
| 63 | MARC::Field008->new( | ||||||||||
| 64 | 'leader' => $leader, | ||||||||||
| 65 | 4 | 'verbose' => $self->{'verbose'}, | |||||||||
| 66 | )->parse($field_008_string); | ||||||||||
| 67 | }; | ||||||||||
| 68 | 4 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 2 | my @errors = err_get(1); | |||||||||
| 70 | 2 | foreach my $error (@errors) { | |||||||||
| 71 | 4 | my %err_params = @{$error->{'msg'}}[1 .. $#{$error->{'msg'}}]; | |||||||||
| 72 | # XXX Weird error. | ||||||||||
| 73 | 4 | ▶ | if (exists $err_params{'DateTime error'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 0 | delete $err_params{'DateTime error'}; | |||||||||
| 75 | } | ||||||||||
| 76 | push @record_errors, Data::MARC::Validator::Report::Error->new( | ||||||||||
| 77 | 4 | 'error' => $error->{'msg'}->[0], | |||||||||
| 78 | 'params' => \%err_params, | ||||||||||
| 79 | ); | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | # Parsing of field 008 is valid, other checks. | ||||||||||
| 83 | } else { | ||||||||||
| 84 | 2 | ▶ | if ($field_008->type_of_date eq 's') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 1 | ▶ | if ($field_008->date1 eq ' ') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||
| 87 | 'error' => 'Field 008 date 1 need to be fill.', | ||||||||||
| 88 | 'params' => { | ||||||||||
| 89 | 'Value' => $field_008_string, | ||||||||||
| 90 | }, | ||||||||||
| 91 | ); | ||||||||||
| 92 | } else { | ||||||||||
| 93 | 0 | ▶ | if ($field_008->date1 eq $field_008->date2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||
| 95 | 'error' => 'Field 008 date 1 is same as date 2.', | ||||||||||
| 96 | 'params' => { | ||||||||||
| 97 | 'Value' => $field_008_string, | ||||||||||
| 98 | }, | ||||||||||
| 99 | ); | ||||||||||
| 100 | } | ||||||||||
| 101 | } | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 2 | ▶ | if ($field_008->type_of_date eq 'c') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 1 | ▶ | if ($field_008->date2 ne '9999') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 1 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||
| 107 | 'error' => 'Field 008 date 2 need to be 9999, it\'s currently published.', | ||||||||||
| 108 | 'params' => { | ||||||||||
| 109 | 'Value' => $field_008_string, | ||||||||||
| 110 | }, | ||||||||||
| 111 | ); | ||||||||||
| 112 | } | ||||||||||
| 113 | } | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 4 | $self->_process_errors($record_id, @record_errors); | |||||||||
| 117 | |||||||||||
| 118 | 4 | return; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 8 | ▶ | sub version { | ||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 122 | 8 | my $self = shift; | |||||||||
| 123 | |||||||||||
| 124 | 8 | return $VERSION; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 6 | ▶ | sub _process_errors { | ||||||||
|
Subroutine
_process_errors: called CC=2 SCAR=7.0
| |||||||||||
| 128 | 6 | my ($self, $record_id, @record_errors) = @_; | |||||||||
| 129 | |||||||||||
| 130 | 6 | ▶ | if (@record_errors) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 6 | push @{$self->{'errors'}}, Data::MARC::Validator::Report::Plugin::Errors->new( | |||||||||
| 132 | 'errors' => \@record_errors, | ||||||||||
| 133 | 6 | 'filters' => $self->{'filters'}, | |||||||||
| 134 | 'record_id' => $record_id, | ||||||||||
| 135 | ); | ||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | 6 | return; | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | 6 | 1; | |||||||||
| 142 | |||||||||||
| 143 | __END__ | ||||||||||