| 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::TitleInfo; | ||||||||||
| 26 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use EBook::FB2::Description::Author; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ▶ | use EBook::FB2::Description::Genre; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use EBook::FB2::Description::Sequence; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 1 | has [qw/book_title keywords date lang src_lang/] => ( | |||||||||
| 32 | isa => 'Str', | ||||||||||
| 33 | is => 'rw' | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | 1 | has annotation => ( isa => 'Ref', is => 'rw' ); | |||||||||
| 37 | |||||||||||
| 38 | has _genres => ( | ||||||||||
| 39 | traits => ['Array'], | ||||||||||
| 40 | isa => 'ArrayRef[Object]', | ||||||||||
| 41 | is => 'rw', | ||||||||||
| 42 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 1 | handles => { | |||||||||
| 44 | genres => 'elements', | ||||||||||
| 45 | add_genre => 'push', | ||||||||||
| 46 | }, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | has _authors => ( | ||||||||||
| 50 | traits => ['Array'], | ||||||||||
| 51 | isa => 'ArrayRef[Object]', | ||||||||||
| 52 | is => 'rw', | ||||||||||
| 53 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 54 | 1 | handles => { | |||||||||
| 55 | authors => 'elements', | ||||||||||
| 56 | add_author => 'push', | ||||||||||
| 57 | }, | ||||||||||
| 58 | ); | ||||||||||
| 59 | |||||||||||
| 60 | has _translators => ( | ||||||||||
| 61 | traits => ['Array'], | ||||||||||
| 62 | isa => 'ArrayRef[Object]', | ||||||||||
| 63 | is => 'rw', | ||||||||||
| 64 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | 1 | handles => { | |||||||||
| 66 | translators => 'elements', | ||||||||||
| 67 | add_translator => 'push', | ||||||||||
| 68 | }, | ||||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | has _sequences => ( | ||||||||||
| 72 | traits => ['Array'], | ||||||||||
| 73 | isa => 'ArrayRef[Object]', | ||||||||||
| 74 | is => 'rw', | ||||||||||
| 75 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | 1 | handles => { | |||||||||
| 77 | sequences => 'elements', | ||||||||||
| 78 | add_sequence => 'push', | ||||||||||
| 79 | }, | ||||||||||
| 80 | ); | ||||||||||
| 81 | |||||||||||
| 82 | has _coverpages => ( | ||||||||||
| 83 | traits => ['Array'], | ||||||||||
| 84 | isa => 'ArrayRef[Str]', | ||||||||||
| 85 | is => 'rw', | ||||||||||
| 86 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 87 | 1 | handles => { | |||||||||
| 88 | coverpages => 'elements', | ||||||||||
| 89 | add_coverpage => 'push', | ||||||||||
| 90 | }, | ||||||||||
| 91 | ); | ||||||||||
| 92 | |||||||||||
| 93 | sub load | ||||||||||
| 94 | 0 | ▶ | { | ||||||||
|
Subroutine
load: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||
| 95 | 0 | my ($self, $node) = @_; | |||||||||
| 96 | |||||||||||
| 97 | 0 | my @nodes = $node->findnodes('book-title'); | |||||||||
| 98 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | $self->book_title($nodes[0]->string_value); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | @nodes = $node->findnodes('keywords'); | |||||||||
| 103 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 0 | $self->keywords($nodes[0]->string_value); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | @nodes = $node->findnodes('lang'); | |||||||||
| 108 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | $self->lang($nodes[0]->string_value); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 0 | @nodes = $node->findnodes('src-lang'); | |||||||||
| 113 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | $self->src_lang($nodes[0]->string_value); | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 0 | @nodes = $node->findnodes('date'); | |||||||||
| 118 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | # TODO: parse node to ::Data object | ||||||||||
| 120 | 0 | $self->date($nodes[0]->string_value); | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | # Now handle multiple entities | ||||||||||
| 124 | 0 | @nodes = $node->findnodes('author'); | |||||||||
| 125 | 0 | foreach my $node (@nodes) { | |||||||||
| 126 | 0 | my $author = EBook::FB2::Description::Author->new; | |||||||||
| 127 | 0 | $author->load($node); | |||||||||
| 128 | 0 | $self->add_author($author); | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 0 | @nodes = $node->findnodes('translator'); | |||||||||
| 132 | 0 | foreach my $node (@nodes) { | |||||||||
| 133 | 0 | my $translator = EBook::FB2::Description::Author->new; | |||||||||
| 134 | 0 | $translator->load($node); | |||||||||
| 135 | 0 | $self->add_translator($translator); | |||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | 0 | @nodes = $node->findnodes('genre'); | |||||||||
| 139 | 0 | foreach my $node (@nodes) { | |||||||||
| 140 | 0 | my $genre = EBook::FB2::Description::Genre->new; | |||||||||
| 141 | 0 | $genre->load($node); | |||||||||
| 142 | 0 | $self->add_genre($genre); | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 0 | @nodes = $node->findnodes('sequence'); | |||||||||
| 146 | 0 | foreach my $node (@nodes) { | |||||||||
| 147 | 0 | my $seq = EBook::FB2::Description::Sequence->new; | |||||||||
| 148 | 0 | $seq->load($node); | |||||||||
| 149 | 0 | $self->add_sequence($seq); | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 0 | @nodes = $node->findnodes('coverpage/image'); | |||||||||
| 153 | 0 | foreach my $node (@nodes) { | |||||||||
| 154 | 0 | my $map = $node->getAttributes; | |||||||||
| 155 | # find href attribute, a litle bit hackerish | ||||||||||
| 156 | 0 | my $i = 0; | |||||||||
| 157 | 0 | ▶ | while ($i < $map->getLength) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 0 | my $item = $map->item($i); | |||||||||
| 159 | 0 | ▶ | if ($item->getName =~ /:href/i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | 0 | my $id = $item->getValue; | |||||||||
| 161 | 0 | $id =~ s/^#//; | |||||||||
| 162 | 0 | $self->add_coverpage($id); | |||||||||
| 163 | } | ||||||||||
| 164 | 0 | $i++; | |||||||||
| 165 | } | ||||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | 0 | @nodes = $node->findnodes('annotation'); | |||||||||
| 169 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | 0 | $self->annotation($nodes[0]); | |||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | |||||||||||
| 174 | } | ||||||||||
| 175 | |||||||||||
| 176 | 1 | 1; | |||||||||
| 177 | |||||||||||
| 178 | __END__ | ||||||||||