File Coverage

blib/lib/Data/MARC/Field008.pm
Criterion Covered Total %
statement 45 53 84.9
branch 3 20 15.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 1 0.0
total 58 86 67.4


line stmt bran cond sub pod time code
1             package Data::MARC::Field008;
2              
3 3     3   202423 use strict;
  3         6  
  3         112  
4 3     3   15 use warnings;
  3         14  
  3         221  
5              
6 3         88 use Data::MARC::Field008::Utils qw(check_cataloging_source check_date
7 3     3   1929 check_modified_record check_type_of_date);
  3         11  
8 3     3   686 use Error::Pure qw(err);
  3         5  
  3         144  
9 3     3   17 use Error::Pure::Utils qw(err_get);
  3         7  
  3         62  
10 3     3   2091 use Mo qw(build is);
  3         1999  
  3         21  
11 3     3   6350 use Mo::utils 0.22 qw(check_isa check_length_fix check_number check_required check_strings);
  3         9617  
  3         73  
12 3     3   442 use Readonly;
  3         5  
  3         1621  
13              
14             Readonly::Array our @MATERIAL_TYPES => qw(book computer_file continuing_resource
15             map mixed_material music visual_material);
16              
17             our $VERSION = 0.04;
18              
19             has cataloging_source => (
20             is => 'ro',
21             );
22              
23             has date_entered_on_file => (
24             is => 'ro',
25             );
26              
27             has date1 => (
28             is => 'ro',
29             );
30              
31             has date2 => (
32             is => 'ro',
33             );
34              
35             has language => (
36             is => 'ro',
37             );
38              
39             has material => (
40             is => 'ro',
41             );
42              
43             has material_type => (
44             is => 'ro',
45             );
46              
47             has modified_record => (
48             is => 'ro',
49             );
50              
51             has place_of_publication => (
52             is => 'ro',
53             );
54              
55             has raw => (
56             is => 'ro',
57             );
58              
59             has type_of_date => (
60             is => 'ro',
61             );
62              
63             sub BUILD {
64 5     5 0 8238 my $self = shift;
65              
66             # Check 'cataloging_source'.
67 5         26 check_cataloging_source($self, 'cataloging_source');
68              
69             # Check 'date_entered_on_file'.
70 5         19 check_required($self, 'date_entered_on_file');
71 5         51 check_length_fix($self, 'date_entered_on_file', 6);
72 5 50 33     114 if (defined $self->{'date_entered_on_file'} && $self->{'date_entered_on_file'} ne ' ') {
73 0         0 check_number($self, 'date_entered_on_file');
74             }
75              
76             # Check 'date1'.
77 5         18 check_date($self, 'date1');
78              
79             # Check 'date2'.
80 3         10 check_date($self, 'date2');
81              
82             # Check 'language'.
83 3         10 check_required($self, 'language');
84 3         27 check_length_fix($self, 'language', 3);
85              
86             # Check 'material_type'.
87 3         42 check_required($self, 'material_type');
88 3         25 check_strings($self, 'material_type', \@MATERIAL_TYPES);
89              
90             # Check 'material'.
91 3 50       137 if ($self->material_type eq 'book') {
    0          
    0          
    0          
    0          
    0          
    0          
92 3         37 check_isa($self, 'material', 'Data::MARC::Field008::Book');
93             } elsif ($self->material_type eq 'computer_file') {
94 0         0 check_isa($self, 'material', 'Data::MARC::Field008::ComputerFile');
95             } elsif ($self->material_type eq 'continuing_resource') {
96 0         0 check_isa($self, 'material', 'Data::MARC::Field008::ContinuingResource');
97             } elsif ($self->material_type eq 'map') {
98 0         0 check_isa($self, 'material', 'Data::MARC::Field008::Map');
99             } elsif ($self->material_type eq 'mixed_material') {
100 0         0 check_isa($self, 'material', 'Data::MARC::Field008::MixedMaterial');
101             } elsif ($self->material_type eq 'music') {
102 0         0 check_isa($self, 'material', 'Data::MARC::Field008::Music');
103             } elsif ($self->material_type eq 'visual_material') {
104 0         0 check_isa($self, 'material', 'Data::MARC::Field008::VisualMaterial');
105             }
106              
107             # Check 'modified_record'
108 3         108 check_modified_record($self, 'modified_record');
109              
110             # Check place_of_publication.
111 3         10 check_required($self, 'place_of_publication');
112 3         26 check_length_fix($self, 'place_of_publication', 3);
113              
114             # Check 'raw'
115 3         42 check_length_fix($self, 'raw', 40);
116              
117             # Check 'type_of_date'.
118 3         34 check_type_of_date($self, 'type_of_date');
119              
120             # Explicit error in case of not strict mode.
121 3         11 my @errors = err_get();
122 3 50       31 if (@errors) {
123             err "Field 008 isn't valid.",
124 0 0       0 defined $self->{'raw'} ? ('Raw string', $self->{'raw'}) : (),
125             ;
126             }
127              
128 3         10 return;
129             }
130              
131             1;
132              
133             __END__
134              
135             =pod
136              
137             =encoding utf8
138              
139             =head1 NAME
140              
141             Data::MARC::Field008 - Data object for MARC field 008.
142              
143             =head1 SYNOPSIS
144              
145             use Data::MARC::Field008;
146              
147             my $obj = Data::MARC::Field008->new(%params);
148             my $cataloging_source = $obj->cataloging_source;
149             my $date_entered_on_file = $obj->date_entered_on_file;
150             my $date1 = $obj->date1;
151             my $date2 = $obj->date2;
152             my $language = $obj->language;
153             my $material = $obj->material;
154             my $material_type = $obj->material_type;
155             my $modified_record = $obj->modified_record;
156             my $place_of_publication = $obj->place_of_publication;
157             my $raw = $obj->raw;
158             my $type_of_date = $obj->type_of_date;
159              
160             =head1 METHODS
161              
162             =head2 C<new>
163              
164             my $obj = Data::MARC::Field008->new(%params);
165              
166             Constructor.
167              
168             =over 8
169              
170             =item * C<cataloging_source>
171              
172             Cataloging source character. The length of the string is 1 character.
173             Possible characters are ' ', 'c', 'd', 'u' or '|'.
174              
175             It's required.
176              
177             Default value is undef.
178              
179             =item * C<date_entered_on_file>
180              
181             Date entered on file.
182              
183             It's required.
184              
185             Default values is undef.
186              
187             =item * C<date1>
188              
189             Date 1.
190              
191             It's required.
192              
193             Default value is undef.
194              
195             =item * C<date2>
196              
197             Date 2.
198              
199             It's required.
200              
201             Default value is undef.
202              
203             =item * C<language>
204              
205             Language. The length of the string is 3 characters.
206             Possible values are ' ', 'zxx', 'mul', 'sgn', 'und', '|||' or three character
207             language code.
208              
209             It's required.
210              
211             Default value is undef.
212              
213             =item * C<material>
214              
215             Material data object.
216              
217             Possible objects are:
218              
219             =over
220              
221             =item * L<Data::MARC::Field008::Book>
222              
223             =item * L<Data::MARC::Field008::ComputerFile>
224              
225             =item * L<Data::MARC::Field008::ContinuingResource>
226              
227             =item * L<Data::MARC::Field008::Map>
228              
229             =item * L<Data::MARC::Field008::MixedMaterial>
230              
231             =item * L<Data::MARC::Field008::Music>
232              
233             =item * L<Data::MARC::Field008::VisualMaterial>
234              
235             =back
236              
237             It's required.
238              
239             Default value is undef.
240              
241             =item * C<material_type>
242              
243             Material type.
244              
245             Possible values are:
246              
247             =over
248              
249             =item * book
250              
251             =item * computer_file
252              
253             =item * continuing_resource
254              
255             =item * map
256              
257             =item * mixed_material
258              
259             =item * music
260              
261             =item * visual_material
262              
263             =back
264              
265             It's required.
266              
267             Default value is undef.
268              
269             =item * C<modified_record>
270              
271             Modified record. The length of the string is 1 character.
272             Possible characters are ' ', 'd', 'o', 'r', 's', 'x' or '|'.
273              
274             It's required.
275              
276             Default value is undef.
277              
278             =item * C<place_of_publication>
279              
280             Place of publication, production, or execution. The length of the string are 3
281             characters.
282             Possible values are 'xx ', 'vp ', or two/three alphabetic codes.
283              
284             It's required.
285              
286             Default value is undef.
287              
288             =item * C<raw>
289              
290             Raw string of field 008. The length of the string is 40 characters.
291              
292             It's optional.
293              
294             Default value is undef.
295              
296             =item * C<type_of_date>
297              
298             The type of date or the publication status. The length of the string is 1
299             character.
300             Possible characters are 'b', 'c', 'd', 'e', 'i', 'k', 'm', 'n', 'p', 'q', 'r',
301             's', 't', 'u' or '|'.
302              
303             It's required.
304              
305             Default value is undef.
306              
307             =back
308              
309             Returns instance of object.
310              
311             =head2 C<cataloging_source>
312              
313             my $cataloging_source = $obj->cataloging_source;
314              
315             Get cataloging source flag.
316              
317             Returns character.
318              
319             =head2 C<date_entered_on_file>
320              
321             my $date_entered_on_file = $obj->date_entered_on_file;
322              
323             Get date entered on file.
324              
325             Returns string.
326              
327             =head2 C<date1>
328              
329             my $date1 = $obj->date1;
330              
331             Get date #1 string.
332              
333             Returns string.
334              
335             =head2 C<date2>
336              
337             my $date2 = $obj->date2;
338              
339             Get date #2 string.
340              
341             Returns string.
342              
343             =head2 C<language>
344              
345             my $language = $obj->language;
346              
347             Get language.
348              
349             Returns string.
350              
351             =head2 C<material>
352              
353             my $material = $obj->material;
354              
355             Get material object.
356              
357             Returns Material object.
358              
359             =head2 C<material_type>
360              
361             my $material_type = $obj->material_type;
362              
363             Get material type.
364              
365             Returns string.
366              
367             =head2 C<modified_record>
368              
369             my $modified_record = $obj->modified_record;
370              
371             Get modified record.
372              
373             Returns string.
374              
375             =head2 C<place_of_publication>
376              
377             my $place_of_publication = $obj->place_of_publication;
378              
379             Get place of publication.
380              
381             Returns string.
382              
383             =head2 C<raw>
384              
385             my $raw = $obj->raw;
386              
387             Get raw string of field 008.
388              
389             Returns string.
390              
391             =head2 C<type_of_date>
392              
393             my $type_of_date = $obj->type_of_date;
394              
395             Get type of date.
396              
397             Returns string.
398              
399             =head1 ERRORS
400              
401             new():
402             Field 008 isn't valid.
403             Raw string: %s
404             From Mo::utils::check_isa():
405             Parameter 'material' must be a 'Data::MARC::Field008::Book' object.
406             Value: %s
407             Reference: %s
408             Parameter 'material' must be a 'Data::MARC::Field008::ComputerFile' object.
409             Value: %s
410             Reference: %s
411             Parameter 'material' must be a 'Data::MARC::Field008::ContinuingResource' object.
412             Value: %s
413             Reference: %s
414             Parameter 'material' must be a 'Data::MARC::Field008::Map' object.
415             Value: %s
416             Reference: %s
417             Parameter 'material' must be a 'Data::MARC::Field008::MixedMaterial' object.
418             Value: %s
419             Reference: %s
420             Parameter 'material' must be a 'Data::MARC::Field008::Music' object.
421             Value: %s
422             Reference: %s
423             Parameter 'material' must be a 'Data::MARC::Field008::VisualMaterial' object.
424             Value: %s
425             Reference: %s
426             From Mo::utils::check_length_fix():
427             Parameter 'date_entered_on_file' has length different than '6'.
428             Value: %s
429             Parameter 'language' has length different than '3'.
430             Value: %s
431             Parameter 'place_of_publication' has length different than '3'.
432             Value: %s
433             Parameter 'raw' has length different than '40'.
434             Value: %s
435             From Mo::utils::check_number():
436             Parameter 'date_entered_on_file' must be a number.
437             Value: %s
438             From Mo::utils::check_required():
439             Parameter 'date_entered_on_file' is required.
440             Parameter 'language' is required.
441             Parameter 'material_type' is required.
442             Parameter 'place_of_publication' is required.
443             From Mo::utils::check_strings():
444             Parameter 'material_type' must be one of defined strings.
445             String: %s
446             Possible strings: %s
447             Parameter 'material_type' must have right string definition.
448             Parameter 'material_type' must have strings definition.
449             From Data::MARC::Field008::Utils::check_cataloging_source():
450             Parameter 'cataloging_source' has bad value.
451             Value: %s
452             Parameter 'cataloging_source' is required.
453             Parameter 'cataloging_source' length is bad.
454             Length: %s
455             Value: %s
456             Expected length: 1
457             Parameter 'cataloging_source' must be a scalar value.
458             Reference: %s
459             From Data::MARC::Field008::Utils::check_date():
460             Parameter 'date1' has bad value.
461             Value: %s
462             Parameter 'date2' has bad value.
463             Value: %s
464             Parameter 'date1' has value with pipe character.
465             Value: %s
466             Parameter 'date2' has value with pipe character.
467             Value: %s
468             Parameter 'date1' has value with space character.
469             Value: %s
470             Parameter 'date2' has value with space character.
471             Value: %s
472             Parameter 'date1' is required.
473             Parameter 'date2' is required.
474             Parameter 'date1' length is bad.
475             Length: %s
476             Value: %s
477             Expected length: 1
478             Parameter 'date2' length is bad.
479             Length: %s
480             Value: %s
481             Expected length: 1
482             Parameter 'date1' must be a scalar value.
483             Reference: %s
484             Parameter 'date2' must be a scalar value.
485             Reference: %s
486             From Data::MARC::Field008::Utils::check_modified_record():
487             Parameter 'modified_record' has bad value.
488             Value: %s
489             Parameter 'modified_record' is required.
490             Parameter 'modified_record' length is bad.
491             Length: %s
492             Value: %s
493             Expected length: 1
494             Parameter 'modified_record' must be a scalar value.
495             Reference: %s
496             From Data::MARC::Field008::Utils::check_type_of_date():
497             Parameter 'type_of_date' has bad value.
498             Value: %s
499             Parameter 'type_of_date' is required.
500             Parameter 'type_of_date' length is bad.
501             Length: %s
502             Value: %s
503             Expected length: 1
504             Parameter 'type_of_date' must be a scalar value.
505             Reference: %s
506              
507             =head1 EXAMPLE
508              
509             =for comment filename=create_and_dump_marc_field_008.pl
510              
511             use strict;
512             use warnings;
513              
514             use Data::Printer;
515             use Data::MARC::Field008;
516             use Data::MARC::Field008::Book;
517              
518             # cnb000000096
519             my $obj = Data::MARC::Field008->new(
520             'cataloging_source' => ' ',
521             'date_entered_on_file' => '830304',
522             'date1' => '1982',
523             'date2' => ' ',
524             'language' => 'cze',
525             'material' => Data::MARC::Field008::Book->new(
526             'biography' => ' ',
527             'conference_publication' => '0',
528             'festschrift' => '|',
529             'form_of_item' => ' ',
530             'government_publication' => 'u',
531             'illustrations' => 'a ',
532             'index' => '0',
533             'literary_form' => '|',
534             'nature_of_content' => ' ',
535             # 89012345678901234
536             'raw' => 'a u0|0 | ',
537             'target_audience' => ' ',
538             ),
539             'material_type' => 'book',
540             'modified_record' => ' ',
541             'place_of_publication' => 'xr ',
542             # 0123456789012345678901234567890123456789
543             'raw' => '830304s1982 xr a u0|0 | cze ',
544             'type_of_date' => 's',
545             );
546              
547             # Print out.
548             p $obj;
549              
550             # Output:
551             # Data::MARC::Field008 {
552             # parents: Mo::Object
553             # public methods (14):
554             # BUILD
555             # Data::MARC::Field008::Utils:
556             # check_cataloging_source, check_date, check_modified_record, check_type_of_date
557             # Error::Pure:
558             # err
559             # Error::Pure::Utils:
560             # err_get
561             # Mo::utils:
562             # check_isa, check_length_fix, check_number, check_regexp, check_required, check_strings
563             # Readonly:
564             # Readonly
565             # private methods (0)
566             # internals: {
567             # cataloging_source " ",
568             # date_entered_on_file 830304,
569             # date1 1982,
570             # date2 " ",
571             # language "cze",
572             # material Data::MARC::Field008::Book,
573             # material_type "book",
574             # modified_record " ",
575             # place_of_publication "xr ",
576             # raw "830304s1982 xr a u0|0 | cze " (dualvar: 830304),
577             # type_of_date "s"
578             # }
579             # }
580              
581             =head1 DEPENDENCIES
582              
583             L<Data::MARC::Field008::Utils>,
584             L<Error::Pure>
585             L<Error::Pure::Utils>
586             L<Mo>,
587             L<Mo::utils>,
588             L<Readonly>.
589              
590             =head1 REPOSITORY
591              
592             L<https://github.com/michal-josef-spacek/Data-MARC-Field008>
593              
594             =head1 AUTHOR
595              
596             Michal Josef Špaček L<mailto:skim@cpan.org>
597              
598             L<http://skim.cz>
599              
600             =head1 LICENSE AND COPYRIGHT
601              
602             © 2025 Michal Josef Špaček
603              
604             BSD 2-Clause License
605              
606             =head1 ACKNOWLEDGEMENTS
607              
608             Development of this software has been made possible by institutional support
609             for the long-term strategic development of the National Library of the Czech
610             Republic as a research organization provided by the Ministry of Culture of
611             the Czech Republic (DKRVO 2024–2028), Area 11: Linked Open Data.
612              
613             =head1 VERSION
614              
615             0.04
616              
617             =cut