blib/lib/Acme/MorningMusume/Base.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 100% 49 / 49 CC 4 SCAR 5.5
CC
4
Cov
100%
_calculate_age
3.0
_initialize
2.0
BEGIN
1.0
CRAP 1.7
« Build ↑ Summary _build/lib/MyBuilder.pm »
1 package Acme::MorningMusume::Base;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.18';
9  
10 2 __PACKAGE__->mk_accessors(qw(
11 name_ja
12 first_name_ja
13 family_name_ja
14 name_en
15 first_name_en
16 family_name_en
17 nick
18 birthday
19 age
20 blood_type
21 hometown
22 emoticon
23 class
24 graduate_date
25 ));
26  
27 sub new {
28 76 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
29 76 my $self = bless {}, $class;
30  
31 76 $self->_initialize;
32  
33 76 return $self;
34 }
35  
36 sub _initialize {
37 76 ▶ my $self = shift;
Subroutine _initialize: called CC=2 SCAR=6.9
38 76 my %info = $self->info;
39  
40 76 $self->{$_} = $info{$_} for keys %info;
41 76 $self->{name_ja} = $self->family_name_ja.$self->first_name_ja;
42 76 $self->{name_en} = $self->first_name_en.' '.$self->family_name_en;
43 76 $self->{age} = $self->_calculate_age;
44  
45 76 return 1;
46 }
47  
48 sub _calculate_age {
49 76 ▶ my $self = shift;
Subroutine _calculate_age: called CC=3 SCAR=11.0
50 76 my $today = DateTime->today;
51  
52 76 ▶ if (($today->month - $self->birthday->month) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($today->month - $self->birthday->month >= 0) { } 50 26 76
53 50 ▶ if (($today->day - $self->birthday->day ) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($today->day - $self->birthday->day >= 0) { } 4 46 50
54 4 return $today->year - $self->birthday->year;
55 } else {
56 46 return ($today->year - $self->birthday->year) - 1;
57 }
58 } else {
59 26 return ($today->year - $self->birthday->year) - 1;
60 }
61 }
62  
63 sub _datetime_from_date {
64 126 ▶ my ($self, $date) = @_;
Subroutine _datetime_from_date: called CC=1 SCAR=0.0
65 126 my ($year, $month, $day) = ($date =~ /(\d{4})-(\d{2})-(\d{2})/);
66  
67 126 DateTime->new(
68 year => $year,
69 month => $month,
70 day => $day,
71 );
72 }
73  
74 2 1;
75  
76 __END__
77  
78 =head1 NAME
79  
80 Acme::MorningMusume::Base - A baseclass of the class represents each
81 member of Morning Musume
82  
83 =head1 SYNOPSIS
84  
85 use Acme::MorningMusume;
86  
87 my $musume = Acme::MorningMusume->new;
88  
89 # retrieve the members as a list of
90 # Acme::MorningMusume::Base based objects
91 my @members = $musume->members;
92  
93 for my $member (@members) {
94 my $name_ja = $member->name_ja;
95 my $first_name_ja = $member->first_name_ja;
96 my $family_name_ja = $member->family_name_ja;
97 my $name_en = $member->name_en;
98 my $first_name_en = $member->first_name_en;
99 my $family_name_en = $member->family_name_en;
100 my $nick = $member->nick; # arrayref
101 my $birthday = $member->birthday; # DateTime object
102 my $age = $member->age;
103 my $blood_type = $member->blood_type;
104 my $hometown = $member->hometown;
105 my $emoticon = $member->emoticon; # arrayref
106 my $class = $member->class;
107 my $graduate_date = $member->graduate_date; # DateTime object
108 }
109  
110 =head1 DESCRIPTION
111  
112 Acme::MorningMusume::Base is a baseclass of the class represents each
113 member of Morning Musume.
114  
115 =head1 ACCESSORS
116  
117 =head2 name_ja
118  
119 =head2 first_name_ja
120  
121 =head2 family_name_ja
122  
123 =head2 name_en
124  
125 =head2 first_name_en
126  
127 =head2 family_name_en
128  
129 =head2 nick
130  
131 =head2 birthday
132  
133 =head2 age
134  
135 =head2 blood_type
136  
137 =head2 hometown
138  
139 =head2 emoticon
140  
141 =head2 class
142  
143 =head2 graduate_date
144  
145 =head1 SEE ALSO
146  
147 =over 4
148  
149 =item * L<DateTime>
150  
151 =back
152  
153 =head1 AUTHOR
154  
155 Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
156  
157 =head1 COPYRIGHT AND LICENSE (The MIT License)
158  
159 Copyright (c) 2005 - 2007, Kentaro Kuribayashi
160 E<lt>kentaro@cpan.orgE<gt>
161  
162 Permission is hereby granted, free of charge, to any person obtaining
163 a copy of this software and associated documentation files (the
164 "Software"), to deal in the Software without restriction, including
165 without limitation the rights to use, copy, modify, merge, publish,
166 distribute, sublicense, and/or sell copies of the Software, and to
167 permit persons to whom the Software is furnished to do so, subject to
168 the following conditions:
169  
170 The above copyright notice and this permission notice shall be
171 included in all copies or substantial portions of the Software.
172  
173 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
174 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
175 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
176 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
177 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
178 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
179 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
180  
181 =cut
« Build ↑ Summary _build/lib/MyBuilder.pm »