line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Biorhythm; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
81253
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
3062
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Date::Calc::Object qw(:all); |
8
|
|
|
|
|
|
|
use Math::Trig; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.2'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $WAVELENGTH = { |
13
|
|
|
|
|
|
|
emotional => 28, |
14
|
|
|
|
|
|
|
intellectual => 33, |
15
|
|
|
|
|
|
|
physical => 23, |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $SECONDARY_CYCLES = { |
19
|
|
|
|
|
|
|
mastery => 1, |
20
|
|
|
|
|
|
|
passion => 1, |
21
|
|
|
|
|
|
|
wisdom => 1, |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'name' => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'birthday' => ( |
29
|
|
|
|
|
|
|
isa => 'Date::Calc::Object', |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'day' => ( |
34
|
|
|
|
|
|
|
isa => 'Date::Calc::Object', |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has '__cache' => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# initializer for constructor |
43
|
|
|
|
|
|
|
sub BUILD { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
my $params = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
die "birtday => REQUIRED!" if not defined $params->{birthday}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->{__cache} = { |
50
|
|
|
|
|
|
|
emotional => [], |
51
|
|
|
|
|
|
|
intellectual => [], |
52
|
|
|
|
|
|
|
physical => [], |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# finalizer for destructor |
57
|
|
|
|
|
|
|
sub DEMOLISH { } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# what day in the cycle are we in? |
60
|
|
|
|
|
|
|
sub index { |
61
|
|
|
|
|
|
|
my ($self, $cycle) = @_; |
62
|
|
|
|
|
|
|
my $diff = $self->day - $self->birthday; |
63
|
|
|
|
|
|
|
my $days = abs($diff); |
64
|
|
|
|
|
|
|
return $days % $WAVELENGTH->{$cycle}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# return the current amplitude of the cycle as a value between -1 and 1 |
68
|
|
|
|
|
|
|
sub value { |
69
|
|
|
|
|
|
|
my ($self, $cycle) = @_; |
70
|
|
|
|
|
|
|
my $day = $self->index($cycle); |
71
|
|
|
|
|
|
|
if (exists($SECONDARY_CYCLES->{$cycle})) { |
72
|
|
|
|
|
|
|
if ($cycle eq 'mastery') { |
73
|
|
|
|
|
|
|
return ($self->value('intellectual') + $self->value('physical')) / 2; |
74
|
|
|
|
|
|
|
} elsif ($cycle eq 'passion') { |
75
|
|
|
|
|
|
|
return ($self->value('physical') + $self->value('emotional')) / 2; |
76
|
|
|
|
|
|
|
} elsif ($cycle eq 'wisdom') { |
77
|
|
|
|
|
|
|
return ($self->value('emotional') + $self->value('intellectual')) / 2; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} else { |
80
|
|
|
|
|
|
|
if (exists($self->{__cache}{$cycle}[$day])) { |
81
|
|
|
|
|
|
|
return $self->{__cache}{$cycle}[$day]; |
82
|
|
|
|
|
|
|
} else { |
83
|
|
|
|
|
|
|
return $self->{__cache}{$cycle}[$day] = |
84
|
|
|
|
|
|
|
sin(pi * 2 * ($day / $WAVELENGTH->{$cycle})); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# go to the next day |
90
|
|
|
|
|
|
|
sub next { |
91
|
|
|
|
|
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
$self->{day}++; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# go to the previous day |
96
|
|
|
|
|
|
|
sub prev { |
97
|
|
|
|
|
|
|
my ($self) = @_; |
98
|
|
|
|
|
|
|
$self->{day}--; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Date::Biorhythm - a biorhythm calculator |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
From the command line |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
biorhythm --birthday=1994-10-09 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Usage |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
use Date::Biorhythm; |
118
|
|
|
|
|
|
|
my $bio = Date::Biorhythm->new({ |
119
|
|
|
|
|
|
|
birthday => Date::Calc::Object->new(0, 1970, 1, 1), |
120
|
|
|
|
|
|
|
name => 'Unix', |
121
|
|
|
|
|
|
|
}); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $i = 0; |
124
|
|
|
|
|
|
|
my $limit = 365; |
125
|
|
|
|
|
|
|
$bio->day(Date::Calc::Object->today); |
126
|
|
|
|
|
|
|
while ($i < $limit) { |
127
|
|
|
|
|
|
|
print $bio->value('emotional'), "\n"; |
128
|
|
|
|
|
|
|
$bio->next; |
129
|
|
|
|
|
|
|
$i++; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 DESCRIPTION |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
I find biorhythms mildly amusing, but I got tired of visiting |
135
|
|
|
|
|
|
|
http://www.facade.com/biorhythm and having to deal with their |
136
|
|
|
|
|
|
|
web-based form for date entry. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
I vaguely remembered there being a Perl module for biorhythm |
139
|
|
|
|
|
|
|
calculation, but I couldn't find it on CPAN. However, further |
140
|
|
|
|
|
|
|
investigation finally led me to BackPAN where I found Date::Biorhythm |
141
|
|
|
|
|
|
|
1.1 which was written by Terrence Brannon (a long time ago). |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Wanting an excuse to try L<Moose|Moose> out, I decided to make a |
144
|
|
|
|
|
|
|
new and modernized version of Date::Biorhythm, and this is the |
145
|
|
|
|
|
|
|
result. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 BUT WTF IS A BIORHYTHM? |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
!http://i41.photobucket.com/albums/e271/sr5i/GoogleMotherFucker.jpg! |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
http://en.wikipedia.org/wiki/Biorhythm |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 METHODS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 meta |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This method was added by Moose, and it gives you access to Date::Biorhythm's |
158
|
|
|
|
|
|
|
metaclass. (See L<Moose|Moose> for more details.) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 new |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The constructor. It takes on optional hashref that will accept the following keys: |
163
|
|
|
|
|
|
|
name, birthday, and day. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 name |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Get or set the name associated with this biorhythm. This will usually |
168
|
|
|
|
|
|
|
be a person's name. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 birthday |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Get or set the birthday used for this biorhythm. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 day |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Get or set the current day (which is represented by a Date::Calc::Object). |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 next |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Go forward one day by incrementing $self->day. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 prev |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Go backward one day by decrementing $self->day. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 index |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Given a primary cycle (such as 'emotional', 'intellectual', or 'physical'), |
189
|
|
|
|
|
|
|
return how many days we are into the cycle. Note that the first day of the |
190
|
|
|
|
|
|
|
cycle returns 0. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 value |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Given a primary cycle or secondary cycle, return a value between -1 and 1 |
195
|
|
|
|
|
|
|
that represents the current amplitude in the cycle. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 SEE ALSO |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
http://www.facade.com/biorhythm |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 AUTHOR |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Terrence Brannon E<lt>metaperl@gmail.comE<gt> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
John Beppu E<lt>beppu@cpan.orgE<gt> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |