Validator/Plugin/Field045.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 93.8% 61 / 65 CC 5 SCAR 7.1
CC
5
Cov
92%
process
4.1
_check_time_period_code
2.0
BEGIN
1.0
CRAP 2.0
« Validator/Plugin/Field035.pm ↑ Summary Validator/Plugin/Field260.pm »
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
BranchTrueFalseTotal
if (defined $field_045) 1 0 1
32 1 my $field_045a = $field_045->subfield('a');
33 1 ▶ if (length($field_045a) != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $field_045a != 4) 0 1 1
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
BranchTrueFalseTotal
if (@record_errors) 1 0 1
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
BranchTrueFalseTotal
unless ($input =~ /^[abcdefghijklmnopqrstuvwxy][\-\d]$/ms) 1 1 2
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__
« Validator/Plugin/Field035.pm ↑ Summary Validator/Plugin/Field260.pm »