Validator/Plugin/Field300.pm

filter: Statementstmt 94.3% 83 / 88 Branchbran 76.9% 20 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 100% 4 / 4 totaltotal 91.8% 124 / 135 CC 15 SCAR 21.0
CC
15
Cov
90%
process
15.8
__ANON__
1.0
BEGIN
1.0
CRAP 8.1
« Validator/Plugin/Field500.pm ↑ Summary Validator/Plugin/Field264.pm »
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
BranchTrueFalseTotal
if ($MARC::Validator::Plugin::Field300::EVAL_ERROR) 0 5 5
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
BranchTrueFalseTotal
unless (defined $field_008_obj) 0 5 5
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
BranchTrueFalseTotal
if ($MARC::Validator::Plugin::Field300::EVAL_ERROR) 0 5 5
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
BranchTrueFalseTotal
if (defined $field_300a) 5 0 5
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
BranchTrueFalseTotal
if (&any(sub { ($bad_string) = $field_300a =~ /($_)/ms; } , @MARC::Validator::Const::FIELD_300ab_BAD)) 1 4 5
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
BranchTrueFalseTotal
if (defined $field_300b) 5 0 5
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
BranchTrueFalseTotal
if (&any(sub { ($bad_string) = $field_300b =~ /($_)/ms; } , @MARC::Validator::Const::FIELD_300ab_BAD)) { } 1 4 5
elsif ($material->isa('Data::MARC::Field008::Book')) { } 4 0 4
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
BranchTrueFalseTotal
if ($material->illustrations eq ' ') { } 1 3 4
elsif ($material->illustrations eq '||||') { } 2 1 3
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
BranchTrueFalseTotal
if ($self->{"recommendation"}) 1 1 2
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
BranchTrueFalseTotal
if (@record_errors) 3 2 5
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
BranchTrueFalseTotal
if (@record_errors_recomm) 1 4 5
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__
« Validator/Plugin/Field500.pm ↑ Summary Validator/Plugin/Field264.pm »