File Coverage

blib/lib/Acme/MomoiroClover/Members/Base.pm
Criterion Covered Total %
statement 33 36 91.6
branch 5 8 62.5
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 2 100.0
total 50 57 87.7


line stmt bran cond sub pod time code
1             package Acme::MomoiroClover::Members::Base;
2              
3 2     2   13 use strict;
  2         2  
  2         66  
4 2     2   45 use warnings;
  2         4  
  2         54  
5 2     2   9 use Date::Simple ();
  2         2  
  2         38  
6 2     2   9 use base qw(Class::Accessor);
  2         3  
  2         2030  
7              
8             our $ansi_colors = {
9             red => "\x1b[38;5;1m",
10             green => "\x1b[38;5;2m",
11             blue => "\x1b[38;5;4m",
12             purple => "\x1b[38;5;5m",
13             pink => "\x1b[38;5;13m",
14             yellow => "\x1b[38;5;3m",
15             };
16              
17              
18             __PACKAGE__->mk_accessors(qw(
19             name_ja
20             first_name_ja
21             family_name_ja
22             name_en
23             first_name_en
24             family_name_en
25             nick
26             birthday
27             age
28             blood_type
29             hometown
30             emoticon
31             graduate_date
32             join_date
33             color
34             ));
35              
36             sub new {
37 33     33 1 59 my $class = shift;
38 33         95 my $self = bless {}, $class;
39              
40 33         170 $self->_initialize;
41              
42 33         134 return $self;
43             }
44              
45             sub say {
46 11     11 1 81064 my ($self, $comment) = @_;
47 11 100       39 print $ansi_colors->{$self->color} if ($self->color);
48 11   66     481 print $self->nick->[0] || $self->name_ja;
49 11         789 print ': ';
50 11         1453 print $comment, "\x1b[0m\n";
51             }
52              
53             sub _initialize {
54 33     33   44 my $self = shift;
55 33         120 my %info = $self->info;
56              
57 33         3496 $self->{$_} = $info{$_} for keys %info;
58 33         274 $self->{name_ja} = $self->family_name_ja.$self->first_name_ja;
59 33         900 $self->{name_en} = $self->first_name_en.' '.$self->family_name_en;
60 33         726 $self->{age} = $self->_calculate_age;
61              
62 33         590 return 1;
63             }
64              
65             sub _calculate_age {
66 33     33   53 my $self = shift;
67 33         83 my $today = Date::Simple::today;
68              
69 33 50       1386 if (($today->month - $self->birthday->month) == 0) {
    100          
70 0 0       0 if (($today->day - $self->birthday->day) >= 0) {
71 0         0 return $today->year - $self->birthday->year;
72             } else {
73 0         0 return ($today->year - $self->birthday->year) - 1;
74             }
75             } elsif (($today->month - $self->birthday->month) > 0) {
76 23         524 return $today->year - $self->birthday->year;
77             } else {
78 10         226 return ($today->year - $self->birthday->year) - 1;
79             }
80             }
81              
82             1;
83              
84             __END__