Object/ISBN.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 12 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 96.3% 80 / 83 CC 8 SCAR 12.4
CC
8
Cov
99%
BUILD
7.0
type
2.0
BEGIN
1.0
CRAP 3.4
↑ Summary Object/Series.pm »
1 package MARC::Convert::Wikidata::Object::ISBN;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Business::ISBN;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Mo qw(build is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Mo::utils 0.08 qw(check_bool check_isa check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use List::Util 1.33 qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 Readonly::Array our @COVERS => qw(hardback paperback);
14  
15 9 our $VERSION = 0.15;
16  
17 9 has collective => (
18 is => 'ro',
19 );
20  
21 9 has cover => (
22 is => 'ro',
23 );
24  
25 9 has isbn => (
26 is => 'ro',
27 );
28  
29 9 has publisher => (
30 is => 'ro',
31 );
32  
33 9 has valid => (
34 is => 'ro',
35 );
36  
37 sub type {
38 2 ▶ my $self = shift;
Subroutine type: called CC=2 SCAR=6.9
Pod documented
39  
40 2 ▶ if ($self->{'_isbn'}->as_isbn10->as_string eq $self->{'isbn'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_isbn'}->as_isbn10->as_string eq $self->{'isbn'}) { } 1 1 2
41 1 return 10;
42 } else {
43 1 return 13;
44 }
45 }
46  
47 sub BUILD {
48 18 ▶ my $self = shift;
Subroutine BUILD: called CC=7 SCAR=19.5
Pod undocumented
49  
50 # Check 'collective'.
51 18 ▶ if (! defined $self->{'collective'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"collective"}) 17 1 18
52 17 $self->{'collective'} = 0;
53 }
54 18 check_bool($self, 'collective');
55  
56 # Check 'cover'.
57 18 ▶ if (defined $self->{'cover'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cover"}) 2 16 18
58 2 ▶ if (none { $self->{'cover'} eq $_ } @COVERS) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $self->{"cover"} eq $_; } , @MARC::Convert::Wikidata::Object::ISBN::COVERS)) 1 1 2
59 1 err "ISBN cover '$self->{'cover'}' isn't valid.";
60 }
61 }
62  
63 # Check 'isbn'.
64 17 check_required($self, 'isbn');
65 16 $self->{'_isbn'} = Business::ISBN->new($self->{'isbn'});
66 16 ▶ if (! defined $self->{'_isbn'} || ! $self->{'_isbn'}->is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_isbn"} and $self->{"_isbn"}->is_valid) 1 15 16
Condition66%2/3
defined $self->{"_isbn"} and $self->{"_isbn"}->is_valid
!ll&&!rl&&r
1015
MC/DC50%1/2
defined $self->{"_isbn"} and $self->{"_isbn"}->is_valid
defined $self->{"_isbn"} $self->{"_isbn"}->is_valid
Truth table66%2/3
A and B
A= defined $self->{"_isbn"}B= $self->{"_isbn"}->is_valid
ABresult
0X0
100
111
67 1 err "ISBN '$self->{'isbn'}' isn't valid.";
68 }
69  
70 # Check 'publisher'.
71 15 check_isa($self, 'publisher', 'MARC::Convert::Wikidata::Object::Publisher');
72  
73 # Check 'valid'.
74 15 ▶ if (! defined $self->{'valid'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"valid"}) 13 2 15
75 13 $self->{'valid'} = 1;
76 }
77 15 check_bool($self, 'valid');
78  
79 15 return;
80 }
81  
82 9 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
↑ Summary Object/Series.pm »