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
« MorningMusume.pm ↑ Summary MorningMusume/AbeNatsumi.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.20';
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 76 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
28 76 my $class = shift;
29 76 my $self = bless {}, $class;
30  
31 76 $self->_initialize;
32  
33 76 return $self;
34 }
35  
36 76 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=6.9
37 76 my $self = shift;
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 76 ▶sub _calculate_age {
Subroutine _calculate_age: called CC=3 SCAR=11.0
49 76 my $self = shift;
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) { } 68 8 76
53 68 ▶ if (($today->day - $self->birthday->day ) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($today->day - $self->birthday->day >= 0) { } 4 64 68
54 4 return $today->year - $self->birthday->year;
55 } else {
56 64 return ($today->year - $self->birthday->year) - 1;
57 }
58 } else {
59 8 return ($today->year - $self->birthday->year) - 1;
60 }
61 }
62  
63 130 ▶sub _datetime_from_date {
Subroutine _datetime_from_date: called CC=1 SCAR=0.0
64 130 my ($self, $date) = @_;
65 130 my ($year, $month, $day) = ($date =~ /(\d{4})-(\d{2})-(\d{2})/);
66  
67 130 DateTime->new(
68 year => $year,
69 month => $month,
70 day => $day,
71 );
72 }
73  
74 2 1;
75  
76 __END__
« MorningMusume.pm ↑ Summary MorningMusume/AbeNatsumi.pm »