FB2/Body.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« FB2.pm ↑ Summary FB2/Body/Section.pm »
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::Body;
26 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 0 ▶use EBook::FB2::Body::Section;
Subroutine BEGIN: called CC=1 SCAR=2.6
28  
29 has name => ( isa => 'Str', is => 'rw' );
30 has title => ( isa => 'Ref', is => 'rw' );
31 has _epigraphs => (
32 isa => 'ArrayRef',
33 is => 'ro',
34 traits => ['Array'],
35 default => sub { [] },
36 handles => {
37 epigraphs => 'elements',
38 add_epigraph => 'push',
39 }
40 );
41 has image => ( isa => 'Str', is => 'rw' );
42 has _sections => (
43 isa => 'ArrayRef',
44 is => 'ro',
45 traits => ['Array'],
46 default => sub { [] },
47 handles => {
48 sections => 'elements',
49 add_section => 'push',
50 }
51 );
52  
53 sub load
54 {
55 my ($self, $node) = @_;
56  
57 my $anode = $node->getAttribute("name");
58 if (defined($anode)) {
59 $self->name($anode);
60 }
61  
62 my @nodes = $node->findnodes("title");
63 if (@nodes) {
64 $self->title($nodes[0]);
65 }
66 @nodes = $node->findnodes("epigraph");
67 foreach my $n (@nodes) {
68 $self->add_epigraph($n);
69 }
70  
71 @nodes = $node->findnodes("image");
72 if (@nodes) {
73 my $map = $nodes[0]->getAttributes;
74 # find href attribute, a litle bit hackerish
75 my $i = 0;
76 while ($i < $map->getLength) {
77 my $item = $map->item($i);
78 if ($item->getName =~ /:href/i) {
79 my $id = $item->getValue;
80 $id =~ s/^#//;
81 $self->image($id);
82 last;
83 }
84 $i++;
85 }
86 }
87  
88 @nodes = $node->findnodes("section");
89 foreach my $n (@nodes) {
90 my $s = EBook::FB2::Body::Section->new();
91 $s->load($n);
92 $self->add_section($s);
93 }
94 }
95  
96 1;
97  
98 __END__
« FB2.pm ↑ Summary FB2/Body/Section.pm »