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   389 use 5.016;
  17         74  
3             our $VERSION = '2.01';
4 17     17   129 use strict;
  17         31  
  17         577  
5 17     17   85 use warnings;
  17         40  
  17         33430  
6              
7             sub new {
8              
9 115     115 1 300 my $class = shift;
10              
11 115         1350 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         1445 return bless $self, $class;
26              
27             }
28              
29             sub hash {
30              
31 41     41 1 88 my $self = shift;
32              
33 41         97 my $hash;
34              
35 41         266 for my $k (keys %$self) {
36 451 100       966 if (not defined $self->{$k}) {
37 251         454 next;
38             }
39 200 100       471 if (ref $self->{$k} eq 'ARRAY') {
40 57         84 $hash->{$k} = [ @{ $self->{$k} } ];
  57         211  
41             } else {
42 143         420 $hash->{$k} = $self->{$k};
43             }
44             }
45              
46 41         285 return $hash;
47              
48             }
49              
50             sub author {
51              
52 1     1 1 32 my $self = shift;
53              
54 1 50       7 return defined $self->{Author} ? @{ $self->{Author} } : ();
  1         8  
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         107 my @add = grep { defined } @_;
  40         123  
75              
76 40         81 push @{ $self->{Author} }, @add;
  40         184  
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 34 my $self = shift;
91 21         37 my $set = shift;
92              
93 21 50       59 if (not defined $set) {
94 0         0 $self->{Software} = undef;
95             } else {
96 21         55 $self->{Software} = $set;
97             }
98              
99             }
100              
101             sub created {
102              
103 30     30 1 55 my $self = shift;
104              
105 30         155 return $self->{Created};
106              
107             }
108              
109             sub set_created {
110              
111 72     72 1 158 my $self = shift;
112 72         181 my $set = shift;
113              
114 72 100       488 if (not defined $set) {
    50          
115 20         99 $self->{Created} = undef;
116             } elsif ($set =~ /^-?\d+$/) {
117 52         204 $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         2 my $set = shift;
128              
129 2         13 return $self->{Modified};
130              
131             }
132              
133             sub set_modified {
134              
135 74     74 1 205 my $self = shift;
136 74         179 my $set = shift;
137              
138 74 50       490 if (not defined $set) {
    50          
139 0         0 $self->{Modified} = undef;
140             } elsif ($set =~ /^-?\d+$/) {
141 74         268 $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 49 my $self = shift;
151              
152 23         92 return $self->{Format};
153              
154             }
155              
156             sub set_format {
157              
158 115     115 1 247 my $self = shift;
159 115         290 my $set = shift;
160              
161 115 50       332 if (not defined $set) {
162 0         0 $self->{Format} = undef;
163             } else {
164 115         368 $self->{Format} = $set;
165             }
166              
167             }
168              
169             sub title {
170              
171 34     34 1 80 my $self = shift;
172              
173 34         159 return $self->{Title};
174              
175             }
176              
177             sub set_title {
178              
179 115     115 1 264 my $self = shift;
180 115         305 my $set = shift;
181              
182 115 50       339 if (not defined $set) {
183 0         0 $self->{Title} = $set;
184             } else {
185 115         434 $self->{Title} = $set;
186             }
187              
188             }
189              
190             sub language {
191              
192 22     22 1 64 my $self = shift;
193              
194 22 100       131 return defined $self->{Language} ? @{ $self->{Language} } : ();
  1         10  
195              
196             }
197              
198             sub set_language {
199              
200 10     10 1 22 my $self = shift;
201 10         31 my @set = grep { defined } @_;
  10         77  
202              
203 10 50       28 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 105 my $self = shift;
214 51         160 my @add = grep { defined } @_;
  51         240  
215              
216 51         85 push @{ $self->{Language} }, @add;
  51         239  
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 28 my $self = shift;
244 10         21 my @add = grep { defined } @_;
  10         30  
245              
246 10         14 push @{ $self->{Genre} }, @add;
  10         43  
247              
248             }
249              
250             sub id {
251              
252 1     1 1 3 my $self = shift;
253              
254 1         6 return $self->{ID};
255              
256             }
257              
258             sub set_id {
259              
260 30     30 1 50 my $self = shift;
261 30         48 my $set = shift;
262              
263 30 50       66 if (not defined $set) {
264 0         0 $self->{ID} = undef;
265             } else {
266 30         96 $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       5 return defined $self->{Contributor} ? @{ $self->{Contributor} } : ();
  1         8  
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 78 my $self = shift;
316 40         107 my @add = grep { defined } @_;
  40         126  
317              
318 40         73 push @{ $self->{Contributor} }, @add;
  40         183  
319              
320             }
321              
322             =head1 NAME
323              
324             EBook::Ishmael::EBook::Metadata - Ebook metadata interface
325              
326             =head1 SYNOPSIS
327              
328             use EBook::Ishmael::EBook::Metadata;
329              
330             my $meta = EBook::Ishmael::EBook::Metadata->new;
331              
332             $meta->title([ 'Moby-Dick' ]);
333             $meta->author([ 'Herman Melville' ]);
334             $meta->language([ 'en' ]);
335              
336             =head1 DESCRIPTION
337              
338             B is a module used by L to provide
339             a format-agnostic interface to ebook metadata. This is developer documentation,
340             for user documentation please consult the L manual.
341              
342             =head1 METHODS
343              
344             =head2 $m = EBook::Ishmael::EBook::Metadata->new()
345              
346             Returns a blessed C object.
347              
348             =head2 $h = $m->hash
349              
350             Returns a plain hash ref of the object's metadata.
351              
352             =head2 Accessors
353              
354             =head3 @a = $m->author()
355              
356             =head3 $m->set_author(@a)
357              
358             =head3 $m->add_author(@a)
359              
360             Set/get the author(s) of the ebook.
361              
362             =head3 $s = $m->software()
363              
364             =head3 $m->set_software($s)
365              
366             Set/get the software used to create the ebook.
367              
368             =head3 $c = $m->created()
369              
370             =head3 $m->set_created($c)
371              
372             Set/get the creation date of the ebook.
373              
374             =head3 $o = $m->modified()
375              
376             =head3 $m->set_modified($o)
377              
378             Set/get the modification date of the ebook.
379              
380             =head3 $f = $m->format()
381              
382             =head3 $m->set_format($f)
383              
384             Set/get the format of the ebook.
385              
386             =head3 $t = $m->title()
387              
388             =head3 $m->set_title($t)
389              
390             Set/get the title of the ebook.
391              
392             =head3 @l = $m->language()
393              
394             =head3 $m->set_language(@l)
395              
396             =head3 $m->add_language(@l)
397              
398             Set/get the language(s) of the ebook.
399              
400             =head3 @g = $m->genre()
401              
402             =head3 $m->set_genre(@g)
403              
404             =head3 $m->add_genre(@a)
405              
406             Set/get the genre(s) of the ebook.
407              
408             =head3 $i = $m->id()
409              
410             =head3 $m->set_id($i)
411              
412             Set/get the identifier of the ebook.
413              
414             =head3 $d = $m->description()
415              
416             =head3 $m->set_description($d)
417              
418             Set/get the text description of the ebook.
419              
420             =head3 @c = $m->contributor()
421              
422             =head3 $m->set_contributor(@c)
423              
424             =head3 $m->add_contributor(@c)
425              
426             Set/get the contributor(s) of the ebook.
427              
428             =head1 AUTHOR
429              
430             Written by Samuel Young, Esamyoung12788@gmail.comE.
431              
432             This project's source can be found on its
433             L. Comments and pull
434             requests are welcome!
435              
436             =head1 COPYRIGHT
437              
438             Copyright (C) 2025-2026 Samuel Young
439              
440             This program is free software: you can redistribute it and/or modify
441             it under the terms of the GNU General Public License as published by
442             the Free Software Foundation, either version 3 of the License, or
443             (at your option) any later version.
444              
445             =cut