Object.pm

filter: Statementstmt 98.7% 80 / 81 Branchbran 50.0% 1 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 94.0% 94 / 100 SCAR 13.9
CC
4
Cov
97%
BUILD
3.0
full_name
2.0
__ANON__
1.0
CRAP 4.0
« Object/ISBN.pm ↑ Summary Object/Publisher.pm »
1 package MARC::Convert::Wikidata::Object;
2  
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 31 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Mo qw(build default is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Mo::utils qw(check_array check_array_object check_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 31 Readonly::Array our @COVERS => qw(hardback paperback);
13  
14 31 our $VERSION = 0.01;
15  
16 31 has authors => (
17 default => [],
18 is => 'ro',
19 );
20  
21 31 has authors_of_afterword => (
22 default => [],
23 is => 'ro',
24 );
25  
26 31 has authors_of_introduction => (
27 default => [],
28 is => 'ro',
29 );
30  
31 31 has ccnb => (
32 is => 'ro',
33 );
34  
35 31 has compilers => (
36 is => 'ro',
37 );
38  
39 31 has cover => (
40 is => 'ro',
41 );
42  
43 31 has directors => (
44 default => [],
45 is => 'ro',
46 );
47  
48 31 has dml => (
49 is => 'ro',
50 );
51  
52 31 has edition_number => (
53 is => 'ro',
54 );
55  
56 31 has editors => (
57 default => [],
58 is => 'ro',
59 );
60  
61 31 has end_time => (
62 is => 'ro',
63 );
64  
65 31 has illustrators => (
66 default => [],
67 is => 'ro',
68 );
69  
70 31 has isbns => (
71 default => [],
72 is => 'ro',
73 );
74  
75 31 has issn => (
76 is => 'ro',
77 );
78  
79 31 has languages => (
80 default => [],
81 is => 'ro',
82 );
83  
84 31 has krameriuses => (
85 default => [],
86 is => 'ro',
87 );
88  
89 31 has narrators => (
90 default => [],
91 is => 'ro',
92 );
93  
94 31 has number_of_pages => (
95 is => 'ro',
96 );
97  
98 31 has oclc => (
99 is => 'ro',
100 );
101  
102 31 has photographers => (
103 default => [],
104 is => 'ro',
105 );
106  
107 31 has publication_date => (
108 is => 'ro',
109 );
110  
111 31 has publishers => (
112 default => [],
113 is => 'ro',
114 );
115  
116 31 has series => (
117 default => [],
118 is => 'ro',
119 );
120  
121 31 has start_time => (
122 is => 'ro',
123 );
124  
125 31 has subtitles => (
126 default => [],
127 is => 'ro',
128 );
129  
130 31 has title => (
131 is => 'ro',
132 );
133  
134 31 has translators => (
135 default => [],
136 is => 'ro',
137 );
138  
139 sub full_name {
140 4 ▶ my $self = shift;
Subroutine full_name: called CC=2 SCAR=6.9
Pod documented
141  
142 4 my $full_name = $self->title;
143 4 foreach my $subtitle (@{$self->subtitles}) {
144 3 $full_name .= ': '.$subtitle;
145 }
146  
147 4 return $full_name;
148 }
149  
150 sub BUILD {
151 63 ▶ my $self = shift;
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
152  
153 # Check authors.
154 63 check_array_object($self, 'authors',
155 'MARC::Convert::Wikidata::Object::People', 'Author');
156  
157 # Check authors of introduction.
158 63 check_array_object($self, 'authors_of_afterword',
159 'MARC::Convert::Wikidata::Object::People', 'Author of afterword');
160  
161 # Check authors of introduction.
162 63 check_array_object($self, 'authors_of_introduction',
163 'MARC::Convert::Wikidata::Object::People', 'Author of introduction');
164  
165 # Check compilers.
166 63 check_array_object($self, 'compilers',
167 'MARC::Convert::Wikidata::Object::People', 'Compiler');
168  
169 63 ▶ if (defined $self->{'cover'} && none { $_ eq $self->{'cover'} } @COVERS) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cover"} and &none(sub { $_ eq $self->{"cover"}; } , @MARC::Convert::Wikidata::Object::COVERS)) 0 63 63
Condition66%2/3
defined $self->{"cover"} and &none(sub {
!ll&&!rl&&r
6210
MC/DC0%0/2
defined $self->{"cover"} and &none(sub { $_ eq $self->{"cover"}; } , @MARC::Convert::Wikidata::Object::COVERS)
defined $self->{"cover"} &none(sub { $_ eq $self->{"cover"}; } , @MARC::Convert::Wikidata::Object::COVERS)
Truth table66%2/3
A and B
A= defined $self->{"cover"}B= &none(sub { $_ eq $self->{"cover"}; } , @MARC::Convert::Wikidata::Object::COVERS)
ABresult
0X0
100
111
170 0 err "Book cover '".$self->{'cover'}."' doesn't exist.";
171 }
172  
173 # Check directors.
174 63 check_array_object($self, 'directors',
175 'MARC::Convert::Wikidata::Object::People', 'Director');
176  
177 # Check dml id
178 63 check_number($self, 'dml');
179  
180 # Check editors.
181 63 check_array_object($self, 'editors',
182 'MARC::Convert::Wikidata::Object::People', 'Editor');
183  
184 # Check end_time.
185 63 check_number($self, 'end_time');
186  
187 # Check illustrators.
188 63 check_array_object($self, 'illustrators',
189 'MARC::Convert::Wikidata::Object::People', 'Illustrator');
190  
191 # Check isbns.
192 63 check_array_object($self, 'isbns',
193 'MARC::Convert::Wikidata::Object::ISBN', 'ISBN');
194  
195 # Check languages.
196 63 check_array($self, 'languages');
197  
198 # Check Kramerius systems.
199 63 check_array_object($self, 'krameriuses',
200 'MARC::Convert::Wikidata::Object::Kramerius', 'Kramerius');
201  
202 # Check narrators.
203 63 check_array_object($self, 'narrators',
204 'MARC::Convert::Wikidata::Object::People', 'Narrator');
205  
206 # Check photographers.
207 63 check_array_object($self, 'photographers',
208 'MARC::Convert::Wikidata::Object::People', 'Photographers');
209  
210 # Check list of publishers.
211 63 check_array_object($self, 'publishers',
212 'MARC::Convert::Wikidata::Object::Publisher', 'Publisher');
213  
214 # Check series.
215 63 check_array_object($self, 'series',
216 'MARC::Convert::Wikidata::Object::Series', 'Book series');
217  
218 # Check start_time.
219 63 check_number($self, 'start_time');
220  
221 # Check series.
222 63 check_array($self, 'subtitles');
223  
224 # Check translators.
225 63 check_array_object($self, 'translators',
226 'MARC::Convert::Wikidata::Object::People', 'Translator');
227  
228 63 return;
229 }
230  
231 31 1;
232  
233 __END__
234  
235 =pod
236  
237 =encoding utf8
238  
239 =head1 NAME
240  
241 MARC::Convert::Wikidata::Object - Bibliographic Wikidata object defined by MARC record.
242  
243 =head1 SYNOPSIS
244  
245 use MARC::Convert::Wikidata::Object;
246  
247 my $obj = MARC::Convert::Wikidata::Object->new(%params);
248 my $authors_ar = $obj->authors;
249 my $authors_of_afterword_ar = $obj->authors_of_afterword;
250 my $authors_of_introduction_ar = $obj->authors_of_introduction;
251 my $ccnb = $obj->ccnb;
252 my $compilers = $obj->compilers;
253 my $cover = $obj->cover;
254 my $directors_ar = $obj->directors;
255 my $dml = $obj->dml;
256 my $edition_number = $obj->edition_number;
257 my $editors_ar = $obj->editors;
258 my $end_time = $obj->end_time;
259 my $full_name = $obj->full_name;
260 my $illustrators_ar = $obj->illustrators;
261 my $isbns_ar = $obj->isbns;
262 my $issn = $obj->issn;
263 my $kramerius_ar = $obj->krameriuses;
264 my $languages_ar = $obj->languages;
265 my $narrators_ar = $obj->narrators;
266 my $number_of_pages = $obj->number_of_pages;
267 my $oclc = $obj->oclc;
268 my $photographers_ar = $obj->photographers;
269 my $publication_date = $obj->publication_date;
270 my $publishers_ar = $obj->publishers;
271 my $series_ar = $obj->series;
272 my $start_time = $obj->start_time;
273 my $subtitles_ar = $obj->subtitles;
274 my $title = $obj->title;
275 my $translators_ar = $obj->translators;
276  
277 =head1 METHODS
278  
279 =head2 C<new>
280  
281 my $obj = MARC::Convert::Wikidata::Object->new(%params);
282  
283 Constructor.
284  
285 Returns instance of object.
286  
287 =over 8
288  
289 =item * C<authors>
290  
291 List of authors.
292 Reference to array with MARC::Convert::Wikidata::Object::People instances.
293  
294 Default value is reference to blank array.
295  
296 =item * C<authors_of_afterword>
297  
298 List of authors of afterword.
299 Reference to array with MARC::Convert::Wikidata::Object::People instances.
300  
301 Default value is reference to blank array.
302  
303 =item * C<authors_of_introduction>
304  
305 List of authors of introduction.
306 Reference to array with MARC::Convert::Wikidata::Object::People instances.
307  
308 Default value is reference to blank array.
309  
310 =item * C<ccnb>
311  
312 ČČNB (Česká národní bibliografie) id.
313  
314 Default value is undef.
315  
316 =item * C<compilers>
317  
318 List of compilers.
319 Reference to array with MARC::Convert::Wikidata::Object::People instances.
320  
321 Default value is reference to blank array.
322  
323 =item * C<cover>
324  
325 Book cover.
326 Possible values:
327 * hardback
328 * paperback
329  
330 Default value is undef.
331  
332 =item * C<directors>
333  
334 List of directors.
335 Reference to array with MARC::Convert::Wikidata::Object::People instances.
336  
337 Default value is reference to blank array.
338  
339 =item * C<dml>
340  
341 DML id.
342  
343 Default value is undef.
344  
345 =item * C<edition_number>
346  
347 Edition number.
348  
349 Default value is undef.
350  
351 =item * C<editors>
352  
353 List of editors.
354 Reference to array with MARC::Convert::Wikidata::Object::People instances.
355  
356 Default value is reference to blank array.
357  
358 =item * C<end_time>
359  
360 End time.
361  
362 Default value is undef.
363  
364 =item * C<illustrators>
365  
366 List of illustrators.
367 Reference to array with MARC::Convert::Wikidata::Object::People instances.
368  
369 Default value is reference to blank array.
370  
371 =item * C<isbns>
372  
373 List of ISBNs.
374 Reference to array with MARC::Convert::Wikidata::Object::ISBN instances.
375  
376 Default value is reference to blank array.
377  
378 =item * C<issn>
379  
380 ISSN number.
381  
382 Default value is undef.
383  
384 =item * C<krameriuses>
385  
386 List of Kramerius systems with digitized scan.
387 Reference to array with MARC::Convert::Wikidata::Object::Kramerius instances.
388  
389 Default value is reference to blank array.
390  
391 =item * C<languages>
392  
393 List of languages of book edition (TODO Format)
394  
395 Default value is reference to blank array.
396  
397 =item * C<narrators>
398  
399 List of narrators.
400 Reference to array with MARC::Convert::Wikidata::Object::People instances.
401  
402 Default value is reference to blank array.
403  
404 =item * C<number_of_pages>
405  
406 Number of pages.
407  
408 Default value is undef.
409  
410 =item * C<oclc>
411  
412 OCLC control number.
413  
414 Default value is undef.
415  
416 =item * C<photographers>
417  
418 List of photographers.
419 Reference to array with MARC::Convert::Wikidata::Object::People instances.
420  
421 Default value is reference to blank array.
422  
423 =item * C<publication_date>
424  
425 Publication date.
426  
427 Default value is undef.
428  
429 =item * C<publishers>
430  
431 List of Publishers.
432 Reference to array with MARC::Convert::Wikidata::Object::Publisher instances.
433  
434 Default value is [].
435  
436 =item * C<series>
437  
438 List of book series.
439 Reference to array with MARC::Convert::Wikidata::Object::Series instances.
440  
441 Default value is [].
442  
443 =item * C<start_time>
444  
445 Start time.
446  
447 Default value is undef.
448  
449 =item * C<subtitles>
450  
451 List of subtitles.
452 Reference to array with strings.
453  
454 Default value is [].
455  
456 =item * C<title>
457  
458 Title of book edition.
459  
460 Default value is undef.
461  
462 =item * C<translators>
463  
464 List of translators.
465 Reference to array with MARC::Convert::Wikidata::Object::People instances.
466  
467 Default value is reference to blank array.
468  
469 =back
470  
471 =head2 C<authors>
472  
473 my $authors_ar = $obj->authors;
474  
475 Get reference to array with author objects.
476  
477 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
478  
479 =head2 C<authors_of_afterword>
480  
481 my $authors_of_afterword_ar = $obj->authors_of_afterword;
482  
483 Get reference to array with author of afterword objects.
484  
485 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
486  
487 =head2 C<authors_of_introduction>
488  
489 my $authors_of_introduction_ar = $obj->authors_of_introduction;
490  
491 Get reference to array with author of introduction objects.
492  
493 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
494  
495 =head2 C<ccnb>
496  
497 my $ccnb = $obj->ccnb;
498  
499 Get ČČNB (Česká národní bibliografie) ID.
500  
501 Returns string.
502  
503 =head2 C<compilers>
504  
505 my $compilers_ar = $obj->compilers;
506  
507 Get reference to array with compiler objects.
508  
509 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
510  
511 =head2 C<cover>
512  
513 my $cover = $obj->cover;
514  
515 Get book cover.
516  
517 Returns string (hardback or paperback).
518  
519 =head2 C<directors>
520  
521 my $directors_ar = $obj->directors;
522  
523 Get list of directors.
524  
525 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
526  
527 =head2 C<dml>
528  
529 my $dml = $obj->dml;
530  
531 Get DML id.
532  
533 Returns number.
534  
535 =head2 C<edition_number>
536  
537 my $edition_number = $obj->edition_number;
538  
539 Get edition number.
540  
541 Returns number.
542  
543 =head2 C<editors>
544  
545 my $editors_ar = $obj->editors;
546  
547 TODO
548  
549 =head2 C<end_time>
550  
551 my $end_time = $obj->end_time;
552  
553 Get end time.
554  
555 Returns number.
556  
557 =head2 C<full_name>
558  
559 my $full_name = $obj->full_name;
560  
561 Get full name of edition in format '__TITLE__: __SUBTITLE__'.
562  
563 Returns string.
564  
565 =head2 C<illustrators>
566  
567 my $illustrators_ar = $obj->illustrators;
568  
569 TODO
570  
571 =head2 C<isbns>
572  
573 my $isbns_ar = $obj->isbns;
574  
575 TODO
576  
577 =head2 C<issn>
578  
579 my $issn = $obj->issn;
580  
581 Get ISSN number.
582  
583 Returns string.
584  
585 =head2 c<krameriuses>
586  
587 my $kramerius_ar = $obj->krameriuses;
588  
589 Get reference to array with Kramerius item objects.
590  
591 Returns reference to array of MARC::Convert::Wikidata::Object::Kramerius instances.
592  
593 =head2 C<languages>
594  
595 my $languages_ar = $obj->languages;
596  
597 TODO
598  
599 =head2 C<narrators>
600  
601 my $narrators_ar = $obj->narrators;
602  
603 Get list of narrators.
604  
605 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
606  
607 =head2 C<number_of_pages>
608  
609 my $number_of_pages = $obj->number_of_pages;
610  
611 TODO
612  
613 =head2 C<oclc>
614  
615 my $oclc = $obj->oclc;
616  
617 Get OCLC control number.
618  
619 Returns string.
620  
621 =head2 C<photographers>
622  
623 my $photographers_ar = $obj->photographers;
624  
625 Get reference to array with photographers objects.
626  
627 Returns reference to array of MARC::Convert::Wikidata::Object::People instances.
628  
629 =head2 C<publication_date>
630  
631 my $publication_date = $obj->publication_date;
632  
633 TODO
634  
635 =head2 C<publishers>
636  
637 my $publishers_ar = $obj->publishers;
638  
639 TODO
640  
641 Returns reference to array of MARC::Convert::Wikidata::Object::Publisher instances.
642  
643 =head2 C<series>
644  
645 my $series_ar = $obj->series;
646  
647 Get reference to array with Serie item objects.
648  
649 Returns reference to array of MARC::Convert::Wikidata::Object::Series instances.
650  
651 =head2 C<start_time>
652  
653 my $start_time = $obj->start_time;
654  
655 Get start time.
656  
657 Returns number.
658  
659 =head2 C<subtitle>
660  
661 my $subtitles_ar = $obj->subtitles;
662  
663 Get reference to array with subtitles.
664  
665 Returns reference to array of strings.
666  
667 =head2 C<title>
668  
669 my $title = $obj->title;
670  
671 TODO
672  
673 =head2 C<translators>
674  
675 my $translators_ar = $obj->translators;
676  
677 TODO
678  
679 =head1 ERRORS
680  
681 new():
682 From Mo::utils::check_array_object():
683 Author isn't 'MARC::Convert::Wikidata::Object::People' object.
684 Author of afterword isn't 'MARC::Convert::Wikidata::Object::People' object.
685 Author of introduction isn't 'MARC::Convert::Wikidata::Object::People' object.
686 Book series isn't 'MARC::Convert::Wikidata::Object::Series' object.
687 Book cover '%s' doesn't exist.
688 Compiler isn't 'MARC::Convert::Wikidata::Object::People' object.
689 Director isn't 'MARC::Convert::Wikidata::Object::People' object.
690 Editor isn't 'MARC::Convert::Wikidata::Object::People' object.
691 Illustrator isn't 'MARC::Convert::Wikidata::Object::People' object.
692 Narrator isn't 'MARC::Convert::Wikidata::Object::People' object.
693 Parameter 'authors' must be a array.
694 Parameter 'authors_of_afterword' must be a array.
695 Parameter 'authors_of_introduction' must be a array.
696 Parameter 'compilers' must be a array.
697 Parameter 'directors' must be a array.
698 Parameter 'editors' must be a array.
699 Parameter 'end_time' must be a number.
700 Parameter 'illustrators' must be a array.
701 Parameter 'languages' must be a array.
702 Parameter 'narrators' must be a array.
703 Parameter 'publishers' must be a array.
704 Parameter 'series' must be a array.
705 Parameter 'start_time' must be a number.
706 Parameter 'translators' must be a array.
707 Publisher isn't 'MARC::Convert::Wikidata::Object::Publisher' object.
708 Translator isn't 'MARC::Convert::Wikidata::Object::People' object.
709  
710 From Mo::utils::check_number():
711 Parameter '%s' must a number.
712 Value: %s
713  
714 =head1 EXAMPLE1
715  
716 =for comment filename=create_and_dump_wikidata_object.pl
717  
718 use strict;
719 use warnings;
720  
721 use Data::Printer;
722 use MARC::Convert::Wikidata::Object;
723 use MARC::Convert::Wikidata::Object::ISBN;
724 use MARC::Convert::Wikidata::Object::People;
725 use MARC::Convert::Wikidata::Object::Publisher;
726 use Unicode::UTF8 qw(decode_utf8);
727
728 my $aut = MARC::Convert::Wikidata::Object::People->new(
729 'date_of_birth' => '1952-12-08',
730 'name' => decode_utf8('Jiří'),
731 'nkcr_aut' => 'jn20000401266',
732 'surname' => 'Jurok',
733 );
734  
735 my $publisher = MARC::Convert::Wikidata::Object::Publisher->new(
736 'name' => decode_utf8('Město Příbor'),
737 'place' => decode_utf8('Příbor'),
738 );
739  
740 my $isbn = MARC::Convert::Wikidata::Object::ISBN->new(
741 'isbn' => '80-238-9541-9',
742 'publisher' => $publisher,
743 );
744  
745 my $obj = MARC::Convert::Wikidata::Object->new(
746 'authors' => [$aut],
747 'ccnb' => 'cnb001188266',
748 'date_of_publication' => 2002,
749 'edition_number' => 2,
750 'isbns' => [$isbn],
751 'number_of_pages' => 414,
752 'publishers' => [$publisher],
753 );
754
755 p $obj;
756  
757 # Output:
758 # MARC::Convert::Wikidata::Object {
759 # Parents Mo::Object
760 # public methods (11) : BUILD, can (UNIVERSAL), DOES (UNIVERSAL), err (Error::Pure), full_name, check_array (Mo::utils), check_array_object (Mo::utils), isa (UNIVERSAL), none (List::MoreUtils::XS), Readonly (Readonly), VERSION (UNIVERSAL)
761 # private methods (1) : __ANON__ (Mo::is)
762 # internals: {
763 # authors [
764 # [0] MARC::Convert::Wikidata::Object::People
765 # ],
766 # authors_of_introduction [],
767 # ccnb "cnb001188266",
768 # compilers [],
769 # date_of_publication 2002,
770 # edition_number 2,
771 # editors [],
772 # illustrators [],
773 # isbns [
774 # [0] MARC::Convert::Wikidata::Object::ISBN
775 # ],
776 # krameriuses [],
777 # number_of_pages 414,
778 # publishers [
779 # [0] MARC::Convert::Wikidata::Object::Publisher
780 # ],
781 # series [],
782 # translators []
783 # }
784 # }
785  
786 =head1 DEPENDENCIES
787  
788 L<Error::Pure>,
789 L<List::MoreUtils>,
790 L<Mo>,
791 L<Mo::utils>,
792 L<Readonly>.
793  
794 =head1 SEE ALSO
795  
796 =over
797  
798 =item L<MARC::Convert::Wikidata>
799  
800 Conversion class between MARC record and Wikidata object.
801  
802 =back
803  
804 =head1 REPOSITORY
805  
806 L<https://github.com/michal-josef-spacek/MARC-Convert-Wikidata-Object>
807  
808 =head1 AUTHOR
809  
810 Michal Josef Špaček L<mailto:skim@cpan.org>
811  
812 L<http://skim.cz>
813  
814 =head1 LICENSE AND COPYRIGHT
815  
816 © Michal Josef Špaček 2021-2023
817  
818 BSD 2-Clause License
819  
820 =head1 VERSION
821  
822 0.01
823  
824 =cut
« Object/ISBN.pm ↑ Summary Object/Publisher.pm »