File Coverage

blib/lib/EBook/FB2/Description.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             # Copyright (c) 2009, 2010 Oleksandr Tymoshenko <gonzo@bluezbox.com>
2             # All rights reserved.
3              
4             # Redistribution and use in source and binary forms, with or without
5             # modification, are permitted provided that the following conditions
6             # are met:
7             # 1. Redistributions of source code must retain the above copyright
8             # notice, this list of conditions and the following disclaimer.
9             # 2. Redistributions in binary form must reproduce the above copyright
10             # notice, this list of conditions and the following disclaimer in the
11             # documentation and/or other materials provided with the distribution.
12              
13             # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14             # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15             # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16             # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17             # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18             # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19             # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20             # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21             # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22             # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23             # SUCH DAMAGE.
24              
25             package EBook::FB2::Description;
26              
27 1     1   1750 use Moose;
  0            
  0            
28              
29             use EBook::FB2::Description::CustomInfo;
30             use EBook::FB2::Description::DocumentInfo;
31             use EBook::FB2::Description::PublishInfo;
32             use EBook::FB2::Description::TitleInfo;
33              
34             has 'title_info' => (
35             isa => 'Object',
36             is => 'rw',
37             handles => {
38             book_title => 'book_title',
39             authors => 'authors',
40             translators => 'translators',
41             sequences => 'sequences',
42             genres => 'genres',
43             lang => 'lang',
44             src_lang => 'src_lang',
45             date => 'date',
46             keywords => 'keywords',
47             coverpages => 'coverpages',
48             },
49             );
50              
51             has 'src_title_info' => (
52             isa => 'Object',
53             is => 'rw',
54             handles => {
55             src_book_title => 'book_title',
56             src_authors => 'authors',
57             src_translators => 'translators',
58             src_sequences => 'sequences',
59             src_genres => 'genres',
60             src_date => 'date',
61             src_keywords => 'keywords',
62             src_coverpages => 'coverpages',
63             },
64             );
65              
66             has 'publish_info' => (
67             isa => 'Object',
68             is => 'rw',
69             handles => {
70             publication_title => 'book_name',
71             publisher => 'publisher',
72             publication_city => 'city',
73             publication_year => 'year',
74             isbn => 'isbn',
75             },
76             );
77              
78              
79             has 'document_info' => (
80             isa => 'Object',
81             is => 'rw',
82             handles => {
83             document_publishers => 'publishers',
84             document_src_urls => 'src_urls',
85             document_authors => 'authors',
86             document_program_used => 'program_used',
87             document_date => 'date',
88             document_src_ocr => 'src_ocr',
89             document_id => 'id',
90             document_version => 'version',
91             document_history => 'history',
92             },
93             );
94              
95             has '_custom_infos' => (
96             isa => 'ArrayRef[Object]',
97             is => 'ro',
98             traits => ['Array'],
99             default => sub { [] },
100             handles => {
101             custom_infos => 'elements',
102             add_custom_info => 'push',
103             },
104             );
105              
106             sub load
107             {
108             my ($self, $node) = @_;
109             my @title_info_nodes = $node->findnodes('title-info');
110              
111             if (@title_info_nodes != 1) {
112             warn ("Wrong number of <title-info> element");
113             return;
114             }
115              
116             my $title_info = EBook::FB2::Description::TitleInfo->new();
117             $title_info->load( $title_info_nodes[0]);
118             $self->title_info($title_info);
119              
120             my @src_title_info_nodes = $node->findnodes('src-title-info');
121              
122             if (@src_title_info_nodes > 1) {
123             warn ("Wrong number of <src-title-info> element");
124             return;
125             }
126              
127             if (@src_title_info_nodes) {
128             my $src_title_info = EBook::FB2::Description::TitleInfo->new();
129             $src_title_info->load( $src_title_info_nodes[0]);
130             $self->src_title_info($src_title_info);
131             }
132              
133             my @publish_info_nodes = $node->findnodes('publish-info');
134              
135             if (@publish_info_nodes > 1) {
136             warn ("Wrong number of <publish-info> element");
137             return;
138             }
139              
140             if (@publish_info_nodes) {
141             my $publish_info = EBook::FB2::Description::PublishInfo->new();
142             $publish_info->load( $publish_info_nodes[0]);
143             $self->publish_info($publish_info);
144             }
145              
146             my @document_info_nodes = $node->findnodes('document-info');
147              
148             if (@document_info_nodes != 1) {
149             warn ("Wrong number of <document-info> element");
150             return;
151             }
152              
153             my $document_info = EBook::FB2::Description::DocumentInfo->new();
154             $document_info->load( $document_info_nodes[0]);
155             $self->document_info($document_info);
156              
157             my @custom_info_nodes = $node->findnodes('custom-info');
158              
159             foreach my $n (@custom_info_nodes) {
160             my $custom_info = EBook::FB2::Description::CustomInfo->new();
161             $custom_info->load( $n );
162             $self->add_custom_info($custom_info);
163             }
164              
165             }
166              
167             1;
168              
169             __END__
170             =head1 NAME
171              
172             EBook::FB2::Description
173              
174             =head1 SYNOPSIS
175              
176             EBook::FB2::Description - FB2 document metadata
177              
178             =head1 SUBROUTINES/METHODS
179              
180             =over 4
181              
182             =item title_info()
183              
184             Returns reference to L<EBook::FB2::Description::TitleInfo> object that
185             contains book metadata.
186              
187             =item src_title_info()
188              
189             Returns reference to L<EBook::FB2::Description::TitleInfo> object that
190             contains original book metadata. Valid if book is translation.
191              
192             =item publish_info()
193              
194             Returns reference to L<EBook::FB2::Description::PublicationInfo>
195              
196              
197             =item document_info()
198              
199             Returns reference to L<EBook::FB2::Description::DocumentInfo> object that
200             contains document metadata: program used, OCR info, etc.
201              
202             =item custom_infos()
203              
204             Returns list of references to L<EBook::FB2::Description::CustomInfo> objects
205              
206             =back
207              
208             =head1 FORWARDED METHODS
209              
210             These methods provided to make access to document metada easier and generally
211             they are just forwarders to B<title_info>, B<src_title_info>, B<document_info>,
212             B<publish_info> members
213              
214             # these are the same
215             my $src_title = $fb2->desciption->src_book_title;
216             my $src_title = $fb2->desciption->src_title_info->book_title;
217              
218             # these are the same
219             my $isbn = $fb2->desciption->isbn;
220             my $isbn = $fb2->desciption->publication_info->isbn;
221              
222            
223             You've got the idea...
224              
225             =over 4
226              
227             =item annotation()
228              
229             Returns reference to XML::DOM::Node, parsed annotation
230              
231             =item authors()
232              
233             Returns list of book authors (references to L<EBook::FB2::Description::Author>)
234              
235             =item book_title()
236              
237             Returns book title
238              
239             =item coverpages()
240              
241             Returns list of ids that references to images with original cover artwork
242              
243             =item date()
244              
245             Returns book creation date
246              
247             =item document_authors()
248              
249             Returns document(fb2) creators
250              
251             =item document_date()
252              
253             Returns document(fb2) moification/creation date
254              
255             =item document_history()
256              
257             Returns document(fb2) history
258              
259             =item document_id()
260              
261             Returns document(fb2) id
262              
263             =item document_program_used()
264              
265             Returns program that has been used for generating this document
266              
267             =item document_publishers()
268              
269             Returns publisher of FB2 document (not book)
270              
271             =item document_src_ocr()
272              
273             Returns OCR author
274              
275             =item document_src_urls()
276              
277             Returns source URL of original document
278              
279             =item document_version()
280              
281             Return document version
282              
283             =item genres()
284              
285             Returns list of genres book falls in (references to
286             L<EBook::FB2::Description::Genre>)
287              
288             =item isbn()
289              
290             Returns book ISBN
291              
292             =item keywords()
293              
294             Returns book keyword
295              
296             =item lang()
297              
298             Return book languagage: "ru", "en", etc...
299              
300             =item publication_city()
301              
302             Returns city where book has been published
303              
304             =item publication_title()
305              
306             Returns original publication title
307              
308             =item publication_year()
309              
310             Returns publication year
311              
312             =item publisher()
313              
314             Returns book publisher
315              
316             =item sequences()
317              
318             Returns list of sequences book belongs to (references to L<EBook::FB2::Description::Sequence>)
319              
320             =item src_authors()
321              
322             See L<authors>. Valid if book is translation.
323              
324             =item src_book_title()
325              
326             See L<book_title>. Valid if book is translation.
327              
328             =item src_coverpages()
329              
330             See L<coverpages>. Valid if book is translation.
331              
332             =item src_date()
333              
334             See L<date>. Valid if book is translation.
335              
336             =item src_genres()
337              
338             See L<genres>. Valid if book is translation.
339              
340             =item src_keywords()
341              
342             See L<keywords>. Valid if book is translation.
343              
344             =item src_lang()
345              
346             Original book language. Valid if book is translation.
347              
348             =item src_sequences()
349              
350             See L<sequences>. Valid if book is translation.
351              
352             =item translators()
353              
354             Returns list of translators represented by references to
355             L<EBook::FB2::Description::Author> objects;
356              
357             =back
358              
359             =head1 AUTHOR
360              
361             Oleksandr Tymoshenko, E<lt>gonzo@bluezbox.comE<gt>
362              
363             =head1 BUGS
364              
365             Please report any bugs or feature requests to E<lt>gonzo@bluezbox.comE<gt>
366              
367             =head1 LICENSE AND COPYRIGHT
368              
369             Copyright 2009, 2010 Oleksandr Tymoshenko.
370              
371             L<http://bluezbox.com>
372              
373             This module is free software; you can redistribute it and/or
374             modify it under the terms of the BSD license. See the F<LICENSE> file
375             included with this distribution.