Calendar.pm

filter: Statementstmt 70.9% 105 / 148 Branchbran 59.0% 26 / 44 Conditioncond 38.7% 12 / 31 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 68.1% 15 / 22 Podpod 0.0% 0 / 16 totaltotal 57.6% 159 / 276 CC 36 SCAR 27.2
CC
36
Cov
64%
delta_workdays
40.1
labels
6.8
add_delta_workdays
6.6
CRAP 15.1
« Calendar/Year.pm ↑ Summary Calc.pm »
1  
2 ###############################################################################
3 ## ##
4 ## Copyright (c) 2000 - 2015 by Steffen Beyer. ##
5 ## All rights reserved. ##
6 ## ##
7 ## This package is free software; you can redistribute it ##
8 ## and/or modify it under the same terms as Perl itself. ##
9 ## ##
10 ###############################################################################
11  
12 package Date::Calendar;
13  
14 4 ▶BEGIN { eval { require bytes; }; }
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 require Exporter;
19  
20 4 @ISA = qw(Exporter);
21  
22 4 @EXPORT = qw();
23  
24 4 @EXPORT_OK = qw();
25  
26 4 $VERSION = '6.4';
27  
28 4 ▶use Carp::Clan qw(^Date::);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 ▶use Date::Calc::Object qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use Date::Calendar::Year qw( check_year empty_period );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 sub new
33 177 ▶{
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
34 177 my($class) = shift;
35 177 my($profile) = shift;
36 177 ▶ my($language) = shift || 0;
Condition100%2/2
shift() || 0
l!l
1176
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
37 177 my($self);
38  
39 177 $self = [ ];
40 177 ▶ $class = ref($class) || $class || 'Date::Calendar';
Condition40%2/5
ref $class || $class || 'Date::Calendar'
l!l
1770
ref $class or $class
l!l&&r!l&&!r
01770
MC/DC0%0/2
ref $class || $class || 'Date::Calendar'
ref $class $class
Truth table33%1/3
A or B
A= ref $classB= $class
ABresult
1X1
011
000
41 177 bless($self, $class);
42 177 $self->[0] = { };
43 177 $self->[1] = $profile;
44 177 $self->[2] = $language;
45 177 $self->[3] = [@_];
46 177 return $self;
47 }
48  
49 sub year
50 227 ▶{
Subroutine year: called CC=2 SCAR=6.9
Pod undocumented
51 227 my($self) = shift;
52 227 my($year) = shift_year(\@_);
53  
54 227 &check_year($year);
55 227 ▶ if (defined $self->[0]{$year})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{$year}) { } 43 184 227
56 {
57 43 return $self->[0]{$year};
58 }
59 else
60 {
61 return $self->[0]{$year} =
62 184 Date::Calendar::Year->new( $year, $self->[1], $self->[2], @{$self->[3]} );
63 }
64 }
65  
66 sub cache_keys
67 2 ▶{
Subroutine cache_keys: called CC=1 SCAR=0.0
Pod undocumented
68 2 my($self) = shift;
69  
70 2 return( sort {$a<=>$b} keys(%{$self->[0]}) );
71 }
72  
73 sub cache_vals
74 0 ▶{
Subroutine cache_vals: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my($self) = shift;
76 0 local($_);
77  
78 0 return( map $self->[0]{$_}, sort {$a<=>$b} keys(%{$self->[0]}) );
79 }
80  
81 sub cache_clr
82 0 ▶{
Subroutine cache_clr: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my($self) = shift;
84  
85 0 $self->[0] = { };
86 }
87  
88 sub cache_add
89 1 ▶{
Subroutine cache_add: called CC=2 SCAR=6.9
Pod undocumented
90 1 my($self) = shift;
91 1 my($year);
92  
93 1 ▶ while (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 1 6
94 {
95 5 $year = shift_year(\@_);
96 5 $self->year($year);
97 }
98 }
99  
100 sub cache_del
101 1 ▶{
Subroutine cache_del: called CC=3 SCAR=11.0
Pod undocumented
102 1 my($self) = shift;
103 1 my($year);
104  
105 1 ▶ while (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
106 {
107 1 $year = shift_year(\@_);
108 1 ▶ if (exists $self->[0]{$year})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->[0]{$year}) 1 0 1
109 {
110 1 delete $self->[0]{$year};
111 }
112 }
113 }
114  
115 sub date2index
116 0 ▶{
Subroutine date2index: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my($self) = shift;
118 0 my(@date) = shift_date(\@_);
119  
120 0 return $self->year($date[0])->date2index(@date);
121 }
122  
123 sub labels
124 5 ▶{
Subroutine labels: called CC=4 SCAR=19.2
Pod undocumented
125 5 my($self) = shift;
126 5 my($year);
127 my(@date);
128 5 my(%result);
129  
130 5 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 0 5
131 {
132 5 @date = shift_date(\@_);
133 5 return $self->year($date[0])->labels(@date);
134 }
135 else
136 {
137 0 local($_);
138 0 %result = ();
139 0 foreach $year (keys(%{$self->[0]}))
140 {
141 0 grep( $result{$_} = 0, $self->year($year)->labels() );
142 }
143 0 ▶ return wantarray ? (keys %result) : scalar(keys %result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
144 }
145 }
146  
147 sub search
148 1 ▶{
Subroutine search: called CC=3 SCAR=11.0
Pod undocumented
149 1 my($self,$pattern) = @_;
150 1 my($year);
151 my(@result);
152  
153 1 @result = ();
154 1 foreach $year (sort {$a<=>$b} keys(%{$self->[0]}))
155 {
156 4 push( @result, $self->year($year)->search($pattern) );
157 }
158 1 ▶ return wantarray ? (@result) : scalar(@result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
159 }
160  
161 sub tags
162 0 ▶{
Subroutine tags: not called CC=2 SCAR=17.9
Pod undocumented
163 0 my($self) = shift;
164 0 my(%result) = ();
165 0 my(@date);
166  
167 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
168 {
169 0 @date = shift_date(\@_);
170 0 return $self->year($date[0])->tags(@date);
171 }
172 0 else { return \%result; }
173 }
174  
175 sub delta_workdays
176 10 ▶{
Subroutine delta_workdays: called CC=18 SCAR=36.9
Pod undocumented
177 10 my($self) = shift;
178 10 my($yy1,$mm1,$dd1) = shift_date(\@_);
179 10 my($yy2,$mm2,$dd2) = shift_date(\@_);
180 10 my($including1,$including2) = (shift,shift);
181 10 my($days,$empty,$year);
182  
183 10 $days = 0;
184 10 $empty = 1;
185 10 ▶ if ($yy1 == $yy2)
Branch: 2 branches
BranchTrueFalseTotal
if ($yy1 == $yy2) { } 0 10 10
elsif ($yy1 < $yy2) { } 2 8 10
186 {
187 0 return $self->year($yy1)->delta_workdays(
188 $yy1,$mm1,$dd1, $yy2,$mm2,$dd2, $including1,$including2);
189 }
190 elsif ($yy1 < $yy2)
191 {
192 2 ▶ unless (($mm1 == 12) && ($dd1 == 31) && (!$including1))
Branch: 1 branch
BranchTrueFalseTotal
unless ($mm1 == 12 and $dd1 == 31 and not $including1) 2 0 2
Condition33%2/6
$mm1 == 12 and $dd1 == 31 and not $including1
!ll&&!rl&&r
200
$mm1 == 12 and $dd1 == 31
!ll&&!rl&&r
020
MC/DC0%0/3
$mm1 == 12 and $dd1 == 31 and not $including1
$mm1 == 12 $dd1 == 31 not $including1
Truth table25%1/4
A and B and not(C)
A= $mm1 == 12B= $dd1 == 31C= not $including1
ABCresult
0XX0
10X0
1100
1111
193 {
194 2 $days += $self->year($yy1)->delta_workdays(
195 $yy1,$mm1,$dd1, $yy1,12,31, $including1,1);
196 2 $empty = 0;
197 }
198 2 ▶ unless (($mm2 == 1) && ($dd2 == 1) && (!$including2))
Branch: 1 branch
BranchTrueFalseTotal
unless ($mm2 == 1 and $dd2 == 1 and not $including2) 2 0 2
Condition33%2/6
$mm2 == 1 and $dd2 == 1 and not $including2
!ll&&!rl&&r
200
$mm2 == 1 and $dd2 == 1
!ll&&!rl&&r
020
MC/DC0%0/3
$mm2 == 1 and $dd2 == 1 and not $including2
$mm2 == 1 $dd2 == 1 not $including2
Truth table25%1/4
A and B and not(C)
A= $mm2 == 1B= $dd2 == 1C= not $including2
ABCresult
0XX0
10X0
1100
1111
199 {
200 2 $days += $self->year($yy2)->delta_workdays(
201 $yy2, 1, 1, $yy2,$mm2,$dd2, 1,$including2);
202 2 $empty = 0;
203 }
204 2 ▶ for ( $year = $yy1 + 1; $year < $yy2; $year++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($year < $yy2) 0 2 2
205 {
206 0 $days += $self->year($year)->delta_workdays(
207 $year,1,1, $year,12,31, 1,1);
208 0 $empty = 0;
209 }
210 }
211 else
212 {
213 8 ▶ unless (($mm2 == 12) && ($dd2 == 31) && (!$including2))
Branch: 1 branch
BranchTrueFalseTotal
unless ($mm2 == 12 and $dd2 == 31 and not $including2) 8 0 8
Condition33%2/6
$mm2 == 12 and $dd2 == 31 and not $including2
!ll&&!rl&&r
800
$mm2 == 12 and $dd2 == 31
!ll&&!rl&&r
080
MC/DC0%0/3
$mm2 == 12 and $dd2 == 31 and not $including2
$mm2 == 12 $dd2 == 31 not $including2
Truth table25%1/4
A and B and not(C)
A= $mm2 == 12B= $dd2 == 31C= not $including2
ABCresult
0XX0
10X0
1100
1111
214 {
215 8 $days -= $self->year($yy2)->delta_workdays(
216 $yy2,$mm2,$dd2, $yy2,12,31, $including2,1);
217 8 $empty = 0;
218 }
219 8 ▶ unless (($mm1 == 1) && ($dd1 == 1) && (!$including1))
Branch: 1 branch
BranchTrueFalseTotal
unless ($mm1 == 1 and $dd1 == 1 and not $including1) 8 0 8
Condition33%2/6
$mm1 == 1 and $dd1 == 1 and not $including1
!ll&&!rl&&r
800
$mm1 == 1 and $dd1 == 1
!ll&&!rl&&r
080
MC/DC0%0/3
$mm1 == 1 and $dd1 == 1 and not $including1
$mm1 == 1 $dd1 == 1 not $including1
Truth table25%1/4
A and B and not(C)
A= $mm1 == 1B= $dd1 == 1C= not $including1
ABCresult
0XX0
10X0
1100
1111
220 {
221 8 $days -= $self->year($yy1)->delta_workdays(
222 $yy1, 1, 1, $yy1,$mm1,$dd1, 1,$including1);
223 8 $empty = 0;
224 }
225 8 ▶ for ( $year = $yy2 + 1; $year < $yy1; $year++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($year < $yy1) 0 8 8
226 {
227 0 $days -= $self->year($year)->delta_workdays(
228 $year,1,1, $year,12,31, 1,1);
229 0 $empty = 0;
230 }
231 }
232 10 ▶ &empty_period() if ($empty);
Branch: 1 branch
BranchTrueFalseTotal
if $empty 0 10 10
233 10 return $days;
234 }
235  
236 sub add_delta_workdays
237 7 ▶{
Subroutine add_delta_workdays: called CC=6 SCAR=18.9
Pod undocumented
238 7 my($self) = shift;
239 7 my($yy,$mm,$dd) = shift_date(\@_);
240 7 my($days) = shift;
241 7 my($date,$rest,$sign);
242  
243 7 ▶ if ($days == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($days == 0) { } 0 7 7
244 {
245 0 $rest = $self->year($yy)->date2index($yy,$mm,$dd); # check date
246 0 $date = Date::Calc->new($yy,$mm,$dd);
247 0 ▶ return wantarray ? ($date,$days) : $date;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
248 }
249 else
250 {
251 7 ▶ $sign = ($days > 0) ? +1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$days > 0 ? : 4 3 7
252 7 ($date,$rest,$sign) = $self->year($yy)->add_delta_workdays($yy,$mm,$dd,$days,$sign);
253 7 ▶ while ($sign)
Branch: 1 branch
BranchTrueFalseTotal
if ($sign) 7 7 14
254 {
255 7 ($date,$rest,$sign) = $self->year($date)->add_delta_workdays($date,$rest,$sign);
256 }
257 7 ▶ return wantarray ? ($date,$rest) : $date;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 1 7
258 }
259 }
260  
261 sub is_full
262 0 ▶{
Subroutine is_full: not called CC=1 SCAR=6.9
Pod undocumented
263 0 my($self) = shift;
264 0 my(@date) = shift_date(\@_);
265 0 my($year) = $self->year($date[0]);
266  
267 0 return $year->vec_full->bit_test( $year->date2index(@date) );
268 }
269  
270 sub is_half
271 0 ▶{
Subroutine is_half: not called CC=1 SCAR=6.9
Pod undocumented
272 0 my($self) = shift;
273 0 my(@date) = shift_date(\@_);
274 0 my($year) = $self->year($date[0]);
275  
276 0 return $year->vec_half->bit_test( $year->date2index(@date) );
277 }
278  
279 sub is_work
280 0 ▶{
Subroutine is_work: not called CC=1 SCAR=6.9
Pod undocumented
281 0 my($self) = shift;
282 0 my(@date) = shift_date(\@_);
283 0 my($year) = $self->year($date[0]);
284  
285 0 return $year->vec_work->bit_test( $year->date2index(@date) );
286 }
287  
288 4 1;
289  
290 __END__
« Calendar/Year.pm ↑ Summary Calc.pm »