blib/lib/EBook/Ishmael/EBook/Metadata.pm

filter: Statementstmt 70.2% 92 / 131 Branchbran 44.7% 17 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.4% 24 / 31 Podpod 100% 28 / 28 totaltotal 70.6% 161 / 228 CC 21 SCAR 10.6
CC
21
Cov
64%
set_author
6.0
genre
6.0
set_genre
6.0
CRAP 2.9
« blib/lib/EBook/Ishmael/EBook/Text.pm ↑ Summary blib/lib/EBook/Ishmael/CharDet/CP.pm »
1 package EBook::Ishmael::EBook::Metadata;
2 17 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 our $VERSION = '2.04';
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new {
8  
9 115 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
10  
11 115 my $self = {
12 Author => undef,
13 Software => undef,
14 Created => undef,
15 Modified => undef,
16 Format => undef,
17 Title => undef,
18 Language => undef,
19 Genre => undef,
20 ID => undef,
21 Description => undef,
22 Contributor => undef,
23 };
24  
25 115 return bless $self, $class;
26  
27 }
28  
29 sub hash {
30  
31 41 ▶ my $self = shift;
Subroutine hash: called CC=4 SCAR=13.9
Pod documented
32  
33 41 my $hash;
34  
35 41 for my $k (keys %$self) {
36 451 ▶ if (not defined $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$k}) 248 203 451
37 248 next;
38 }
39 203 ▶ if (ref $self->{$k} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$k} eq 'ARRAY') { } 57 146 203
40 57 $hash->{$k} = [ @{ $self->{$k} } ];
41 } else {
42 146 $hash->{$k} = $self->{$k};
43 }
44 }
45  
46 41 return $hash;
47  
48 }
49  
50 sub author {
51  
52 1 ▶ my $self = shift;
Subroutine author: called CC=2 SCAR=7.1
Pod documented
53  
54 1 ▶ return defined $self->{Author} ? @{ $self->{Author} } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Author'} ? : 1 0 1
55  
56 }
57  
58 sub set_author {
59  
60 0 ▶ my $self = shift;
Subroutine set_author: not called CC=2 SCAR=17.9
Pod documented
61 0 my @set = grep { defined } @_;
62  
63 0 ▶ if (@set) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set) { } 0 0 0
64 0 $self->{Author} = \@set;
65 } else {
66 0 $self->{Author} = undef;
67 }
68  
69 }
70  
71 sub add_author {
72  
73 40 ▶ my $self = shift;
Subroutine add_author: called CC=1 SCAR=0.0
Pod documented
74 40 my @add = grep { defined } @_;
75  
76 40 push @{ $self->{Author} }, @add;
77  
78 }
79  
80 sub software {
81  
82 0 ▶ my $self = shift;
Subroutine software: not called CC=1 SCAR=6.9
Pod documented
83  
84 0 return $self->{Software};
85  
86 }
87  
88 sub set_software {
89  
90 21 ▶ my $self = shift;
Subroutine set_software: called CC=2 SCAR=7.4
Pod documented
91 21 my $set = shift;
92  
93 21 ▶ if (not defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set) { } 0 21 21
94 0 $self->{Software} = undef;
95 } else {
96 21 $self->{Software} = $set;
97 }
98  
99 }
100  
101 sub created {
102  
103 51 ▶ my $self = shift;
Subroutine created: called CC=1 SCAR=0.0
Pod documented
104  
105 51 return $self->{Created};
106  
107 }
108  
109 sub set_created {
110  
111 82 ▶ my $self = shift;
Subroutine set_created: called CC=3 SCAR=12.7
Pod documented
112 82 my $set = shift;
113  
114 82 ▶ if (not defined $set) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $set) { } 0 82 82
elsif ($set =~ /^-?\d+$/u) { } 82 0 82
115 0 $self->{Created} = undef;
116 } elsif ($set =~ /^-?\d+$/) {
117 82 $self->{Created} = $set;
118 } else {
119 0 die "created must be either undef or an integar";
120 }
121  
122 }
123  
124 sub modified {
125  
126 2 ▶ my $self = shift;
Subroutine modified: called CC=1 SCAR=0.0
Pod documented
127 2 my $set = shift;
128  
129 2 return $self->{Modified};
130  
131 }
132  
133 sub set_modified {
134  
135 74 ▶ my $self = shift;
Subroutine set_modified: called CC=3 SCAR=12.7
Pod documented
136 74 my $set = shift;
137  
138 74 ▶ if (not defined $set) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $set) { } 0 74 74
elsif ($set =~ /^-?\d+$/u) { } 74 0 74
139 0 $self->{Modified} = undef;
140 } elsif ($set =~ /^-?\d+$/) {
141 74 $self->{Modified} = $set;
142 } else {
143 0 die "modified must be either an integar or undef";
144 }
145  
146 }
147  
148 sub format {
149  
150 23 ▶ my $self = shift;
Subroutine format: called CC=1 SCAR=0.0
Pod documented
151  
152 23 return $self->{Format};
153  
154 }
155  
156 sub set_format {
157  
158 115 ▶ my $self = shift;
Subroutine set_format: called CC=2 SCAR=7.4
Pod documented
159 115 my $set = shift;
160  
161 115 ▶ if (not defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set) { } 0 115 115
162 0 $self->{Format} = undef;
163 } else {
164 115 $self->{Format} = $set;
165 }
166  
167 }
168  
169 sub title {
170  
171 34 ▶ my $self = shift;
Subroutine title: called CC=1 SCAR=0.0
Pod documented
172  
173 34 return $self->{Title};
174  
175 }
176  
177 sub set_title {
178  
179 115 ▶ my $self = shift;
Subroutine set_title: called CC=2 SCAR=7.4
Pod documented
180 115 my $set = shift;
181  
182 115 ▶ if (not defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set) { } 0 115 115
183 0 $self->{Title} = $set;
184 } else {
185 115 $self->{Title} = $set;
186 }
187  
188 }
189  
190 sub language {
191  
192 22 ▶ my $self = shift;
Subroutine language: called CC=2 SCAR=6.9
Pod documented
193  
194 22 ▶ return defined $self->{Language} ? @{ $self->{Language} } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Language'} ? : 1 21 22
195  
196 }
197  
198 sub set_language {
199  
200 10 ▶ my $self = shift;
Subroutine set_language: called CC=2 SCAR=7.2
Pod documented
201 10 my @set = grep { defined } @_;
202  
203 10 ▶ if (@set) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set) { } 10 0 10
204 10 $self->{Language} = \@set;
205 } else {
206 0 $self->{Language} = undef;
207 }
208  
209 }
210  
211 sub add_language {
212  
213 51 ▶ my $self = shift;
Subroutine add_language: called CC=1 SCAR=0.0
Pod documented
214 51 my @add = grep { defined } @_;
215  
216 51 push @{ $self->{Language} }, @add;
217  
218 }
219  
220 sub genre {
221  
222 0 ▶ my $self = shift;
Subroutine genre: not called CC=2 SCAR=17.9
Pod documented
223  
224 0 ▶ return defined $self->{Genre} ? @{ $self->{Genre} } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Genre'} ? : 0 0 0
225  
226 }
227  
228 sub set_genre {
229  
230 0 ▶ my $self = shift;
Subroutine set_genre: not called CC=2 SCAR=17.9
Pod documented
231 0 my @set = grep { defined } @_;
232  
233 0 ▶ if (@set) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set) { } 0 0 0
234 0 $self->{Genre} = \@set;
235 } else {
236 0 $self->{Genre} = undef;
237 }
238  
239 }
240  
241 sub add_genre {
242  
243 10 ▶ my $self = shift;
Subroutine add_genre: called CC=1 SCAR=0.0
Pod documented
244 10 my @add = grep { defined } @_;
245  
246 10 push @{ $self->{Genre} }, @add;
247  
248 }
249  
250 sub id {
251  
252 1 ▶ my $self = shift;
Subroutine id: called CC=1 SCAR=0.0
Pod documented
253  
254 1 return $self->{ID};
255  
256 }
257  
258 sub set_id {
259  
260 30 ▶ my $self = shift;
Subroutine set_id: called CC=2 SCAR=7.4
Pod documented
261 30 my $set = shift;
262  
263 30 ▶ if (not defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set) { } 0 30 30
264 0 $self->{ID} = undef;
265 } else {
266 30 $self->{ID} = $set;
267 }
268  
269 }
270  
271 sub description {
272  
273 0 ▶ my $self = shift;
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
274  
275 0 return $self->{Description};
276  
277 }
278  
279 sub set_description {
280  
281 0 ▶ my $self = shift;
Subroutine set_description: not called CC=2 SCAR=17.9
Pod documented
282 0 my $set = shift;
283  
284 0 ▶ if (not defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $set) { } 0 0 0
285 0 $self->{Description} = undef;
286 } else {
287 0 $self->{Description} = $set;
288 }
289  
290 }
291  
292 sub contributor {
293  
294 1 ▶ my $self = shift;
Subroutine contributor: called CC=2 SCAR=7.1
Pod documented
295  
296 1 ▶ return defined $self->{Contributor} ? @{ $self->{Contributor} } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Contributor'} ? : 1 0 1
297  
298 }
299  
300 sub set_contributor {
301  
302 0 ▶ my $self = shift;
Subroutine set_contributor: not called CC=2 SCAR=17.9
Pod documented
303 0 my @set = grep { defined } @_;
304  
305 0 ▶ if (@set) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set) { } 0 0 0
306 0 $self->{Contributor} = \@set;
307 } else {
308 0 $self->{Contributor} = undef;
309 }
310  
311 }
312  
313 sub add_contributor {
314  
315 40 ▶ my $self = shift;
Subroutine add_contributor: called CC=1 SCAR=0.0
Pod documented
316 40 my @add = grep { defined } @_;
317  
318 40 push @{ $self->{Contributor} }, @add;
319  
320 }
321  
322 17 1;
323  
324 =head1 NAME
325  
326 EBook::Ishmael::EBook::Metadata - Ebook metadata interface
327  
328 =head1 SYNOPSIS
329  
330 use EBook::Ishmael::EBook::Metadata;
331  
332 my $meta = EBook::Ishmael::EBook::Metadata->new;
333  
334 $meta->title([ 'Moby-Dick' ]);
335 $meta->author([ 'Herman Melville' ]);
336 $meta->language([ 'en' ]);
337  
338 =head1 DESCRIPTION
339  
340 B<EBook::Ishmael::EBook::Metadata> is a module used by L<ishmael> to provide
341 a format-agnostic interface to ebook metadata. This is developer documentation,
342 for user documentation please consult the L<ishmael> manual.
343  
344 =head1 METHODS
345  
346 =head2 $m = EBook::Ishmael::EBook::Metadata->new()
347  
348 Returns a blessed C<EBook::Ishmael::EBook::Metadata> object.
349  
350 =head2 $h = $m->hash
351  
352 Returns a plain hash ref of the object's metadata.
353  
354 =head2 Accessors
355  
356 =head3 @a = $m->author()
357  
358 =head3 $m->set_author(@a)
359  
360 =head3 $m->add_author(@a)
361  
362 Set/get the author(s) of the ebook.
363  
364 =head3 $s = $m->software()
365  
366 =head3 $m->set_software($s)
367  
368 Set/get the software used to create the ebook.
369  
370 =head3 $c = $m->created()
371  
372 =head3 $m->set_created($c)
373  
374 Set/get the creation date of the ebook.
375  
376 =head3 $o = $m->modified()
377  
378 =head3 $m->set_modified($o)
379  
380 Set/get the modification date of the ebook.
381  
382 =head3 $f = $m->format()
383  
384 =head3 $m->set_format($f)
385  
386 Set/get the format of the ebook.
387  
388 =head3 $t = $m->title()
389  
390 =head3 $m->set_title($t)
391  
392 Set/get the title of the ebook.
393  
394 =head3 @l = $m->language()
395  
396 =head3 $m->set_language(@l)
397  
398 =head3 $m->add_language(@l)
399  
400 Set/get the language(s) of the ebook.
401  
402 =head3 @g = $m->genre()
403  
404 =head3 $m->set_genre(@g)
405  
406 =head3 $m->add_genre(@a)
407  
408 Set/get the genre(s) of the ebook.
409  
410 =head3 $i = $m->id()
411  
412 =head3 $m->set_id($i)
413  
414 Set/get the identifier of the ebook.
415  
416 =head3 $d = $m->description()
417  
418 =head3 $m->set_description($d)
419  
420 Set/get the text description of the ebook.
421  
422 =head3 @c = $m->contributor()
423  
424 =head3 $m->set_contributor(@c)
425  
426 =head3 $m->add_contributor(@c)
427  
428 Set/get the contributor(s) of the ebook.
429  
430 =head1 AUTHOR
431  
432 Written by Samuel Young, E<lt>samyoung12788@gmail.comE<gt>.
433  
434 This project's source can be found on its
435 L<Codeberg Page|https://codeberg.org/1-1sam/ishmael>. Comments and pull
436 requests are welcome!
437  
438 =head1 COPYRIGHT
439  
440 Copyright (C) 2025-2026 Samuel Young
441  
442 This program is free software: you can redistribute it and/or modify
443 it under the terms of the GNU General Public License as published by
444 the Free Software Foundation, either version 3 of the License, or
445 (at your option) any later version.
446  
447 =cut
« blib/lib/EBook/Ishmael/EBook/Text.pm ↑ Summary blib/lib/EBook/Ishmael/CharDet/CP.pm »