blib/lib/MARC/Field008.pm

filter: Statementstmt 94.8% 129 / 136 Branchbran 75.9% 41 / 54 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 27 / 27 Podpod 100% 3 / 3 totaltotal 90.6% 213 / 235 CC 31 SCAR 21.2
CC
31
Cov
89%
_parse_different
20.0
_serialize_different
8.1
parse
6.0
CRAP 8.3
↑ Summary
1 package MARC::Field008;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Data::MARC::Field008;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Data::MARC::Field008::Book 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Data::MARC::Field008::ComputerFile 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Data::MARC::Field008::ContinuingResource 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Data::MARC::Field008::Map 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Data::MARC::Field008::MixedMaterial 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Data::MARC::Field008::Music 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Data::MARC::Field008::VisualMaterial 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use List::Util 1.33 qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Mo::utils 0.08 qw(check_bool check_isa check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 our $VERSION = 0.06;
22  
23 # Constructor.
24 24 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
25 24 my ($class, @params) = @_;
26  
27 # Create object.
28 24 my $self = bless {}, $class;
29  
30 # Ignore data errors.
31 24 $self->{'ignore_data_errors'} = 0;
32  
33 # Leader.
34 24 $self->{'leader'} = undef;
35  
36 # Mode strict.
37 24 $self->{'mode_strict'} = 0;
38  
39 # Verbose mode.
40 24 $self->{'verbose'} = 0;
41  
42 # Process parameters.
43 24 set_params($self, @params);
44  
45 # Check 'ignore_data_errors'.
46 24 check_required($self, 'ignore_data_errors');
47 24 check_bool($self, 'ignore_data_errors');
48  
49 # Check 'leader'.
50 23 check_isa($self, 'leader', 'Data::MARC::Leader');
51  
52 # Check 'mode_strict'.
53 21 check_bool($self, 'mode_strict');
54  
55 # Check 'verbose'.
56 21 check_bool($self, 'verbose');
57  
58 21 return $self;
59 }
60  
61 18 ▶sub parse {
Subroutine parse: called CC=6 SCAR=17.9
Pod documented
62 18 my ($self, $field_008) = @_;
63  
64 # Parameter 'leader' is required for parse().
65 18 check_required($self, 'leader');
66  
67 # XXX Fix white space issue in MARC XML record.
68 17 ▶ if (length($field_008) < 40) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $field_008 < 40) 4 13 17
69 4 $field_008 .= (' ' x (40 - length($field_008)));
70 }
71  
72 # Dashes are spaces.
73 17 ▶ if (! $self->{'mode_strict'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"mode_strict"}) 15 2 17
74 15 $field_008 =~ s/\-/\ /msg;
75 }
76  
77 # Check length.
78 17 ▶ if (length($field_008) > 40) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $field_008 > 40) 1 16 17
79 1 err 'Bad length of MARC 008 field.',
80 'Length', length($field_008),
81 ;
82 }
83 16 ▶ if ($self->{'verbose'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 16 16
84 0 print "Field 008: |$field_008|\n";
85 }
86  
87 16 my $field_008_obj = eval {
88 16 my %material_params = eval {
89 16 $self->_parse_different($field_008);
90 };
91 16 my %params = (
92 'raw' => $field_008,
93  
94 'date_entered_on_file' => (substr $field_008, 0, 6),
95 'type_of_date' => (substr $field_008, 6, 1),
96 'date1' => (substr $field_008, 7, 4),
97 'date2' => (substr $field_008, 11, 4),
98 'place_of_publication' => (substr $field_008, 15, 3),
99 %material_params,
100 'language' => (substr $field_008, 35, 3),
101 'modified_record' => (substr $field_008, 38, 1),
102 'cataloging_source' => (substr $field_008, 39, 1),
103 );
104 16 Data::MARC::Field008->new(%params);
105 };
106 16 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MARC::Field008::EVAL_ERROR) 2 14 16
107 2 err "Couldn't parse MARC 008 field.";
108 }
109  
110 14 return $field_008_obj;
111 }
112  
113 8 ▶sub serialize {
Subroutine serialize: called CC=3 SCAR=11.0
Pod documented
114 8 my ($self, $field_008_obj) = @_;
115  
116 # Check object.
117 8 ▶ if (! blessed($field_008_obj) || ! $field_008_obj->isa('Data::MARC::Field008')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($field_008_obj) and $field_008_obj->isa("Data::MARC::Field008")) 2 6 8
Condition100%3/3
builtin::blessed($field_008_obj) and $field_008_obj->isa("Data::MARC::Field008")
!ll&&!rl&&r
116
MC/DC100%2/2
builtin::blessed($field_008_obj) and $field_008_obj->isa("Data::MARC::Field008")
builtin::blessed($field_008_obj) $field_008_obj->isa("Data::MARC::Field008")
Truth table100%3/3
A and B
A= builtin::blessed($field_008_obj)B= $field_008_obj->isa("Data::MARC::Field008")
ABresult
0X0
100
111
118 2 err "Bad 'Data::MARC::Field008' instance to serialize.";
119 }
120  
121 6 my $field_008 = $field_008_obj->date_entered_on_file.
122 $field_008_obj->type_of_date.
123 $field_008_obj->date1.
124 $field_008_obj->date2.
125 $field_008_obj->place_of_publication.
126 $self->_serialize_different($field_008_obj->material).
127 $field_008_obj->language.
128 $field_008_obj->modified_record.
129 $field_008_obj->cataloging_source;
130  
131 6 return $field_008;
132 }
133  
134 16 ▶sub _parse_different {
Subroutine _parse_different: called CC=17 SCAR=30.0
135 16 my ($self, $field_008) = @_;
136  
137 16 my %params;
138  
139 # Book
140 16 ▶ if ((any { $self->{'leader'}->type eq $_ } qw(a t))
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 7 branches
BranchTrueFalseTotal
if (&any(sub { $self->{'leader'}->type eq $_; } , 'a', 't') and &any(sub { $self->{'leader'}->bibliographic_level eq $_; } , 'a', 'c', 'd', 'm')) { } 6 10 16
elsif ($self->{'leader'}->type eq 'm') { } 2 8 10
elsif (&any(sub { $self->{'leader'}->type eq $_; } , 'e', 'f')) { } 2 6 8
elsif (&any(sub { $self->{'leader'}->type eq $_; } , 'c', 'd', 'i', 'j')) { } 2 4 6
elsif ($self->{'leader'}->type eq 'a' and &any(sub { $self->{'leader'}->bibliographic_level eq $_; } , 'b', 'i', 's')) { } 2 2 4
elsif (&any(sub { $self->{'leader'}->type eq $_; } , 'g', 'k', 'o', 'r')) { } 2 0 2
elsif ($self->{'leader'}->type eq 'p') { } 0 0 0
Condition100%3/3
&any(sub { $self->{"leader"}->type eq $_; } , "a", "t") and &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "a", "c", "d", "m")
!ll&&!rl&&r
826
MC/DC100%2/2
&any(sub { $self->{"leader"}->type eq $_; } , "a", "t") and &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "a", "c", "d", "m")
&any(sub { $self->{"leader"}->type eq $_; } , "a", "t") &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "a", "c", "d", "m")
Truth table100%3/3
A and B
A= &any(sub { $self->{"leader"}->type eq $_; } , "a", "t")B= &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "a", "c", "d", "m")
ABresult
0X0
100
111
141 32 ▶ && (any { $self->{'leader'}->bibliographic_level eq $_ } qw(a c d m))) {
Subroutine __ANON__: called CC=1 SCAR=0.0
142  
143 6 my %mat_params = (
144 'illustrations' => substr($field_008, 18, 4),
145 'target_audience' => substr($field_008, 22, 1),
146 'form_of_item' => substr($field_008, 23, 1),
147 'nature_of_content' => substr($field_008, 24, 4),
148 'government_publication' => substr($field_008, 28, 1),
149 'conference_publication' => substr($field_008, 29, 1),
150 'festschrift' => substr($field_008, 30, 1),
151 'index' => substr($field_008, 31, 1),
152 'literary_form' => substr($field_008, 33, 1),
153 'biography' => substr($field_008, 34, 1),
154  
155 'raw' => substr($field_008, 18, 17),
156 );
157 6 ▶ $Data::MARC::Field008::Book::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 1 5 6
158 6 my $material = Data::MARC::Field008::Book->new(%mat_params);
159 4 %params = (
160 'material' => $material,
161 'material_type' => 'book',
162 );
163  
164 # Computer files.
165 } elsif ($self->{'leader'}->type eq 'm') {
166 2 my %mat_params = (
167 'target_audience' => substr($field_008, 22, 1),
168 'form_of_item' => substr($field_008, 23, 1),
169 'type_of_computer_file' => substr($field_008, 26, 1),
170 'government_publication' => substr($field_008, 28, 1),
171  
172 'raw' => substr($field_008, 18, 17),
173 );
174 2 ▶ $Data::MARC::Field008::ComputerFile::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 2 2
175 2 my $material = Data::MARC::Field008::ComputerFile->new(%mat_params);
176 2 %params = (
177 'material' => $material,
178 'material_type' => 'computer_file',
179 );
180  
181 # Maps.
182 14 ▶ } elsif (any { $self->{'leader'}->type eq $_ } qw(e f)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
183 2 my %mat_params = (
184 'relief' => substr($field_008, 18, 4),
185 'projection' => substr($field_008, 22, 2),
186 'type_of_cartographic_material' => substr($field_008, 25, 1),
187 'government_publication' => substr($field_008, 28, 1),
188 'form_of_item' => substr($field_008, 29, 1),
189 'index' => substr($field_008, 31, 1),
190 'special_format_characteristics' => substr($field_008, 33, 2),
191  
192 'raw' => substr($field_008, 18, 17),
193 );
194 2 ▶ $Data::MARC::Field008::Map::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 2 2
195 2 my $material = Data::MARC::Field008::Map->new(%mat_params);
196 2 %params = (
197 'material' => $material,
198 'material_type' => 'map',
199 );
200  
201 # Music.
202 18 ▶ } elsif (any { $self->{'leader'}->type eq $_ } qw(c d i j)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
203 2 my %mat_params = (
204 'form_of_composition' => substr($field_008, 18, 2),
205 'format_of_music' => substr($field_008, 20, 1),
206 'music_parts' => substr($field_008, 21, 1),
207 'target_audience' => substr($field_008, 22, 1),
208 'form_of_item' => substr($field_008, 23, 1),
209 'accompanying_matter' => substr($field_008, 24, 6),
210 'literary_text_for_sound_recordings' => substr($field_008, 30, 2),
211 'transposition_and_arrangement' => substr($field_008, 33, 1),
212  
213 'raw' => substr($field_008, 18, 17),
214 );
215 2 ▶ $Data::MARC::Field008::Music::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 2 2
216 2 my $material = Data::MARC::Field008::Music->new(%mat_params);
217 2 %params = (
218 'material' => $material,
219 'material_type' => 'music',
220 );
221  
222 # Continuing Resources
223 ▶ } elsif ($self->{'leader'}->type eq 'a'
Condition66%2/3
$self->{"leader"}->type eq "a" and &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "b", "i", "s")
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"leader"}->type eq "a" and &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "b", "i", "s")
$self->{"leader"}->type eq "a" &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "b", "i", "s")
Truth table66%2/3
A and B
A= $self->{"leader"}->type eq "a"B= &any(sub { $self->{"leader"}->bibliographic_level eq $_; } , "b", "i", "s")
ABresult
0X0
100
111
224 6 ▶ && (any { $self->{'leader'}->bibliographic_level eq $_ } qw(b i s))) {
Subroutine __ANON__: called CC=1 SCAR=0.0
225  
226 2 my %mat_params = (
227 'frequency' => substr($field_008, 18, 1),
228 'regularity' => substr($field_008, 19, 1),
229 'type_of_continuing_resource' => substr($field_008, 21, 1),
230 'form_of_original_item' => substr($field_008, 22, 1),
231 'form_of_item' => substr($field_008, 23, 1),
232 'nature_of_entire_work' => substr($field_008, 24, 1),
233 'nature_of_content' => substr($field_008, 25, 3),
234 'government_publication' => substr($field_008, 28, 1),
235 'conference_publication' => substr($field_008, 29, 1),
236 'original_alphabet_or_script_of_title' => substr($field_008, 33, 1),
237 'entry_convention' => substr($field_008, 34, 1),
238  
239 'raw' => substr($field_008, 18, 17),
240 );
241 2 ▶ $Data::MARC::Field008::ContinuingResource::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 2 2
242 2 my $material = Data::MARC::Field008::ContinuingResource->new(%mat_params);
243 2 %params = (
244 'material' => $material,
245 'material_type' => 'continuing_resource',
246 );
247  
248 # Visual Materials
249 4 ▶ } elsif (any { $self->{'leader'}->type eq $_ } qw(g k o r)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
250 2 my %mat_params = (
251 'running_time_for_motion_pictures_and_videorecordings' => substr($field_008, 18, 3),
252 'target_audience' => substr($field_008, 22, 1),
253 'government_publication' => substr($field_008, 28, 1),
254 'form_of_item' => substr($field_008, 29, 1),
255 'type_of_visual_material' => substr($field_008, 33, 1),
256 'technique' => substr($field_008, 34, 1),
257  
258 'raw' => substr($field_008, 18, 17),
259 );
260 2 ▶ $Data::MARC::Field008::VisualMaterial::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 2 2
261 2 my $material = Data::MARC::Field008::VisualMaterial->new(%mat_params);
262 2 %params = (
263 'material' => $material,
264 'material_type' => 'visual_material',
265 );
266  
267 # Mixed Materials
268 } elsif ($self->{'leader'}->type eq 'p') {
269 0 my %mat_params = (
270 'form_of_item' => substr($field_008, 23, 1),
271  
272 'raw' => substr($field_008, 18, 17),
273 );
274 0 ▶ $Data::MARC::Field008::MixedMaterial::STRICT = $self->{'ignore_data_errors'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ignore_data_errors'} ? : 0 0 0
275 0 my $material = Data::MARC::Field008::MixedMaterial->new(%mat_params);
276 0 %params = (
277 'material' => $material,
278 'material_type' => 'mixed_material',
279 );
280  
281 } else {
282 0 err "Unsupported 008 type.";
283 }
284  
285 14 return %params;
286 }
287  
288 6 ▶sub _serialize_different {
Subroutine _serialize_different: called CC=8 SCAR=20.9
289 6 my ($self, $material) = @_;
290  
291 6 my $ret;
292 6 ▶ if ($material->isa('Data::MARC::Field008::Book')) {
Branch: 7 branches
BranchTrueFalseTotal
if ($material->isa('Data::MARC::Field008::Book')) { } 1 5 6
elsif ($material->isa('Data::MARC::Field008::ComputerFile')) { } 1 4 5
elsif ($material->isa('Data::MARC::Field008::ContinuingResource')) { } 1 3 4
elsif ($material->isa('Data::MARC::Field008::Map')) { } 1 2 3
elsif ($material->isa('Data::MARC::Field008::MixedMaterial')) { } 0 2 2
elsif ($material->isa('Data::MARC::Field008::Music')) { } 1 1 2
elsif ($material->isa('Data::MARC::Field008::VisualMaterial')) { } 1 0 1
293 1 $ret = $material->illustrations.
294 $material->target_audience.
295 $material->form_of_item.
296 $material->nature_of_content.
297 $material->government_publication.
298 $material->conference_publication.
299 $material->festschrift.
300 $material->index.
301 ' '.
302 $material->literary_form.
303 $material->biography;
304  
305 } elsif ($material->isa('Data::MARC::Field008::ComputerFile')) {
306 1 $ret = (' ' x 4).
307 $material->target_audience.
308 $material->form_of_item.
309 (' ' x 2).
310 $material->type_of_computer_file.
311 ' '.
312 $material->government_publication.
313 (' ' x 6);
314 } elsif ($material->isa('Data::MARC::Field008::ContinuingResource')) {
315 1 $ret = $material->frequency.
316 $material->regularity.
317 ' '.
318 $material->type_of_continuing_resource.
319 $material->form_of_original_item.
320 $material->form_of_item.
321 $material->nature_of_entire_work.
322 $material->nature_of_content.
323 $material->government_publication.
324 $material->conference_publication.
325 (' ' x 3).
326 $material->original_alphabet_or_script_of_title.
327 $material->entry_convention;
328 } elsif ($material->isa('Data::MARC::Field008::Map')) {
329 1 $ret = $material->relief.
330 $material->projection.
331 ' '.
332 $material->type_of_cartographic_material.
333 (' ' x 2).
334 $material->government_publication.
335 $material->form_of_item.
336 ' '.
337 $material->index.
338 ' '.
339 $material->special_format_characteristics;
340 } elsif ($material->isa('Data::MARC::Field008::MixedMaterial')) {
341 0 $ret = (' ' x 5).
342 $material->form_of_item.
343 (' ' x 10);
344 } elsif ($material->isa('Data::MARC::Field008::Music')) {
345 1 $ret = $material->form_of_composition.
346 $material->format_of_music.
347 $material->music_parts.
348 $material->target_audience.
349 $material->form_of_item.
350 $material->accompanying_matter.
351 $material->literary_text_for_sound_recordings.
352 ' '.
353 $material->transposition_and_arrangement.
354 ' ';
355 } elsif ($material->isa('Data::MARC::Field008::VisualMaterial')) {
356 1 $ret = $material->running_time_for_motion_pictures_and_videorecordings.
357 ' '.
358 $material->target_audience.
359 (' ' x 5).
360 $material->government_publication.
361 $material->form_of_item.
362 (' ' x 3).
363 $material->type_of_visual_material.
364 $material->technique;
365 }
366  
367 6 return $ret;
368 }
369  
370 5 1;
371  
372 __END__
↑ Summary