File Coverage

blib/lib/EBook/Ishmael/EBook/Metadata.pm
Criterion Covered Total %
statement 91 129 70.5
branch 18 38 47.3
condition n/a
subroutine 24 31 77.4
pod 28 28 100.0
total 161 226 71.2


line stmt bran cond sub pod time code
1             package EBook::Ishmael::EBook::Metadata;
2 17     17   391 use 5.016;
  17         80  
3             our $VERSION = '2.03';
4 17     17   113 use strict;
  17         31  
  17         506  
5 17     17   103 use warnings;
  17         30  
  17         29727  
6              
7             sub new {
8              
9 115     115 1 253 my $class = shift;
10              
11 115         1417 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         1531 return bless $self, $class;
26              
27             }
28              
29             sub hash {
30              
31 41     41 1 122 my $self = shift;
32              
33 41         82 my $hash;
34              
35 41         264 for my $k (keys %$self) {
36 451 100       956 if (not defined $self->{$k}) {
37 251         438 next;
38             }
39 200 100       487 if (ref $self->{$k} eq 'ARRAY') {
40 57         82 $hash->{$k} = [ @{ $self->{$k} } ];
  57         205  
41             } else {
42 143         473 $hash->{$k} = $self->{$k};
43             }
44             }
45              
46 41         342 return $hash;
47              
48             }
49              
50             sub author {
51              
52 1     1 1 3 my $self = shift;
53              
54 1 50       5 return defined $self->{Author} ? @{ $self->{Author} } : ();
  1         7  
55              
56             }
57              
58             sub set_author {
59              
60 0     0 1 0 my $self = shift;
61 0         0 my @set = grep { defined } @_;
  0         0  
62              
63 0 0       0 if (@set) {
64 0         0 $self->{Author} = \@set;
65             } else {
66 0         0 $self->{Author} = undef;
67             }
68              
69             }
70              
71             sub add_author {
72              
73 40     40 1 82 my $self = shift;
74 40         97 my @add = grep { defined } @_;
  40         244  
75              
76 40         76 push @{ $self->{Author} }, @add;
  40         200  
77              
78             }
79              
80             sub software {
81              
82 0     0 1 0 my $self = shift;
83              
84 0         0 return $self->{Software};
85              
86             }
87              
88             sub set_software {
89              
90 21     21 1 35 my $self = shift;
91 21         33 my $set = shift;
92              
93 21 50       75 if (not defined $set) {
94 0         0 $self->{Software} = undef;
95             } else {
96 21         68 $self->{Software} = $set;
97             }
98              
99             }
100              
101             sub created {
102              
103 30     30 1 69 my $self = shift;
104              
105 30         146 return $self->{Created};
106              
107             }
108              
109             sub set_created {
110              
111 72     72 1 151 my $self = shift;
112 72         153 my $set = shift;
113              
114 72 100       492 if (not defined $set) {
    50          
115 20         91 $self->{Created} = undef;
116             } elsif ($set =~ /^-?\d+$/) {
117 52         232 $self->{Created} = $set;
118             } else {
119 0         0 die "created must be either undef or an integar";
120             }
121              
122             }
123              
124             sub modified {
125              
126 2     2 1 6 my $self = shift;
127 2         4 my $set = shift;
128              
129 2         15 return $self->{Modified};
130              
131             }
132              
133             sub set_modified {
134              
135 74     74 1 161 my $self = shift;
136 74         155 my $set = shift;
137              
138 74 50       541 if (not defined $set) {
    50          
139 0         0 $self->{Modified} = undef;
140             } elsif ($set =~ /^-?\d+$/) {
141 74         261 $self->{Modified} = $set;
142             } else {
143 0         0 die "modified must be either an integar or undef";
144             }
145              
146             }
147              
148             sub format {
149              
150 23     23 1 44 my $self = shift;
151              
152 23         105 return $self->{Format};
153              
154             }
155              
156             sub set_format {
157              
158 115     115 1 238 my $self = shift;
159 115         431 my $set = shift;
160              
161 115 50       501 if (not defined $set) {
162 0         0 $self->{Format} = undef;
163             } else {
164 115         353 $self->{Format} = $set;
165             }
166              
167             }
168              
169             sub title {
170              
171 34     34 1 72 my $self = shift;
172              
173 34         186 return $self->{Title};
174              
175             }
176              
177             sub set_title {
178              
179 115     115 1 275 my $self = shift;
180 115         271 my $set = shift;
181              
182 115 50       376 if (not defined $set) {
183 0         0 $self->{Title} = $set;
184             } else {
185 115         492 $self->{Title} = $set;
186             }
187              
188             }
189              
190             sub language {
191              
192 22     22 1 71 my $self = shift;
193              
194 22 100       122 return defined $self->{Language} ? @{ $self->{Language} } : ();
  1         60  
195              
196             }
197              
198             sub set_language {
199              
200 10     10 1 23 my $self = shift;
201 10         28 my @set = grep { defined } @_;
  10         46  
202              
203 10 50       23 if (@set) {
204 10         41 $self->{Language} = \@set;
205             } else {
206 0         0 $self->{Language} = undef;
207             }
208              
209             }
210              
211             sub add_language {
212              
213 51     51 1 113 my $self = shift;
214 51         141 my @add = grep { defined } @_;
  51         216  
215              
216 51         119 push @{ $self->{Language} }, @add;
  51         243  
217              
218             }
219              
220             sub genre {
221              
222 0     0 1 0 my $self = shift;
223              
224 0 0       0 return defined $self->{Genre} ? @{ $self->{Genre} } : ();
  0         0  
225              
226             }
227              
228             sub set_genre {
229              
230 0     0 1 0 my $self = shift;
231 0         0 my @set = grep { defined } @_;
  0         0  
232              
233 0 0       0 if (@set) {
234 0         0 $self->{Genre} = \@set;
235             } else {
236 0         0 $self->{Genre} = undef;
237             }
238              
239             }
240              
241             sub add_genre {
242              
243 10     10 1 17 my $self = shift;
244 10         22 my @add = grep { defined } @_;
  10         33  
245              
246 10         13 push @{ $self->{Genre} }, @add;
  10         43  
247              
248             }
249              
250             sub id {
251              
252 1     1 1 2 my $self = shift;
253              
254 1         7 return $self->{ID};
255              
256             }
257              
258             sub set_id {
259              
260 30     30 1 49 my $self = shift;
261 30         50 my $set = shift;
262              
263 30 50       72 if (not defined $set) {
264 0         0 $self->{ID} = undef;
265             } else {
266 30         89 $self->{ID} = $set;
267             }
268              
269             }
270              
271             sub description {
272              
273 0     0 1 0 my $self = shift;
274              
275 0         0 return $self->{Description};
276              
277             }
278              
279             sub set_description {
280              
281 0     0 1 0 my $self = shift;
282 0         0 my $set = shift;
283              
284 0 0       0 if (not defined $set) {
285 0         0 $self->{Description} = undef;
286             } else {
287 0         0 $self->{Description} = $set;
288             }
289              
290             }
291              
292             sub contributor {
293              
294 1     1 1 3 my $self = shift;
295              
296 1 50       7 return defined $self->{Contributor} ? @{ $self->{Contributor} } : ();
  1         7  
297              
298             }
299              
300             sub set_contributor {
301              
302 0     0 1 0 my $self = shift;
303 0         0 my @set = grep { defined } @_;
  0         0  
304              
305 0 0       0 if (@set) {
306 0         0 $self->{Contributor} = \@set;
307             } else {
308 0         0 $self->{Contributor} = undef;
309             }
310              
311             }
312              
313             sub add_contributor {
314              
315 40     40 1 79 my $self = shift;
316 40         87 my @add = grep { defined } @_;
  40         139  
317              
318 40         68 push @{ $self->{Contributor} }, @add;
  40         173  
319              
320             }
321              
322             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 is a module used by L to provide
341             a format-agnostic interface to ebook metadata. This is developer documentation,
342             for user documentation please consult the L manual.
343              
344             =head1 METHODS
345              
346             =head2 $m = EBook::Ishmael::EBook::Metadata->new()
347              
348             Returns a blessed C 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, Esamyoung12788@gmail.comE.
433              
434             This project's source can be found on its
435             L. 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