blib/lib/Acme/MorningMusume.pm

filter: Statementstmt 71.9% 41 / 57 Branchbran 50.0% 10 / 20 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 70.0% 7 / 10 Podpod 100% 4 / 4 totaltotal 69.0% 69 / 100 CC 13 SCAR 19.0
CC
13
Cov
67%
sort
12.0
select
12.0
members
8.1
CRAP 6.7
↑ Summary blib/lib/Acme/MorningMusume/Base.pm »
1 package Acme::MorningMusume;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.19';
10  
11 3 my @members = qw(
12 FukudaAsuka
13 NakazawaYuko
14 IidaKaori
15 AbeNatsumi
16 IshiguroAya
17 IchiiSayaka
18 YaguchiMari
19 YasudaKei
20 GotohMaki
21 IshikawaRika
22 YoshizawaHitomi
23 TsujiNozomi
24 KagoAi
25 TakahashiAi
26 KonnoAsami
27 OgawaMakoto
28 NiigakiRisa
29 KameiEri
30 TanakaReina
31 MichishigeSayumi
32 FujimotoMiki
33 KusumiKoharu
34 MitsuiAika
35 LiChun
36 QianLin
37 SuzukiKanon
38 IkutaErina
39 FukumuraMizuki
40 SayashiRiho
41 IikuboHaruna
42 IshidaAyumi
43 SatohMasaki
44 KudohHaruka
45 OdaSakura
46 OgataHaruna
47 NonakaMiki
48 MakinoMaria
49 HagaAkane
50 );
51  
52 my @date_joined = map {
53 3 my ($year, $month, $day) = ($_ =~ /(\d{4})-(\d{2})-(\d{2})/);
54 36 DateTime->new(
55 year => $year,
56 month => $month,
57 day => $day,
58 );
59 } qw(
60 1997-09-07
61 1998-05-03
62 1999-08-04
63 2000-04-16
64 2001-08-26
65 2003-01-19
66 2005-05-01
67 2006-12-10
68 2011-01-02
69 2011-09-29
70 2012-09-14
71 2014-09-30
72 );
73 3 unshift @date_joined, undef;
74  
75 sub new {
76 2 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77 2 my $self = bless {members => []}, $class;
78  
79 2 $self->_initialize;
80  
81 2 return $self;
82 }
83  
84 sub members {
85 5 ▶ my ($self, $type, @members) = @_;
Subroutine members: called CC=8 SCAR=20.9
Pod documented
86 5 ▶ @members = @{$self->{members}} unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 5 0 5
87  
88 5 ▶ return @members unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 2 3 5
89  
90 3 ▶ if ($type eq 'active') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'active') { } 1 2 3
elsif ($type eq 'graduate') { } 1 1 2
elsif ($type->isa('DateTime')) { } 1 0 1
91 1 return grep {!$_->graduate_date} @members;
92 }
93 elsif ($type eq 'graduate') {
94 1 return grep {$_->graduate_date} @members;
95 }
96 elsif ($type->isa('DateTime')) {
97 return grep {
98 1 ▶ $date_joined[$_->class] <= $type and
Branch: 1 branch
BranchTrueFalseTotal
$date_joined[$_->class] <= $type and !$_->graduate_date || $type <= $_->graduate_date 13 25 38
Condition83%5/6
$date_joined[$_->class] <= $type && (!$_->graduate_date || $type <= $_->graduate_date)
!ll&&!rl&&r
25310
not $_->graduate_date or $type <= $_->graduate_date
l!l&&r!l&&!r
0103
MC/DC66%2/3
$date_joined[$_->class] <= $type && (!$_->graduate_date || $type <= $_->graduate_date)
$date_joined[$_->class] <= $type not $_->graduate_date $type <= $_->graduate_date
Truth table75%3/4
A && not(B) or C
A= $date_joined[$_->class] <= $typeB= not $_->graduate_dateC= $type <= $_->graduate_date
ABCresult
0XX0
1000
11X1
1011
99 (!$_->graduate_date or $type <= $_->graduate_date)
100 } @members;
101 }
102 }
103  
104 sub sort {
105 0 ▶ my ($self, $type, $order, @members) = @_;
Subroutine sort: not called CC=3 SCAR=24.8
Pod documented
106 0 ▶ @members = $self->members unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 0 0 0
107  
108 # order by desc if $order is true
109 0 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) { } 0 0 0
110 0 return sort {$b->$type <=> $a->$type} @members;
111 }
112 else {
113 0 return sort {$a->$type <=> $b->$type} @members;
114 }
115 }
116  
117 sub select {
118 0 ▶ my ($self, $type, $number, $operator, @members) = @_;
Subroutine select: not called CC=3 SCAR=24.8
Pod documented
119  
120 $self->_die('invalid operator was passed in')
121 0 ▶ unless grep {$operator eq $_} qw(== >= <= > <);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$operator eq $_;} "==", ">=", "<=", ">", "<" 0 0 0
122  
123 0 ▶ @members = $self->members unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 0 0 0
124 0 my $compare = eval "(sub { \$number $operator \$_[0] })";
125  
126 0 return grep { $compare->($_->$type) } @members;
127 }
128  
129 sub _initialize {
130 2 ▶ my $self = shift;
Subroutine _initialize: called CC=2 SCAR=6.9
131  
132 2 for my $member (@members) {
133 76 my $module_name = 'Acme::MorningMusume::'.$member;
134  
135 76 eval qq|require $module_name;|;
136 76 push @{$self->{members}}, $module_name->new;
137 }
138  
139 2 return 1;
140 }
141  
142 sub _die {
143 0 ▶ my ($self, $message) = @_;
Subroutine _die: not called CC=1 SCAR=6.9
144 0 Carp::croak($message);
145 }
146  
147 3 1;
148  
149 __END__
150  
151 =head1 NAME
152  
153 Acme::MorningMusume - All about Japanese pop star "Morning Musume"
154  
155 =head1 SYNOPSIS
156  
157 use Acme::MorningMusume;
158  
159 my $musume = Acme::MorningMusume->new;
160  
161 # retrieve the members on their activities
162 my @members = $musume->members; # retrieve all
163 my @active_members = $musume->members('active');
164 my @graduate_members = $musume->members('graduate');
165 my @at_some_time_members = $musume->members(DateTime->now->subtract(years => 5));
166  
167 # retrieve the members under some conditions
168 my @sorted_by_age = $musume->sort('age', 1);
169 my @sorted_by_class = $musume->sort('class', 1);
170 my @selected_by_age = $musume->select('age', 18, '>=');
171 my @selected_by_class = $musume->select('class', 5, '==');
172  
173 =head1 DESCRIPTION
174  
175 "Morning Musume" is one of highly famous Japanese pop stars.
176  
177 It consists of many pretty girls and has been known as a group which
178 members change one after another so frequently that people can't
179 completely tell who is who in the group.
180  
181 This module, Acme::MorningMusume, provides an easy method to catch up
182 with Morning Musume.
183  
184 =head1 METHODS
185  
186 =head2 new
187  
188 =over 4
189  
190 my $musume = Acme::MorningMusume->new;
191  
192 Creates and returns a new Acme::MorningMusume object.
193  
194 =back
195  
196 =head2 members ( $type )
197  
198 =over 4
199  
200 # $type can be one of the values below:
201 # + active : active members
202 # + graduate : graduate members
203 # + DateTime object : members at the time passed in
204 # + undef : all members
205  
206 my @members = $musume->members('active');
207  
208 Returns the members as a list of the L<Acme::MorningMusume::Base>
209 based object represents each member. See also the documentation of
210 L<Acme::MorningMusume::Base> for more details.
211  
212 =back
213  
214 =head2 sort ( $type, $order [ , @members ] )
215  
216 =over 4
217  
218 # $type can be one of the values below:
219 # + age : sort by age
220 # + class : sort by class
221 #
222 # $order can be a one of the values below:
223 # + something true value : sort in descending order
224 # + something false value : sort in ascending order
225  
226 my @sorted_members = $musume->sort('age', 1); # sort by age in descending order
227  
228 Returns the members sorted by the I<$type> field.
229  
230 =back
231  
232 =head2 select ( $type, $number, $operator [, @members] )
233  
234 =over 4
235  
236 # $type can be one of the same values above:
237 my @selected_members = $musume->select('age', 18, '>=');
238  
239 Returns the members satisfy the given I<$type> condition. I<$operator>
240 must be a one of '==', '>=', '<=', '>', and '<'. This method compares
241 the given I<$type> to the member's one in the order below:
242  
243 $number $operator $member_value
244  
245 =back
246  
247 =head1 SEE ALSO
248  
249 =over 4
250  
251 =item * MORNING MUSUME -Hello! Project-
252  
253 L<http://www.helloproject.com/>
254  
255 =item * Morning Musume - Wikipedia
256  
257 L<http://en.wikipedia.org/wiki/Morning_Musume>
258  
259 =item * L<Acme::MorningMusume::Base>
260  
261 =back
262  
263 =head1 AUTHOR
264  
265 =over 4
266  
267 =item * Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
268  
269 =item * Kaneko Tatsuya L<https://github.com/catatsuy>
270  
271 =back
272  
273 =head1 COPYRIGHT AND LICENSE (The MIT License)
274  
275 Copyright (c) 2005 - 2013, Kentaro Kuribayashi
276 E<lt>kentaro@cpan.orgE<gt>
277  
278 Permission is hereby granted, free of charge, to any person obtaining
279 a copy of this software and associated documentation files (the
280 "Software"), to deal in the Software without restriction, including
281 without limitation the rights to use, copy, modify, merge, publish,
282 distribute, sublicense, and/or sell copies of the Software, and to
283 permit persons to whom the Software is furnished to do so, subject to
284 the following conditions:
285  
286 The above copyright notice and this permission notice shall be
287 included in all copies or substantial portions of the Software.
288  
289 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
290 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
291 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
292 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
293 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
294 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
295 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
296  
297 =cut
↑ Summary blib/lib/Acme/MorningMusume/Base.pm »