Validator/Plugin/Field020.pm

filter: Statementstmt 94.1% 64 / 68 Branchbran 85.0% 17 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 93.3% 98 / 105 CC 12 SCAR 19.0
CC
12
Cov
92%
process
12.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.7
« Validator/Plugin/Field264.pm ↑ Summary Validator/Plugin/Field008.pm »
1 package MARC::Validator::Plugin::Field020;
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 Business::ISBN;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Data::MARC::Validator::Report::Error 0.02;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Data::MARC::Validator::Report::Plugin::Errors 0.02;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Error::Pure::Utils qw(clean err_get);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use MARC::Leader;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 our $VERSION = 0.25;
15  
16 10 ▶sub module_name {
Subroutine module_name: called CC=1 SCAR=0.0
Pod documented
17 10 my $self = shift;
18  
19 10 return __PACKAGE__;
20 }
21  
22 11 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
23 11 my $self = shift;
24  
25 11 return 'field_020';
26 }
27  
28 8 ▶sub process {
Subroutine process: called CC=12 SCAR=25.1
Pod documented
29 8 my ($self, $marc_record) = @_;
30  
31 8 my $record_id = $self->{'cb_record_id'}->($marc_record);
32 8 my @record_errors;
33  
34 8 my $leader_string = $marc_record->leader;
35 8 my $leader = eval {
36 MARC::Leader->new(
37 8 'verbose' => $self->{'verbose'},
38 )->parse($leader_string);
39 };
40 8 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MARC::Validator::Plugin::Field020::EVAL_ERROR) 0 8 8
41 # Error in leader, not validate.
42 0 clean();
43 0 return;
44 }
45  
46 8 my @isbn_fields = $marc_record->field('020');
47 8 foreach my $isbn_field (@isbn_fields) {
48 9 my $isbn = $isbn_field->subfield('a');
49 9 ▶ if (! defined $isbn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isbn) 1 8 9
50 1 next;
51 }
52 8 my $isbn_obj = Business::ISBN->new($isbn);
53 8 ▶ if (! defined $isbn_obj) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $isbn_obj) { } 1 7 8
elsif (not $isbn_obj->is_valid) { } 1 6 7
54 1 push @record_errors, Data::MARC::Validator::Report::Error->new(
55 'error' => 'Bad ISBN in 020a field.',
56 'params' => {
57 'Value' => $isbn,
58 },
59 );
60 } elsif (! $isbn_obj->is_valid) {
61 1 $isbn_obj->fix_checksum;
62 1 ▶ if (! $isbn_obj->is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isbn_obj->is_valid) { } 1 0 1
63 1 push @record_errors, Data::MARC::Validator::Report::Error->new(
64 'error' => 'Bad ISBN in 020a field after fixing of checksum.',
65 'params' => {
66 'Value' => $isbn,
67 },
68 );
69 } else {
70 0 push @record_errors, Data::MARC::Validator::Report::Error->new(
71 'error' => 'Bad checksum of ISBN in 020a field.',
72 'params' => {
73 'Value' => $isbn,
74 },
75 );
76 }
77 } else {
78 6 ▶ if ($isbn_obj->as_string ne $isbn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn_obj->as_string ne $isbn) 5 1 6
79 5 ▶ if ($isbn =~ m/^[\d\-]+$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn =~ /^[\d\-]+$/ms) { } 3 2 5
80 3 push @record_errors, Data::MARC::Validator::Report::Error->new(
81 'error' => 'Bad ISBN in 020a field, bad formatting.',
82 'params' => {
83 'Value' => $isbn,
84 'proposed_value' => $isbn_obj->as_string,
85 },
86 );
87 } else {
88 # Skip ISBD punctuations.
89 2 ▶ if ($leader->descriptive_cataloging_form eq 'i') {
Branch: 1 branch
BranchTrueFalseTotal
if ($leader->descriptive_cataloging_form eq 'i') { } 1 1 2
90 1 my $new_isbn = $isbn_obj->as_string;
91 1 ▶ if ($isbn !~ m/^$new_isbn\s*:?\s*$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isbn =~ /^$new_isbn\s*:?\s*$/ms) 0 1 1
92 0 push @record_errors, Data::MARC::Validator::Report::Error->new(
93 'error' => 'Bad ISBN in 020a field, extra characters.',
94 'params' => {
95 'Value' => $isbn,
96 'proposed_value' => $isbn_obj->as_string,
97 },
98 );
99 }
100 } else {
101 1 push @record_errors, Data::MARC::Validator::Report::Error->new(
102 'error' => 'Bad ISBN in 020a field, extra characters.',
103 'params' => {
104 'Value' => $isbn,
105 'proposed_value' => $isbn_obj->as_string,
106 },
107 );
108 }
109 }
110 }
111 }
112 }
113  
114 8 ▶ if (@record_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@record_errors) 6 2 8
115 6 push @{$self->{'errors'}}, Data::MARC::Validator::Report::Plugin::Errors->new(
116 'errors' => \@record_errors,
117 6 'filters' => $self->{'filters'},
118 'record_id' => $record_id,
119 );
120 }
121  
122 8 return;
123 }
124  
125 10 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
126 10 my $self = shift;
127  
128 10 return $VERSION;
129 }
130  
131 6 1;
132  
133 __END__
« Validator/Plugin/Field264.pm ↑ Summary Validator/Plugin/Field008.pm »