blib/lib/Date/Horoscope.pm

filter: Statementstmt 85.3% 35 / 41 Branchbran 21.4% 3 / 14 Conditioncond 33.3% 8 / 24 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 83.3% 5 / 6 Podpod 50.0% 1 / 2 totaltotal 54.0% 54 / 100 CC 17 SCAR 37.1
CC
17
Cov
58%
day_month_logic
90.0
locate
9.9
BEGIN
1.0
CRAP 41.0
↑ Summary
1 package Date::Horoscope;
2  
3 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Date::Manip;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 ▶use strict qw(vars subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 require Exporter;
11  
12 1 @ISA = qw(Exporter AutoLoader);
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16 1 @EXPORT = qw(
17
18 );
19 1 $VERSION = '2.2';
20  
21 # year is irrelevant for our purposes
22  
23 1 %Date::Horoscope::horoscope = (
24 'aries' => {
25 'position' => 1,
26 'start' => '3/21/92',
27 'end' => '4/20/92',
28 },
29 'taurus' => {
30 'position' => 2,
31 'start' => '4/21/92',
32 'end' => '5/20/92',
33 },
34 'gemini' => {
35 'position' => 3,
36 'start' => '5/21/92',
37 'end' => '6/21/92',
38 },
39 'cancer' => {
40 'position' => 4,
41 'start' => '6/22/92',
42 'end' => '7/22/92',
43 },
44 'leo' => {
45 'position' => 5,
46 'start' => '7/23/92',
47 'end' => '8/23/92',
48 },
49 'virgo' => {
50 'position' => 6,
51 'start' => '8/24/92',
52 'end' => '9/22/92',
53 },
54 'libra' => {
55 'position' => 7,
56 'start' => '9/23/92',
57 'end' => '10/22/92',
58 },
59 'scorpio' => {
60 'position' => 8,
61 'start' => '10/23/92',
62 'end' => '11/21/92',
63 },
64 'sagittarius' => {
65 'position' => 9,
66 'start' => '11/22/92',
67 'end' => '12/21/92',
68 },
69 'capricorn' => {
70 'position' => 10,
71 'start' => '1/1/92', # NOT TRUE BUT NECESSARY
72 'end' => '1/19/92',
73 },
74 'aquarius' => {
75 'position' => 11,
76 'start' => '1/20/92',
77 'end' => '2/18/92',
78 },
79 'pisces' => {
80 'position' => 12,
81 'start' => '2/19/92',
82 'end' => '3/20/92',
83 }
84 );
85  
86  
87  
88 # day_month_logic:
89 # -----------------------------------------------------------------------
90 # Return a one if the day/month combo is greater than the day/month combo
91 # it was subtracted from. Return 0 if equal and -1 if less.
92  
93 0 ▶sub day_month_logic {
Subroutine day_month_logic: not called CC=9 SCAR=45.0
Pod undocumented
94 0 my ($M,$D)=@_;
95  
96 #warn "day_month_logic: $M, $D";
97  
98 0 ▶ ($M < 0) && return -1;
Branch: 1 branch
BranchTrueFalseTotal
$M < 0 and return -1 0 0 0
99 0 ▶ ($M > 0) && return 1;
Branch: 1 branch
BranchTrueFalseTotal
$M > 0 and return 1 0 0 0
100 0 ▶ ($M == 0) && ($D == 0) && return 0;
Branch: 1 branch
BranchTrueFalseTotal
$M == 0 and $D == 0 and return 0 0 0 0
Condition0%0/3
$M == 0 and $D == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$M == 0 and $D == 0
$M == 0 $D == 0
Truth table0%0/3
A and B
A= $M == 0B= $D == 0
ABresult
0X0
100
111
101 0 ▶ ($M == 0) && ($D > 0) && return 1;
Branch: 1 branch
BranchTrueFalseTotal
$M == 0 and $D > 0 and return 1 0 0 0
Condition0%0/3
$M == 0 and $D > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$M == 0 and $D > 0
$M == 0 $D > 0
Truth table0%0/3
A and B
A= $M == 0B= $D > 0
ABresult
0X0
100
111
102 0 ▶ ($M == 0) && ($D < 0) && return -1;
Branch: 1 branch
BranchTrueFalseTotal
$M == 0 and $D < 0 and return -1 0 0 0
Condition0%0/3
$M == 0 and $D < 0
!ll&&!rl&&r
000
MC/DC0%0/2
$M == 0 and $D < 0
$M == 0 $D < 0
Truth table0%0/3
A and B
A= $M == 0B= $D < 0
ABresult
0X0
100
111
103 }
104  
105  
106 5 ▶sub locate {
Subroutine locate: called CC=9 SCAR=22.9
Pod documented
107 5 my $input_date = $_[0];
108  
109 #warn "input_date: $input_date";
110  
111 5 my %input_date;
112 5 $input_date{month} = &UnixDate($input_date, '%m');
113 5 $input_date{day} = &UnixDate($input_date, '%d');
114 5 $input_date{year} = 1992;
115  
116 #warn "Y-M-D: $input_date{year}-$input_date{month}-$input_date{day}";
117  
118 5 ▶ return 'capricorn' if $input_date{month}==12 && $input_date{day} >=22 && $input_date{day} <=31;
Branch: 1 branch
BranchTrueFalseTotal
if $input_date{"month"} == 12 and $input_date{"day"} >= 22 and $input_date{"day"} <= 31 0 5 5
Condition33%2/6
$input_date{"month"} == 12 and $input_date{"day"} >= 22 and $input_date{"day"} <= 31
!ll&&!rl&&r
500
$input_date{"month"} == 12 and $input_date{"day"} >= 22
!ll&&!rl&&r
500
MC/DC0%0/3
$input_date{"month"} == 12 and $input_date{"day"} >= 22 and $input_date{"day"} <= 31
$input_date{"month"} == 12 $input_date{"day"} >= 22 $input_date{"day"} <= 31
Truth table25%1/4
A and B and C
A= $input_date{"month"} == 12B= $input_date{"day"} >= 22C= $input_date{"day"} <= 31
ABCresult
0XX0
10X0
1100
1111
119  
120
121 5 $input_date{new} = "$input_date{year}-$input_date{month}-$input_date{day}";
122 #warn "<1>input_date{new} = $input_date{new}";
123 5 $input_date{new} =~ s/\s+//g;
124  
125  
126 #warn "<2>input_date{new} = $input_date{new}";
127  
128 my @sorted_keys =
129 sort {
130 5 $Date::Horoscope::horoscope{$a}{position}
131 <=>
132 $Date::Horoscope::horoscope{$b}{position}
133 140 } (keys %Date::Horoscope::horoscope);
134  
135  
136 # this returns something like 'taurus', 'sagittarius', etc.
137 5 for my $h (@sorted_keys) {
138  
139 # start and end dates of this zodiac sign... year irrelevant
140 60 my $start = &ParseDate($Date::Horoscope::horoscope{$h}{start});
141 60 my $end = &ParseDate($Date::Horoscope::horoscope{$h}{end});
142 60 my $input = &ParseDate($input_date{new});
143  
144  
145  
146 60 my $S=&Date_Cmp($start,$input);
147 60 my $E=&Date_Cmp($input,$end);
148  
149 #warn sprintf("H: %s S: %d E: %d", $h, $S, $E);
150 #warn sprintf ("start: %s end: %s input: %s", $start, $end, $input);
151  
152 60 ▶ return $h if (
Branch: 1 branch
BranchTrueFalseTotal
if not $S && $E or $S < 0 and $E < 0 5 55 60
Condition66%6/9
not $S && $E or $S < 0 and $E < 0
l!l&&r!l&&!r
0555
$S && $E
!ll&&!rl&&r
0060
$S < 0 and $E < 0
!ll&&!rl&&r
45105
MC/DC50%2/4
not $S && $E or $S < 0 and $E < 0
$S $E $S < 0 $E < 0
Truth table60%3/5
not(A && B) or C and D
A= $SB= $EC= $S < 0D= $E < 0
ABCDresult
0XXX1
10XX1
11111
110X0
11100
153 ((!$S) || (!$E)) ||
154 (($S < 0) && ($E < 0))
155 );
156
157 }
158 }
159
160  
161  
162 # Autoload methods go after =cut, and are processed by the autosplit program.
163  
164 1 1;
165 __END__
↑ Summary