blib/lib/Acme/2zicon/Base.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 54 / 54 SCAR 13.9
CC
4
Cov
100%
_calculate_age
3.0
_initialize
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Acme/2zicon.pm ↑ Summary blib/lib/Acme/2zicon/KinoshitaHiyori.pm »
1 package Acme::2zicon::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.5';
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 introduction
23 twitter
24 ));
25  
26 sub new {
27 20 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
28 20 my $self = bless {}, $class;
29  
30 20 $self->_initialize;
31  
32 20 return $self;
33 }
34  
35 sub _initialize {
36 20 ▶ my $self = shift;
Subroutine _initialize: called CC=2 SCAR=6.9
37 20 my %info = $self->info;
38  
39 20 $self->{$_} = $info{$_} for keys %info;
40 20 $self->{name_ja} = $self->family_name_ja.$self->first_name_ja;
41 20 $self->{name_en} = $self->first_name_en.' '.$self->family_name_en;
42 20 $self->{age} = $self->_calculate_age;
43 20 $self->{introduction} = $self->_introduction($info{introduction});
44  
45 20 return 1;
46 }
47  
48 sub _calculate_age {
49 20 ▶ my $self = shift;
Subroutine _calculate_age: called CC=3 SCAR=11.0
50 20 my $today = DateTime->today;
51  
52 20 ▶ if (($today->month - $self->birthday->month) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($today->month - $self->birthday->month >= 0) { } 10 10 20
53 10 ▶ if (($today->day - $self->birthday->day ) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($today->day - $self->birthday->day >= 0) { } 6 4 10
54 6 return $today->year - $self->birthday->year;
55 } else {
56 4 return ($today->year - $self->birthday->year) - 1;
57 }
58 } else {
59 10 return ($today->year - $self->birthday->year) - 1;
60 }
61 }
62  
63 sub _datetime_from_date {
64 20 ▶ my ($self, $date) = @_;
Subroutine _datetime_from_date: called CC=1 SCAR=0.0
65 20 my ($year, $month, $day) = ($date =~ /(\d{4})\.(\d{2})\.(\d{2})/);
66  
67 20 DateTime->new(
68 year => $year,
69 month => $month,
70 day => $day,
71 );
72 }
73  
74 sub _introduction {
75 20 ▶ my ($self, $introduction) = @_;
Subroutine _introduction: called CC=1 SCAR=0.0
76 20 $introduction =~ s/\[(\w+)\]/$self->{$1}/g;
77 20 return $introduction;
78 }
79  
80 2 1;
81  
82 __END__
83  
84 =head1 NAME
85  
86 Acme::2zicon::Base
87  
88 =head1 SYNOPSIS
89  
90 use Acme::2zicon;
91  
92 my $nizicon = Acme::2zicon->new;
93  
94 # retrieve the members as a list of
95 # Acme::2zicon::Base based objects
96 my @members = $nizicon->members;
97  
98 for my $member (@members) {
99 my $name_ja = $member->name_ja;
100 my $first_name_ja = $member->first_name_ja;
101 my $family_name_ja = $member->family_name_ja;
102 my $name_en = $member->name_en;
103 my $first_name_en = $member->first_name_en;
104 my $family_name_en = $member->family_name_en;
105 my $nick = $member->nick; # arrayref
106 my $birthday = $member->birthday; # DateTime object
107 my $age = $member->age;
108 my $blood_type = $member->blood_type;
109 my $hometown = $member->hometown;
110 my $twitter = $member->twitter;
111 }
112  
113 =head1 DESCRIPTION
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 twitter
140  
141 =head1 SEE ALSO
142  
143 =over 4
144  
145 =item * L<DateTime>
146  
147 =back
148  
149 =head1 AUTHOR
150  
151 =head1 COPYRIGHT AND LICENSE (The MIT License)
152  
153 =cut
« blib/lib/Acme/2zicon.pm ↑ Summary blib/lib/Acme/2zicon/KinoshitaHiyori.pm »