File Coverage

blib/lib/MARC/Convert/Wikidata/Object/ISBN.pm
Criterion Covered Total %
statement 45 45 100.0
branch 12 12 100.0
condition 2 3 66.6
subroutine 11 11 100.0
pod 1 2 50.0
total 71 73 97.2


line stmt bran cond sub pod time code
1             package MARC::Convert::Wikidata::Object::ISBN;
2              
3 9     9   207466 use strict;
  9         22  
  9         487  
4 9     9   103 use warnings;
  9         18  
  9         478  
5              
6 9     9   5569 use Business::ISBN;
  9         738569  
  9         584  
7 9     9   4574 use Error::Pure qw(err);
  9         100688  
  9         364  
8 9     9   4975 use Mo qw(build is);
  9         5748  
  9         76  
9 9     9   20386 use Mo::utils 0.08 qw(check_bool check_isa check_required);
  9         28127  
  9         328  
10 9     9   1621 use List::Util 1.33 qw(none);
  9         167  
  9         696  
11 9     9   85 use Readonly;
  9         33  
  9         5388  
12              
13             Readonly::Array our @COVERS => qw(hardback paperback);
14              
15             our $VERSION = 0.15;
16              
17             has collective => (
18             is => 'ro',
19             );
20              
21             has cover => (
22             is => 'ro',
23             );
24              
25             has isbn => (
26             is => 'ro',
27             );
28              
29             has publisher => (
30             is => 'ro',
31             );
32              
33             has valid => (
34             is => 'ro',
35             );
36              
37             sub type {
38 2     2 1 43 my $self = shift;
39              
40 2 100       14 if ($self->{'_isbn'}->as_isbn10->as_string eq $self->{'isbn'}) {
41 1         530 return 10;
42             } else {
43 1         464 return 13;
44             }
45             }
46              
47             sub BUILD {
48 18     18 0 2125628 my $self = shift;
49              
50             # Check 'collective'.
51 18 100       141 if (! defined $self->{'collective'}) {
52 17         48 $self->{'collective'} = 0;
53             }
54 18         88 check_bool($self, 'collective');
55              
56             # Check 'cover'.
57 18 100       416 if (defined $self->{'cover'}) {
58 2 100   3   31 if (none { $self->{'cover'} eq $_ } @COVERS) {
  3         49  
59 1         15 err "ISBN cover '$self->{'cover'}' isn't valid.";
60             }
61             }
62              
63             # Check 'isbn'.
64 17         80 check_required($self, 'isbn');
65 16         191 $self->{'_isbn'} = Business::ISBN->new($self->{'isbn'});
66 16 100 66     6264 if (! defined $self->{'_isbn'} || ! $self->{'_isbn'}->is_valid) {
67 1         9 err "ISBN '$self->{'isbn'}' isn't valid.";
68             }
69              
70             # Check 'publisher'.
71 15         193 check_isa($self, 'publisher', 'MARC::Convert::Wikidata::Object::Publisher');
72              
73             # Check 'valid'.
74 15 100       267 if (! defined $self->{'valid'}) {
75 13         128 $self->{'valid'} = 1;
76             }
77 15         56 check_bool($self, 'valid');
78              
79 15         291 return;
80             }
81              
82             1;
83              
84             __END__
85              
86             =pod
87              
88             =encoding utf8
89              
90             =head1 NAME
91              
92             MARC::Convert::Wikidata::Object::ISBN - Bibliographic Wikidata object for ISBN number defined by MARC record.
93              
94             =head1 SYNOPSIS
95              
96             use MARC::Convert::Wikidata::Object::ISBN;
97              
98             my $obj = MARC::Convert::Wikidata::Object::ISBN->new(%params);
99             my $collective = $obj->collective.
100             my $cover = $obj->cover;
101             my $isbn = $obj->isbn;
102             my $publisher = $obj->publisher;
103             my $type = $obj->type;
104             my $valid = $obj->valid;
105              
106             =head1 METHODS
107              
108             =head2 C<new>
109              
110             my $obj = MARC::Convert::Wikidata::Object::ISBN->new(%params);
111              
112             Constructor.
113              
114             Returns instance of object.
115              
116             =over 8
117              
118             =item * C<collective>
119              
120             ISBN collective flag.
121              
122             Parameter means that ISBN is for collection.
123              
124             Valid value is boolean (0/1).
125              
126             Default value is 0.
127              
128             =item * C<cover>
129              
130             ISBN cover.
131              
132             Parameter is optional. Valid values are: hardback, paperback
133              
134             Default value is undef.
135              
136             =item * C<isbn>
137              
138             ISBN number.
139              
140             Parameter is required.
141              
142             Default value is undef.
143              
144             =item * C<publisher>
145              
146             Publishing house object.
147             Instance of MARC::Convert::Wikidata::Object::Publisher.
148              
149             Default value is undef.
150              
151             =item * C<valid>
152              
153             Flag if ISBN is valid or not.
154              
155             Default value is 1 (valid),
156              
157             =back
158              
159             =head2 C<collective>
160              
161             my $collective = $obj->collective.
162              
163             Get collective flag.
164              
165             Returns bool (0/1).
166              
167             =head2 C<cover>
168              
169             my $cover = $obj->cover;
170              
171             Get ISBN cover.
172              
173             Returns string.
174              
175             =head2 C<isbn>
176              
177             my $isbn = $obj->isbn;
178              
179             Get ISBN number.
180              
181             Returns string.
182              
183             =head2 C<publisher>
184              
185             my $publisher = $obj->publisher;
186              
187             Get publishing house name.
188              
189             Returns instance of MARC::Convert::Wikidata::Object::Publisher.
190              
191             =head2 C<type>
192              
193             my $type = $obj->type;
194              
195             Get type of ISBN number (10 or 13 character length)
196              
197             Returns number (10 or 13).
198              
199             =head2 C<valid>
200              
201             my $valid = $obj->valid;
202              
203             Get valid flag.
204              
205             Returns boolean (0/1).
206              
207             =head1 ERRORS
208              
209             new():
210             Parameter 'collective' must be a bool (0/1).
211             Parameter 'isbn' is required.
212             ISBN '%s' isn't valid.
213             ISBN cover '%s' isn't valid.
214             From check_isa():
215             Parameter 'publisher' must be a 'MARC::Convert::Wikidata::Object::Publisher' object.
216             From check_bool():
217             Parameter '%s' must be a bool (0/1).
218             Value: %s
219              
220             =head1 EXAMPLE1
221              
222             =for comment filename=create_and_dump_isbn.pl
223              
224             use strict;
225             use warnings;
226              
227             use Data::Printer;
228             use MARC::Convert::Wikidata::Object::ISBN;
229             use MARC::Convert::Wikidata::Object::Publisher;
230            
231             my $obj = MARC::Convert::Wikidata::Object::ISBN->new(
232             'isbn' => '978-80-00-05046-1',
233             'publisher' => MARC::Convert::Wikidata::Object::Publisher->new(
234             'name' => 'Albatros',
235             ),
236             );
237            
238             p $obj;
239              
240             # Output:
241             # MARC::Convert::Wikidata::Object::ISBN {
242             # parents: Mo::Object
243             # public methods (8):
244             # BUILD, type
245             # Error::Pure:
246             # err
247             # List::Util:
248             # none
249             # Mo::utils:
250             # check_bool, check_isa, check_required
251             # Readonly:
252             # Readonly
253             # private methods (0)
254             # internals: {
255             # collective 0,
256             # _isbn 978-80-00-05046-1 (Business::ISBN13),
257             # isbn "978-80-00-05046-1" (dualvar: 978),
258             # publisher MARC::Convert::Wikidata::Object::Publisher,
259             # valid 1
260             # }
261             # }
262              
263             =head1 DEPENDENCIES
264              
265             L<Business::ISBN>,
266             L<Error::Pure>,
267             L<Mo>,
268             L<Mo::utils>,
269             L<List::Util>,
270             L<Readonly>.
271              
272             =head1 SEE ALSO
273              
274             =over
275              
276             =item L<MARC::Convert::Wikidata>
277              
278             Conversion class between MARC record and Wikidata object.
279              
280             =back
281              
282             =head1 REPOSITORY
283              
284             L<https://github.com/michal-josef-spacek/MARC-Convert-Wikidata-Object>
285              
286             =head1 AUTHOR
287              
288             Michal Josef Špaček L<mailto:skim@cpan.org>
289              
290             L<http://skim.cz>
291              
292             =head1 LICENSE AND COPYRIGHT
293              
294             © Michal Josef Špaček 2021-2025
295              
296             BSD 2-Clause License
297              
298             =head1 VERSION
299              
300             0.15
301              
302             =cut