blib/lib/Acme/Nogizaka46.pm

filter: Statementstmt 84.2% 48 / 57 Branchbran 63.6% 14 / 22 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 80.0% 8 / 10 Podpod 100% 4 / 4 totaltotal 81.3% 83 / 102 SCAR 27.5
CC
14
Cov
80%
sort
12.0
members
8.0
select
4.0
CRAP 15.6
↑ Summary blib/lib/Acme/Nogizaka46/Base.pm »
1 package Acme::Nogizaka46;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.2';
10  
11 4 my @members = qw(
12 AkimotoManatsu
13 AndoMikumo
14 IkutaErika
15 IkomaRina
16 IchikiRena
17 ItoNene
18 ItoMarika
19 InoueSayuri
20 IwaseYumiko
21 EtoMisa
22 KashiwaYukina
23 KawagoHina
24 KawamuraMahiro
25 SaitoAsuka
26 SaitoChiharu
27 SaitoYuri
28 SakuraiReika
29 ShiraishiMai
30 TakayamaKazumi
31 NakadaKana
32 NakamotoHimeka
33 NagashimaSeira
34 NishinoNanase
35 NojoAmi
36 HashimotoNanami
37 HatanakaSeira
38 HiguchiHina
39 FukagawaMai
40 HoshinoMinami
41 MatsumuraSayuri
42 MiyazawaSeira
43 YamatoRina
44 YamamotoHonoka
45 YoshimotoAyaka
46 WakatsukiYumi
47 WadaMaaya
48 ItoKarin
49 ItoJunna
50 KitanoHinako
51 SagaraIori
52 SasakiKotoko
53 ShinuchiMai
54 SuzukiAyane
55 TeradaRanze
56 NishikawaNanami
57 HoriMiona
58 YadaRisako
59 YamazakiRena
60 YonetokuKyoka
61 WatanabeMiria
62 MatsuiRena
63 );
64  
65 my %date_joined = map {
66 4 my ($class, $year, $month, $day) = ($_ =~ /(\w+):(\d{4})-(\d{2})-(\d{2})/);
67 12 $class => DateTime->new(
68 year => $year,
69 month => $month,
70 day => $day,
71 );
72 } qw(
73 1:2011-08-21
74 2:2013-05-11
75 MatsuiRena:2014-02-24
76 );
77  
78 sub new {
79 3 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
80 3 my $self = bless {members => []}, $class;
81  
82 3 $self->_initialize;
83  
84 3 return $self;
85 }
86  
87 sub members {
88 10 ▶ my ($self, $type, @members) = @_;
Subroutine members: called CC=8 SCAR=20.8
Pod documented
89 10 ▶ @members = @{$self->{members}} unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 10 0 10
90  
91 10 ▶ return @members unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 4 6 10
92  
93 6 ▶ if ($type eq 'active') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'active') { } 1 5 6
elsif ($type eq 'graduate') { } 1 4 5
elsif ($type->isa('DateTime')) { } 4 0 4
94 1 return grep {!$_->graduate_date} @members;
95 }
96 elsif ($type eq 'graduate') {
97 1 return grep {$_->graduate_date} @members;
98 }
99 elsif ($type->isa('DateTime')) {
100 return grep {
101 4 ▶ $date_joined{$_->class} <= $type and
Branch: 1 branch
BranchTrueFalseTotal
$date_joined{$_->class} <= $type and !$_->graduate_date || $type <= $_->graduate_date 138 66 204
Condition100%6/6
$date_joined{$_->class} <= $type && (!$_->graduate_date || $type <= $_->graduate_date)
!ll&&!rl&&r
6623115
not $_->graduate_date or $type <= $_->graduate_date
l!l&&r!l&&!r
971823
MC/DC100%3/3
$date_joined{$_->class} <= $type && (!$_->graduate_date || $type <= $_->graduate_date)
$date_joined{$_->class} <= $type not $_->graduate_date $type <= $_->graduate_date
Truth table100%4/4
A && not(B) or C
A= $date_joined{$_->class} <= $typeB= not $_->graduate_dateC= $type <= $_->graduate_date
ABCresult
0XX0
1000
11X1
1011
102 (!$_->graduate_date or $type <= $_->graduate_date)
103 } @members;
104 }
105 }
106  
107 sub sort {
108 0 ▶ my ($self, $type, $order, @members) = @_;
Subroutine sort: not called CC=3 SCAR=24.8
Pod documented
109 0 ▶ @members = $self->members unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 0 0 0
110  
111 # order by desc if $order is true
112 0 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) { } 0 0 0
113 0 return sort {$b->$type <=> $a->$type} @members;
114 }
115 else {
116 0 return sort {$a->$type <=> $b->$type} @members;
117 }
118 }
119  
120 sub select {
121 2 ▶ my ($self, $type, $num_or_str, $operator, @members) = @_;
Subroutine select: called CC=4 SCAR=14.0
Pod documented
122  
123 $self->_die('invalid operator was passed in')
124 2 ▶ unless grep {$operator eq $_} qw(== >= <= > < eq ne);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$operator eq $_;} "==", ">=", "<=", ">", "<", "eq", "ne" 0 2 2
125  
126 2 ▶ @members = $self->members unless @members;
Branch: 1 branch
BranchTrueFalseTotal
unless @members 2 0 2
127 2 ▶ if ($type eq 'center') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'center') { } 1 1 2
128 } else {
129 1 my $compare = eval "(sub { \$num_or_str $operator \$_[0] })";
130  
131 1 return grep { $compare->($_->$type) } @members;
132 }
133 }
134  
135 sub _initialize {
136 3 ▶ my $self = shift;
Subroutine _initialize: called CC=2 SCAR=6.9
137  
138 3 for my $member (@members) {
139 153 my $module_name = 'Acme::Nogizaka46::'.$member;
140  
141 153 eval qq|require $module_name;|;
142 153 push @{$self->{members}}, $module_name->new;
143 }
144  
145 3 return 1;
146 }
147  
148 sub _die {
149 0 ▶ my ($self, $message) = @_;
Subroutine _die: not called CC=1 SCAR=6.9
150 0 Carp::croak($message);
151 }
152  
153 4 1;
154  
155 __END__
156  
157 =head1 NAME
158  
159 Acme::Nogizaka46 - All about "Nogizaka46"
160  
161 =head1 SYNOPSIS
162  
163 use Acme::Nogizaka46;
164  
165 my $nogizaka = Acme::Nogizaka46->new;
166  
167 # retrieve the members on their activities
168 my @members = $nogizaka->members; # retrieve all
169 my @active_members = $nogizaka->members('active');
170 my @graduate_members = $nogizaka->members('graduate');
171 my @at_some_time_members = $nogizaka->members(DateTime->now->subtract(years => 5));
172  
173 # retrieve the members under some conditions
174 my @sorted_by_age = $nogizaka->sort('age', 1);
175 my @sorted_by_class = $nogizaka->sort('class', 1);
176 my @selected_by_age = $nogizaka->select('age', 18, '>=');
177 my @selected_by_class = $nogizaka->select('class', 5, '==');
178  
179 =head1 DESCRIPTION
180  
181 "Nogizaka46" is a Japanese female idol group.
182  
183 This module, Acme::Nogizaka46, provides an easy method to catch up
184 with Nogizaka46.
185  
186 =head1 METHODS
187  
188 =head2 new
189  
190 =over 4
191  
192 my $nogizaka = Acme::Nogizaka46->new;
193  
194 Creates and returns a new Acme::Nogizaka46 object.
195  
196 =back
197  
198 =head2 members ( $type )
199  
200 =over 4
201  
202 # $type can be one of the values below:
203 # + active : active members
204 # + graduate : graduate members
205 # + DateTime object : members at the time passed in
206 # + undef : all members
207  
208 my @members = $nogizaka->members('active');
209  
210 Returns the members as a list of the L<Acme::Nogizaka46::Base>
211 based object represents each member. See also the documentation of
212 L<Acme::Nogizaka46::Base> for more details.
213  
214 =back
215  
216 =head2 sort ( $type, $order [ , @members ] )
217  
218 =over 4
219  
220 # $type can be one of the values below:
221 # + age : sort by age
222 # + class : sort by class
223 #
224 # $order can be a one of the values below:
225 # + something true value : sort in descending order
226 # + something false value : sort in ascending order
227  
228 my @sorted_members = $nogizaka->sort('age', 1); # sort by age in descending order
229  
230 Returns the members sorted by the I<$type> field.
231  
232 =back
233  
234 =head2 select ( $type, $number, $operator [, @members] )
235  
236 =over 4
237  
238 # $type can be one of the same values above:
239 my @selected_members = $nogizaka->select('age', 18, '>=');
240  
241 Returns the members satisfy the given I<$type> condition. I<$operator>
242 must be a one of '==', '>=', '<=', '>', and '<'. This method compares
243 the given I<$type> to the member's one in the order below:
244  
245 $number $operator $member_value
246  
247 =back
248  
249 =head1 SEE ALSO
250  
251 =over 4
252  
253 =item * Nogizaka46
254  
255 L<http://www.nogizaka46.com/>
256  
257 =item * Nogizaka46 - Wikipedia
258  
259 L<https://en.wikipedia.org/wiki/Nogizaka46>
260  
261 =back
262  
263 =head1 AUTHOR
264  
265 =over 4
266  
267 =item * Takaaki TSUJIMOTO E<lt>2gmon.t@gmail.comE<gt>
268  
269 =back
270  
271 =head1 COPYRIGHT AND LICENSE (The MIT License)
272  
273 Copyright (c) 2015, Takaaki TSUJIMOTO E<lt>2gmon.t@gmail.comE<gt>
274  
275 Original 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/Nogizaka46/Base.pm »