| 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 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | 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 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 38 | 1 | 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 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 1 | handles => { | |||||||||
| 50 | emails => 'elements', | ||||||||||
| 51 | add_email => 'push', | ||||||||||
| 52 | }, | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | sub load | ||||||||||
| 56 | 0 | ▶ | { | ||||||||
|
Subroutine
load: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||
| 57 | 0 | my ($self, $node) = @_; | |||||||||
| 58 | |||||||||||
| 59 | 0 | my @nodes = $node->findnodes('first-name'); | |||||||||
| 60 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $self->first_name($nodes[0]->string_value()); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | @nodes = $node->findnodes('middle-name'); | |||||||||
| 65 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $self->middle_name($nodes[0]->string_value()); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | @nodes = $node->findnodes('last-name'); | |||||||||
| 70 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | $self->last_name($nodes[0]->string_value()); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | @nodes = $node->findnodes('nickname'); | |||||||||
| 75 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | $self->nickname($nodes[0]->string_value()); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | @nodes = $node->findnodes('home-page'); | |||||||||
| 80 | 0 | foreach my $n (@nodes) { | |||||||||
| 81 | 0 | $self->add_home_page($n->string_value()); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 0 | @nodes = $node->findnodes('email'); | |||||||||
| 85 | 0 | foreach my $n (@nodes) { | |||||||||
| 86 | 0 | $self->add_email($n->string_value()); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | @nodes = $node->findnodes('id'); | |||||||||
| 90 | 0 | ▶ | if (@nodes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | $self->id($nodes[0]->string_value()); | |||||||||
| 92 | } | ||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | sub to_str | ||||||||||
| 96 | 0 | ▶ | { | ||||||||
|
Subroutine
to_str: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 97 | 0 | my $self = shift; | |||||||||
| 98 | 0 | my $name = $self->first_name; | |||||||||
| 99 | 0 | ▶ | $name .= ' ' . $self->middle_name if defined($self->middle_name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | ▶ | if ($name ne '') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | ▶ | $name .= ' "' . $self->nickname . '"' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | if defined($self->nickname); | ||||||||||
| 103 | } | ||||||||||
| 104 | else { | ||||||||||
| 105 | 0 | ▶ | $name = $self->nickname if defined($self->nickname); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | $name .= ' ' . $self->last_name if defined($self->last_name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | return $name; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 1 | 1; | |||||||||
| 114 | |||||||||||
| 115 | __END__ | ||||||||||