| 1 | package MARC::Validator::Plugin::Field045; | ||||||||||
| 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 | |||||||||||
| 10 | 6 | our $VERSION = 0.25; | |||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | sub module_name { | ||||||||
|
Subroutine
module_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 3 | my $self = shift; | |||||||||
| 14 | |||||||||||
| 15 | 3 | return __PACKAGE__; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 4 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | 4 | my $self = shift; | |||||||||
| 20 | |||||||||||
| 21 | 4 | return 'field_045'; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 25 | 1 | my ($self, $marc_record) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 1 | my $record_id = $self->{'cb_record_id'}->($marc_record); | |||||||||
| 28 | 1 | my @record_errors; | |||||||||
| 29 | |||||||||||
| 30 | 1 | my $field_045 = $marc_record->field('045'); | |||||||||
| 31 | 1 | ▶ | if (defined $field_045) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | my $field_045a = $field_045->subfield('a'); | |||||||||
| 33 | 1 | ▶ | if (length($field_045a) != 4) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | push @record_errors, Data::MARC::Validator::Report::Error->new( | |||||||||
| 35 | 'error' => "Field 045a has bad length.", | ||||||||||
| 36 | ); | ||||||||||
| 37 | } | ||||||||||
| 38 | 1 | my $field_045a_first = substr $field_045a, 0, 2; | |||||||||
| 39 | 1 | my $field_045a_second = substr $field_045a, 2, 2; | |||||||||
| 40 | 1 | push @record_errors, $self->_check_time_period_code($field_045a_first, 'first'); | |||||||||
| 41 | 1 | push @record_errors, $self->_check_time_period_code($field_045a_second, 'second'); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | if (@record_errors) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 1 | push @{$self->{'errors'}}, Data::MARC::Validator::Report::Plugin::Errors->new( | |||||||||
| 46 | 'errors' => \@record_errors, | ||||||||||
| 47 | 1 | 'filters' => $self->{'filters'}, | |||||||||
| 48 | 'record_id' => $record_id, | ||||||||||
| 49 | ); | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | return; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 3 | ▶ | sub version { | ||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 56 | 3 | my $self = shift; | |||||||||
| 57 | |||||||||||
| 58 | 3 | return $VERSION; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 2 | ▶ | sub _check_time_period_code { | ||||||||
|
Subroutine
_check_time_period_code: called CC=2 SCAR=6.9
| |||||||||||
| 62 | 2 | my ($self, $input, $resolution) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 2 | ▶ | if ($input !~ m/^[abcdefghijklmnopqrstuvwxy][\-\d]$/ms) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 1 | return Data::MARC::Validator::Report::Error->new( | |||||||||
| 66 | 'error' => "Field 045a has invalid $resolution block.", | ||||||||||
| 67 | 'params' => { | ||||||||||
| 68 | 'value' => $input, | ||||||||||
| 69 | }, | ||||||||||
| 70 | ); | ||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 1 | return (); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 6 | 1; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||