File Coverage

blib/lib/EBook/FB2/Description/Author.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::Author;
26 1     1   1901 use Moose;
  0            
  0            
27              
28             has [qw/first_name middle_name last_name nickname id/] => (
29             isa => 'Str',
30             is => 'rw'
31             );
32              
33             has _home_pages => (
34             isa => 'ArrayRef',
35             is => 'ro',
36             traits => ['Array'],
37             default => sub { [] },
38             handles => {
39             home_pages => 'elements',
40             add_home_page => 'push',
41             },
42             );
43              
44             has _emails => (
45             isa => 'ArrayRef',
46             is => 'ro',
47             traits => ['Array'],
48             default => sub { [] },
49             handles => {
50             emails => 'elements',
51             add_email => 'push',
52             },
53             );
54              
55             sub load
56             {
57             my ($self, $node) = @_;
58              
59             my @nodes = $node->findnodes('first-name');
60             if (@nodes) {
61             $self->first_name($nodes[0]->string_value());
62             }
63              
64             @nodes = $node->findnodes('middle-name');
65             if (@nodes) {
66             $self->middle_name($nodes[0]->string_value());
67             }
68              
69             @nodes = $node->findnodes('last-name');
70             if (@nodes) {
71             $self->last_name($nodes[0]->string_value());
72             }
73              
74             @nodes = $node->findnodes('nickname');
75             if (@nodes) {
76             $self->nickname($nodes[0]->string_value());
77             }
78              
79             @nodes = $node->findnodes('home-page');
80             foreach my $n (@nodes) {
81             $self->add_home_page($n->string_value());
82             }
83              
84             @nodes = $node->findnodes('email');
85             foreach my $n (@nodes) {
86             $self->add_email($n->string_value());
87             }
88              
89             @nodes = $node->findnodes('id');
90             if (@nodes) {
91             $self->id($nodes[0]->string_value());
92             }
93             }
94              
95             sub to_str
96             {
97             my $self = shift;
98             my $name = $self->first_name;
99             $name .= ' ' . $self->middle_name if defined($self->middle_name);
100             if ($name ne '') {
101             $name .= ' "' . $self->nickname . '"'
102             if defined($self->nickname);
103             }
104             else {
105             $name = $self->nickname if defined($self->nickname);
106             }
107              
108             $name .= ' ' . $self->last_name if defined($self->last_name);
109              
110             return $name;
111             }
112              
113             1;
114              
115             __END__
116             =head1 NAME
117              
118             EBook::FB2::Description::Author
119              
120             =head1 SYNOPSIS
121              
122             EBook::FB2::Description::Author - person description: author/translator
123              
124             =head1 SUBROUTINES/METHODS
125              
126             =over 4
127              
128             =item emails()
129              
130             Returns list of person's email addresses
131              
132             =item first_name()
133              
134             Returns persons's first name
135              
136             =item home_pages()
137              
138             Returns persons's homepage
139              
140             =item id()
141              
142             Returns persons's identifier assigned by the library
143              
144             =item last_name()
145              
146             TODO: document last_name()
147              
148             Returns person's last name
149              
150             =item middle_name()
151              
152             Returns person's middle name
153              
154             =item nickname()
155              
156             Returns person's nickname
157              
158             =item to_str()
159              
160             Returns string representation
161              
162              
163              
164             =back
165              
166             =head1 AUTHOR
167              
168             Oleksandr Tymoshenko, E<lt>gonzo@bluezbox.comE<gt>
169              
170             =head1 BUGS
171              
172             Please report any bugs or feature requests to E<lt>gonzo@bluezbox.comE<gt>
173              
174             =head1 LICENSE AND COPYRIGHT
175              
176             Copyright 2009, 2010 Oleksandr Tymoshenko.
177              
178             L<http://bluezbox.com>
179              
180             This module is free software; you can redistribute it and/or
181             modify it under the terms of the BSD license. See the F<LICENSE> file
182             included with this distribution.