Object/ISBN.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 8 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 95.7% 68 / 71 SCAR 17.9
CC
6
Cov
98%
BUILD
5.0
type
2.0
BEGIN
1.0
CRAP 6.0
« Object/Utils.pm ↑ Summary Object.pm »
1 package MARC::Convert::Wikidata::Object::ISBN;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Business::ISBN;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Mo qw(build is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Mo::utils qw(check_isa check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use List::Util qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 7 Readonly::Array our @COVERS => qw(hardback paperback);
14  
15 7 our $VERSION = 0.01;
16  
17 7 has cover => (
18 is => 'ro',
19 );
20  
21 7 has isbn => (
22 is => 'ro',
23 );
24  
25 7 has publisher => (
26 is => 'ro',
27 );
28  
29 sub type {
30 2 ▶ my $self = shift;
Subroutine type: called CC=2 SCAR=6.9
Pod documented
31  
32 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
33 1 return 10;
34 } else {
35 1 return 13;
36 }
37 }
38  
39 sub BUILD {
40 13 ▶ my $self = shift;
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
41  
42 13 check_required($self, 'isbn');
43  
44 12 $self->{'_isbn'} = Business::ISBN->new($self->{'isbn'});
45 12 ▶ if (! defined $self->{'_isbn'} || ! $self->{'_isbn'}->is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_isbn"} and $self->{"_isbn"}->is_valid) 1 11 12
Condition66%2/3
defined $self->{"_isbn"} and $self->{"_isbn"}->is_valid
!ll&&!rl&&r
1011
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
46 1 err "ISBN '$self->{'isbn'}' isn't valid.";
47 }
48  
49 11 check_isa($self, 'publisher', 'MARC::Convert::Wikidata::Object::Publisher');
50  
51 11 ▶ if (defined $self->{'cover'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"cover"}) 2 9 11
52 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
53 1 err "ISBN cover '$self->{'cover'}' isn't valid.";
54 }
55 }
56  
57 10 return;
58 }
59  
60 7 1;
61  
62 __END__
63  
64 =pod
65  
66 =encoding utf8
67  
68 =head1 NAME
69  
70 MARC::Convert::Wikidata::Object::ISBN - Bibliographic Wikidata object for ISBN number defined by MARC record.
71  
72 =head1 SYNOPSIS
73  
74 use MARC::Convert::Wikidata::Object::ISBN;
75  
76 my $obj = MARC::Convert::Wikidata::Object::ISBN->new(%params);
77 my $cover = $obj->cover;
78 my $isbn = $obj->isbn;
79 my $publisher = $obj->publisher;
80 my $type = $obj->type;
81  
82 =head1 METHODS
83  
84 =head2 C<new>
85  
86 my $obj = MARC::Convert::Wikidata::Object::ISBN->new(%params);
87  
88 Constructor.
89  
90 Returns instance of object.
91  
92 =over 8
93  
94 =item * C<cover>
95  
96 ISBN cover.
97  
98 Parameter is optional. Valid values are: hardback, paperback
99  
100 Default value is undef.
101  
102 =item * C<isbn>
103  
104 ISBN number.
105  
106 Parameter is required.
107  
108 Default value is undef.
109  
110 =item * C<publisher>
111  
112 Publishing house object.
113 Instance of MARC::Convert::Wikidata::Object::Publisher.
114  
115 Default value is undef.
116  
117 =back
118  
119 =head2 C<cover>
120  
121 my $cover = $obj->cover;
122  
123 Get ISBN cover.
124  
125 Returns string.
126  
127 =head2 C<isbn>
128  
129 my $isbn = $obj->isbn;
130  
131 Get ISBN number.
132  
133 Returns string.
134  
135 =head2 C<publisher>
136  
137 my $publisher = $obj->publisher;
138  
139 Get publishing house name.
140  
141 Returns instance of MARC::Convert::Wikidata::Object::Publisher.
142  
143 =head2 C<type>
144  
145 my $type = $obj->type;
146  
147 Get type of ISBN number (10 or 13 character length)
148  
149 Returns number (10 or 13).
150  
151 =head1 ERRORS
152  
153 new():
154 Parameter 'isbn' is required.
155 ISBN '%s' isn't valid.
156 ISBN cover '%s' isn't valid.
157 From check_isa():
158 Parameter 'publisher' must be a 'MARC::Convert::Wikidata::Object::Publisher' object.
159  
160 =head1 EXAMPLE1
161  
162 =for comment filename=create_and_dump_isbn.pl
163  
164 use strict;
165 use warnings;
166  
167 use Data::Printer;
168 use MARC::Convert::Wikidata::Object::ISBN;
169 use MARC::Convert::Wikidata::Object::Publisher;
170
171 my $obj = MARC::Convert::Wikidata::Object::ISBN->new(
172 'isbn' => '978-80-00-05046-1',
173 'publisher' => MARC::Convert::Wikidata::Object::Publisher->new(
174 'name' => 'Albatros',
175 ),
176 );
177
178 p $obj;
179  
180 # Output:
181 # MARC::Convert::Wikidata::Object::ISBN {
182 # Parents Mo::Object
183 # public methods (9) : BUILD, can (UNIVERSAL), DOES (UNIVERSAL), err (Error::Pure), check_isa (Mo::utils), check_required (Mo::utils), isa (UNIVERSAL), type, VERSION (UNIVERSAL)
184 # private methods (1) : __ANON__ (Mo::build)
185 # internals: {
186 # _isbn Business::ISBN13,
187 # isbn "978-80-00-05046-1",
188 # publisher MARC::Convert::Wikidata::Object::Publisher
189 # }
190 # }
191  
192 =head1 DEPENDENCIES
193  
194 L<Business::ISBN>,
195 L<Error::Pure>,
196 L<Mo>,
197 L<Mo::utils>,
198 L<List::Util>,
199 L<Readonly>.
200  
201 =head1 SEE ALSO
202  
203 =over
204  
205 =item L<MARC::Convert::Wikidata>
206  
207 Conversion class between MARC record and Wikidata object.
208  
209 =back
210  
211 =head1 REPOSITORY
212  
213 L<https://github.com/michal-josef-spacek/MARC-Convert-Wikidata-Object>
214  
215 =head1 AUTHOR
216  
217 Michal Josef Špaček L<mailto:skim@cpan.org>
218  
219 L<http://skim.cz>
220  
221 =head1 LICENSE AND COPYRIGHT
222  
223 © Michal Josef Špaček 2021-2023
224  
225 BSD 2-Clause License
226  
227 =head1 VERSION
228  
229 0.01
230  
231 =cut
« Object/Utils.pm ↑ Summary Object.pm »