Object/PublicationDate.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 6 / 6 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 98.8% 88 / 89 CC 6 SCAR 8.3
CC
6
Cov
100%
BUILD
4.0
_check_conflict
3.0
BEGIN
1.0
CRAP 2.3
« Object.pm ↑ Summary Object/People.pm »
1 package MARC::Convert::Wikidata::Object::PublicationDate;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Mo qw(build is);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Mo::utils 0.15 qw(check_bool check_strings);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Mo::utils::Date 0.02 qw(check_date);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 Readonly::Array our @SOURCING_CIRCUMSTANCES => qw(circa near presumably disputed);
13 11 Readonly::Array our @PRECISION => qw(day month year decade century millenium);
14  
15 11 our $VERSION = 0.15;
16  
17 11 has copyright => (
18 is => 'ro',
19 );
20  
21 11 has date => (
22 is => 'ro',
23 );
24  
25 11 has earliest_date => (
26 is => 'ro',
27 );
28  
29 11 has end_time => (
30 is => 'ro',
31 );
32  
33 11 has latest_date => (
34 is => 'ro',
35 );
36  
37 11 has precision => (
38 is => 'ro',
39 );
40  
41 11 has sourcing_circumstances => (
42 is => 'ro',
43 );
44  
45 11 has start_time => (
46 is => 'ro',
47 );
48  
49 sub BUILD {
50 35 ▶ my $self = shift;
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
51  
52 # Conflicts.
53 35 _check_conflict($self, 'date', 'earliest_date');
54 34 _check_conflict($self, 'date', 'latest_date');
55 33 _check_conflict($self, 'date', 'start_time');
56 32 _check_conflict($self, 'date', 'end_time');
57 31 _check_conflict($self, 'earliest_date', 'start_time');
58 30 _check_conflict($self, 'earliest_date', 'end_time');
59 29 _check_conflict($self, 'latest_date', 'start_time');
60 28 _check_conflict($self, 'latest_date', 'end_time');
61 27 _check_conflict($self, 'precision', 'start_time');
62 26 _check_conflict($self, 'precision', 'end_time');
63 25 _check_conflict($self, 'precision', 'earliest_date');
64 24 _check_conflict($self, 'precision', 'latest_date');
65  
66 # Check 'copyright'.
67 23 ▶ if (! defined $self->{'copyright'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"copyright"}) 20 3 23
68 20 $self->{'copyright'} = 0;
69 }
70 23 check_bool($self, 'copyright');
71  
72 # Check 'date'.
73 22 check_date($self, 'date');
74  
75 # Check 'earliest_date'.
76 22 check_date($self, 'earliest_date');
77  
78 # Check 'end_time'.
79 22 check_date($self, 'end_time');
80  
81 # Check 'latest_date'.
82 22 check_date($self, 'latest_date');
83  
84 # Check 'precision'.
85 22 ▶ if (! defined $self->{'precision'} && defined $self->{'date'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"precision"} and defined $self->{"date"}) 9 13 22
Condition100%3/3
not defined $self->{"precision"} and defined $self->{"date"}
!ll&&!rl&&r
1129
MC/DC100%2/2
not defined $self->{"precision"} and defined $self->{"date"}
not defined $self->{"precision"} defined $self->{"date"}
Truth table100%3/3
not(A) and B
A= not defined $self->{"precision"}B= defined $self->{"date"}
ABresult
0X0
100
111
86 9 $self->{'precision'} = 'day';
87 }
88 22 check_strings($self, 'precision', \@PRECISION);
89  
90 # Check 'sourcing_circumstances'.
91 22 check_strings($self, 'sourcing_circumstances', \@SOURCING_CIRCUMSTANCES);
92  
93 # Check 'start_time'.
94 22 check_date($self, 'start_time');
95  
96 22 return;
97 }
98  
99 # TODO To Mo::utils.
100 sub _check_conflict {
101 354 ▶ my ($self, $param1, $param2) = @_;
Subroutine _check_conflict: called CC=3 SCAR=11.0
102  
103 354 ▶ if (defined $self->{$param1} && defined $self->{$param2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$param1} and defined $self->{$param2}) 12 342 354
Condition100%3/3
defined $self->{$param1} and defined $self->{$param2}
!ll&&!rl&&r
2628012
MC/DC100%2/2
defined $self->{$param1} and defined $self->{$param2}
defined $self->{$param1} defined $self->{$param2}
Truth table100%3/3
A and B
A= defined $self->{$param1}B= defined $self->{$param2}
ABresult
0X0
100
111
104 12 err "Parameter '$param1' is in conflict with parameter '$param2'.";
105 }
106  
107 342 return;
108 }
109  
110 11 1;
111  
112 __END__
113  
114 =pod
115  
116 =encoding utf8
117  
118 =head1 NAME
119  
120 MARC::Convert::Wikidata::Object::PublicationDate - Bibliographic Wikidata object for publication date defined by MARC record.
121  
122 =head1 SYNOPSIS
123  
124 use MARC::Convert::Wikidata::Object::PublicationDate;
125  
126 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(%params);
127 my $copyright = $obj->copyright;
128 my $date = $obj->date;
129 my $earliest_date = $obj->earliest_date;
130 my $end_time = $obj->end_time;
131 my $latest_date = $obj->latest_date;
132 my $precision = $obj->precision;
133 my $sourcing_circumstances = $obj->sourcing_circumstances;
134 my $start_time = $obj->start_time;
135  
136 =head1 DESCRIPTION
137  
138 The object for store publication date in book editions in the Czech National
139 Library.
140  
141 Possible scenarios are:
142  
143 =over
144  
145 =item Precise date
146  
147 We could use 'date' parameter to store publication date.
148  
149 =item Precise decade
150  
151 We could use 'date' and 'precision' parameters to store publication date with
152 precision (e.g. decade 1910s).
153  
154 =item Date between
155  
156 We could use 'earliest_date' and 'latest_date' parameters to store publication
157 date.
158  
159 =item Date defined as period of time
160  
161 We could use 'start_time' and 'end_time' parameters to store publication date.
162 e.g. For book series which one volume is from 'start_time' and last volume from
163 'end_time' publication date.
164  
165 =item Date which is with some accuracy
166  
167 We could use 'date' and 'sourcing_circumstances' parameters do define accuracy
168 (e.g. circa).
169  
170 =item Date for copyright
171  
172 We could use previous versions with 'copyright' parameter.
173  
174 =back
175  
176 =head1 METHODS
177  
178 =head2 C<new>
179  
180 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(%params);
181  
182 Constructor.
183  
184 Returns instance of object.
185  
186 =over 8
187  
188 =item * C<copyright>
189  
190 Flag, that date is for copyright.
191  
192 Default value is 0.
193  
194 =item * C<date>
195  
196 Precise date.
197  
198 Date is in YYYY-MM-DD, YYYY-M-D, YYYY-MM, YYYY-M or YYYY format.
199  
200 The parameter is in conflict with (earliest_date and latest_date) and (start_time
201 and end_time).
202  
203 Default value is undef.
204  
205 =item * C<earliest_date>
206  
207 Earliest date for definition publication date between dates.
208  
209 Date is in YYYY-MM-DD, YYYY-M-D, YYYY-MM, YYYY-M or YYYY format.
210  
211 The parameter is in conflict with (date) and (start_time
212 and end_time).
213  
214 Default value is undef.
215  
216 =item * C<end_time>
217  
218 End date for definition publication date via period of time.
219  
220 Date is in YYYY-MM-DD, YYYY-M-D, YYYY-MM, YYYY-M or YYYY format.
221  
222 The parameter is in conflict with (date) and (earliest_date and latest_date).
223  
224 Default value is undef.
225  
226 =item * C<latest_date>
227  
228 Latest date for definition publication date between dates.
229  
230 Date is in YYYY-MM-DD, YYYY-M-D, YYYY-MM, YYYY-M or YYYY format.
231  
232 The parameter is in conflict with (date) and (start_time
233 and end_time).
234  
235 Default value is undef.
236  
237 =item * C<precision>
238  
239 Precision for date.
240  
241 Possible values are:
242  
243 =over
244  
245 =item * day (default if 'date' present)
246  
247 =item * month
248  
249 =item * year
250  
251 =item * decade
252  
253 =item * century
254  
255 =item * millenium
256  
257 =back
258  
259 =item * C<sourcing_circumstances>
260  
261 Sourcing circumstances string.
262  
263 Possible values are:
264  
265 =over
266  
267 =item * circa
268  
269 =item * near
270  
271 =item * presumably
272  
273 =item * disputed
274  
275 =back
276  
277 =item * C<start_time>
278  
279 Start date for definition publication date via period of time.
280  
281 Date is in YYYY-MM-DD, YYYY-M-D, YYYY-MM, YYYY-M or YYYY format.
282  
283 The parameter is in conflict with (date) and (earliest_date and latest_date).
284  
285 Default value is undef.
286  
287 =back
288  
289 =head2 C<copyright>
290  
291 my $copyright = $obj->copyright;
292  
293 Get copyright flag.
294  
295 Returns 0/1.
296  
297 =head2 C<date>
298  
299 my $date = $obj->date;
300  
301 Get date.
302  
303 Returns string.
304  
305 =head2 C<earliest_date>
306  
307 my $earliest_date = $obj->earliest_date;
308  
309 Get earlest date.
310  
311 Returns string.
312  
313 =head2 C<end_time>
314  
315 my $end_time = $obj->end_time;
316  
317 Get end time.
318  
319 Returns string.
320  
321 =head2 C<latest_date>
322  
323 my $latest_date = $obj->latest_date;
324  
325 Get latest date.
326  
327 Returns string.
328  
329 =head2 C<precision>
330  
331 my $precision = $obj->precision;
332  
333 Get date precision.
334  
335 Returns string.
336  
337 =head2 C<sourcing_circumstances>
338  
339 my $sourcing_circumstances = $obj->sourcing_circumstances;
340  
341 Get sourcing circumstances string.
342  
343 Returns string.
344  
345 =head2 C<start_time>
346  
347 my $start_time = $obj->start_time;
348  
349 Get start time.
350  
351 Returns string.
352  
353 =head1 ERRORS
354  
355 new():
356 From Mo::utils::check_bool():
357 Parameter 'copyright' must be a bool (0/1).
358 Value: %s
359 From Mo::utils::check_strings():
360 Parameter 'precision' must have strings definition.
361 Parameter 'precision' must have right string definition.
362 Parameter 'precision' must be one of defined strings.
363 String: %s
364 Possible strings: %s
365 Parameter 'sourcing_circumstances' must have strings definition.
366 Parameter 'sourcing_circumstances' must have right string definition.
367 Parameter 'sourcing_circumstances' must be one of defined strings.
368 String: %s
369 Possible strings: %s
370 From Mo::utils::Date::check_date():
371 Parameter 'date' for date is in bad format.
372 Value: %s
373 Parameter 'date' has year greater than actual year.
374 Parameter 'earliest_date' for date is in bad format.
375 Value: %s
376 Parameter 'earliest_date' has year greater than actual year.
377 Parameter 'end_time' for date is in bad format.
378 Value: %s
379 Parameter 'end_time' has year greater than actual year.
380 Parameter 'start_time' for date is in bad format.
381 Value: %s
382 Parameter 'start_time' has year greater than actual year.
383 Parameter 'date' is in conflict with parameter 'earliest_date'.
384 Parameter 'date' is in conflict with parameter 'latest_date'.
385 Parameter 'date' is in conflict with parameter 'start_time'.
386 Parameter 'date' is in conflict with parameter 'end_time'.
387 Parameter 'earliest_date' is in conflict with parameter 'start_time'.
388 Parameter 'earliest_date' is in conflict with parameter 'end_time'.
389 Parameter 'latest_date' is in conflict with parameter 'start_time'.
390 Parameter 'latest_date' is in conflict with parameter 'end_time'.
391 Parameter 'precision' is in conflict with parameter 'earliest_date'.
392 Parameter 'precision' is in conflict with parameter 'latest_date'.
393 Parameter 'precision' is in conflict with parameter 'start_time'.
394 Parameter 'precision' is in conflict with parameter 'end_time'.
395  
396 =head1 EXAMPLE1
397  
398 =for comment filename=create_and_dump_publication_date1.pl
399  
400 use strict;
401 use warnings;
402  
403 use Data::Printer;
404 use MARC::Convert::Wikidata::Object::PublicationDate;
405
406 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(
407 'date' => '2014',
408 );
409
410 p $obj;
411  
412 # Output:
413 # MARC::Convert::Wikidata::Object::PublicationDate {
414 # parents: Mo::Object
415 # public methods (5):
416 # BUILD
417 # Error::Pure:
418 # err
419 # Mo::utils:
420 # check_bool, check_strings
421 # Readonly:
422 # Readonly
423 # private methods (1): _check_conflict
424 # internals: {
425 # date 2014
426 # }
427 # }
428  
429 =head1 EXAMPLE2
430  
431 =for comment filename=create_and_dump_publication_date2.pl
432  
433 use strict;
434 use warnings;
435  
436 use Data::Printer;
437 use MARC::Convert::Wikidata::Object::PublicationDate;
438
439 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(
440 'earliest_date' => '2014',
441 'latest_date' => '2020',
442 );
443
444 p $obj;
445  
446 # Output:
447 # MARC::Convert::Wikidata::Object::PublicationDate {
448 # parents: Mo::Object
449 # public methods (5):
450 # BUILD
451 # Error::Pure:
452 # err
453 # Mo::utils:
454 # check_bool, check_strings
455 # Readonly:
456 # Readonly
457 # private methods (1): _check_conflict
458 # internals: {
459 # earliest_date 2014,
460 # latest_date 2020
461 # }
462 # }
463  
464 =head1 EXAMPLE3
465  
466 =for comment filename=create_and_dump_publication_date3.pl
467  
468 use strict;
469 use warnings;
470  
471 use Data::Printer;
472 use MARC::Convert::Wikidata::Object::PublicationDate;
473
474 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(
475 'start_time' => '2014',
476 'end_time' => '2020',
477 );
478
479 p $obj;
480  
481 # Output:
482 # MARC::Convert::Wikidata::Object::PublicationDate {
483 # parents: Mo::Object
484 # public methods (5):
485 # BUILD
486 # Error::Pure:
487 # err
488 # Mo::utils:
489 # check_bool, check_strings
490 # Readonly:
491 # Readonly
492 # private methods (1): _check_conflict
493 # internals: {
494 # end_time 2020,
495 # start_time 2014
496 # }
497 # }
498  
499 =head1 EXAMPLE4
500  
501 =for comment filename=create_and_dump_publication_date4.pl
502  
503 use strict;
504 use warnings;
505  
506 use Data::Printer;
507 use MARC::Convert::Wikidata::Object::PublicationDate;
508
509 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(
510 'date' => '2014',
511 'sourcing_circumstances' => 'circa',
512 );
513
514 p $obj;
515  
516 # Output:
517 # MARC::Convert::Wikidata::Object::PublicationDate {
518 # parents: Mo::Object
519 # public methods (5):
520 # BUILD
521 # Error::Pure:
522 # err
523 # Mo::utils:
524 # check_bool, check_strings
525 # Readonly:
526 # Readonly
527 # private methods (1): _check_conflict
528 # internals: {
529 # date 2014,
530 # sourcing_circumstances "circa"
531 # }
532 # }
533  
534 =head1 EXAMPLE5
535  
536 =for comment filename=create_and_dump_publication_date5.pl
537  
538 use strict;
539 use warnings;
540  
541 use Data::Printer;
542 use MARC::Convert::Wikidata::Object::PublicationDate;
543
544 my $obj = MARC::Convert::Wikidata::Object::PublicationDate->new(
545 'copyright' => 1,
546 'date' => '2014',
547 );
548
549 p $obj;
550  
551 # Output:
552 # MARC::Convert::Wikidata::Object::PublicationDate {
553 # parents: Mo::Object
554 # public methods (5):
555 # BUILD
556 # Error::Pure:
557 # err
558 # Mo::utils:
559 # check_bool, check_strings
560 # Readonly:
561 # Readonly
562 # private methods (1): _check_conflict
563 # internals: {
564 # copyright 1,
565 # date 2014
566 # }
567 # }
568  
569 =head1 DEPENDENCIES
570  
571 L<Error::Pure>,
572 L<Mo>,
573 L<Mo::utils>,
574 L<Mo::utils::Date>,
575 L<Readonly>.
576  
577 =head1 SEE ALSO
578  
579 =over
580  
581 =item L<MARC::Convert::Wikidata>
582  
583 Conversion class between MARC record and Wikidata object.
584  
585 =back
586  
587 =head1 REPOSITORY
588  
589 L<https://github.com/michal-josef-spacek/MARC-Convert-Wikidata-Object>
590  
591 =head1 AUTHOR
592  
593 Michal Josef Špaček L<mailto:skim@cpan.org>
594  
595 L<http://skim.cz>
596  
597 =head1 LICENSE AND COPYRIGHT
598  
599 © Michal Josef Špaček 2021-2025
600  
601 BSD 2-Clause License
602  
603 =head1 VERSION
604  
605 0.15
606  
607 =cut
« Object.pm ↑ Summary Object/People.pm »