CalendarMonth/DateTool.pm

filter: Statementstmt 88.4% 567 / 641 Branchbran 37.7% 34 / 90 Conditioncond 14.8% 8 / 54 MC/DCmcdc 3.1% 1 / 32 Subroutinesub 92.5% 173 / 187 Podpod 100% 9 / 9 totaltotal 78.1% 792 / 1013 CC 70 SCAR 19.8
CC
70
Cov
78%
_dump_tests
56.0
_datemanip_fails
42.0
_ncal_cmd
23.3
CRAP 7.2
« CalendarMonth/Locale.pm ↑ Summary CalendarMonth/DateTool/DateTime.pm »
1 package HTML::CalendarMonth::DateTool;
2 {
3 10 $HTML::CalendarMonth::DateTool::VERSION = '1.26';
4 }
5  
6 # Base class for determining what date calculation package to use.
7  
8 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use File::Which qw( which );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 my %Toolmap = (
15 'Time::Local' => 'TimeLocal',
16 'Date::Calc' => 'DateCalc',
17 'DateTime' => 'DateTime',
18 'Date::Manip' => 'DateManip',
19 'ncal' => 'Ncal',
20 'cal' => 'Cal',
21 );
22  
23 10 my %Classmap;
24 10 $Classmap{lc $Toolmap{$_}} = $_ foreach keys %Toolmap;
25  
26 10 my($Cal_Cmd, $Ncal_Cmd);
27  
28 461 ▶sub _toolmap {
Subroutine _toolmap: called CC=5 SCAR=16.1
29 461 shift;
30 461 my $str = shift;
31 461 my $tool = $Toolmap{$str};
32 461 ▶ unless ($tool) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tool) 308 153 461
33 308 foreach (values %Toolmap) {
34 1085 ▶ if ($str =~ /^$_$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^$_$/i) 308 777 1085
35 308 $tool = $_;
36 308 last;
37 }
38 }
39 }
40 461 ▶ return unless $tool;
Branch: 1 branch
BranchTrueFalseTotal
unless $tool 0 461 461
41 461 join('::', __PACKAGE__, $tool);
42 }
43  
44 310 ▶sub new {
Subroutine new: called CC=7 SCAR=19.9
Pod documented
45 310 my $class = shift;
46 310 my $self = {};
47 310 bless $self, $class;
48 310 my %parms = @_;
49 310 $self->{year} = $parms{year};
50 310 $self->{month} = $parms{month};
51 310 $self->{weeknum} = $parms{weeknum};
52 310 $self->{historic} = $parms{historic};
53 310 ▶ if (! $self->{year}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"year"}) 1 309 310
54 1 my @dmy = $self->_dmy_now;
55 1 $self->{year} = $dmy[2];
56 1 ▶ $self->{month} ||= $dmy[1];
Condition33%1/3
$self->{"month"} ||= $dmy[1]
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"month"} ||= $dmy[1]
$self->{"month"} $dmy[1]
Truth table33%1/3
A ||= B
A= $self->{"month"}B= $dmy[1]
ABresult
1X1
011
000
57 }
58 310 ▶ $self->{month} ||= 1;
Condition50%1/2
$self->{"month"} ||= 1
l!l
3100
MC/DC0%0/1
$self->{"month"} ||= 1
$self->{"month"}
Truth table50%1/2
A
A= $self->{"month"}
Aresult
11
00
59 310 ▶ if ($parms{datetool}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parms{"datetool"}) 152 158 310
60 $self->{datetool} = $self->_toolmap($parms{datetool})
61 152 ▶ or croak "Sorry, didn't find a tool for datetool '$parms{datetool}'\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"datetool"} = $self->_toolmap($parms{"datetool"}) or croak(qq[Sorry, didn't find a tool for datetool '$parms{"datetool"}'\n]) 152 0 152
62 }
63 310 my $dc = $self->_summon_date_class;
64 308 ▶ unless (eval "require $dc") {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $dc") 0 308 308
65 0 croak "Problem loading $dc ($@)\n";
66 }
67 # rebless into new class
68 308 bless $self, $dc;
69 }
70  
71 1538 ▶sub year { shift->{year} }
Subroutine year: called CC=1 SCAR=0.0
Pod documented
72 1228 ▶sub month { shift->{month} }
Subroutine month: called CC=1 SCAR=0.0
Pod documented
73 310 ▶sub weeknum { shift->{weeknum} }
Subroutine weeknum: called CC=1 SCAR=0.0
Pod documented
74 0 ▶sub historic { shift->{historic} }
Subroutine historic: not called CC=1 SCAR=6.9
Pod documented
75 310 ▶sub datetool { shift->{datetool} }
Subroutine datetool: called CC=1 SCAR=0.0
Pod documented
76  
77 446 ▶sub _name {
Subroutine _name: called CC=2 SCAR=7.0
78 446 my $class = shift;
79 446 ▶ $class = ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
2941520
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
80 446 lc((split(/::/, $class))[-1]);
81 }
82  
83 1 ▶sub _cal_cmd {
Subroutine _cal_cmd: called CC=7 SCAR=30.7
84 1 my $self = shift;
85 1 ▶ if (! defined $Cal_Cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Cal_Cmd) 1 0 1
86 1 ▶ $Cal_Cmd = which('cal') || '';
Condition50%1/2
which('cal') || ''
l!l
01
MC/DC0%0/1
which('cal') || ''
which('cal')
Truth table50%1/2
A
A= which('cal')
Aresult
11
00
87 1 ▶ if ($Cal_Cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Cal_Cmd) 0 1 1
88 0 my @out = grep { ! /^\s*$/ } `$Cal_Cmd 9 1752`;
89 # September 1752
90 #Su Mo Tu We Th Fr Sa
91 # 1 2 14 15 16
92 #17 18 19 20 21 22 23
93 #24 25 26 27 28 29 30
94 0 my @pat = (
95 qr/^\s*\S+\s+\d+$/,
96 qr/^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s*$/,
97 qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/,
98 qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/,
99 qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/,
100 );
101 0 ▶ if (@out == @pat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@out == @pat) { } 0 0 0
102 0 for my $i (0 .. $#out) {
103 0 ▶ if ($out[$i] !~ $pat[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out[$i] =~ /$pat[$i]/) 0 0 0
104 0 $Cal_Cmd = '';
105 0 last;
106 }
107 }
108 }
109 else {
110 0 $Cal_Cmd = '';
111 }
112 }
113 }
114 1 $Cal_Cmd;
115 }
116  
117 1 ▶sub _ncal_cmd {
Subroutine _ncal_cmd: called CC=7 SCAR=31.5
118 1 my $self = shift;
119 1 ▶ if (! defined $Ncal_Cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Ncal_Cmd) 1 0 1
120 1 ▶ $Ncal_Cmd = which('ncal') || '';
Condition50%1/2
which('ncal') || ''
l!l
01
MC/DC0%0/1
which('ncal') || ''
which('ncal')
Truth table50%1/2
A
A= which('ncal')
Aresult
11
00
121 1 ▶ if ($Ncal_Cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Ncal_Cmd) 0 1 1
122 0 my @out = grep { ! /^\s*$/ } map { s/^\s*//; $_ } `$Ncal_Cmd 9 1752`;
123 # September 1752
124 #Mo 18 25
125 #Tu 1 19 26
126 #We 2 20 27
127 #Th 14 21 28
128 #Fr 15 22 29
129 #Sa 16 23 30
130 #Su 17 24
131 0 my @pat = (
132 qr/^\s*\S+\s+\d+$/,
133 qr/^\s*\S+\s+\d+\s+\d+\s*$/,
134 qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/,
135 qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/,
136 qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/,
137 qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/,
138 qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/,
139 qr/^\s*\S+\s+\d+\s+\d+\s*$/,
140 );
141 0 ▶ if (@out == @pat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@out == @pat) { } 0 0 0
142 0 for my $i (0 .. $#out) {
143 0 ▶ if ($out[$i] !~ $pat[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out[$i] =~ /$pat[$i]/) 0 0 0
144 0 $Ncal_Cmd = '';
145 0 last;
146 }
147 }
148 }
149 else {
150 0 $Ncal_Cmd = '';
151 }
152 }
153 }
154 1 $Ncal_Cmd;
155 }
156  
157 0 ▶sub day_epoch {
Subroutine day_epoch: not called CC=3 SCAR=24.8
Pod documented
158 # in case our subclasses are lazy
159 0 my($self, $day, $month, $year) = @_;
160 0 ▶ $month ||= $self->month;
Condition0%0/3
$month ||= $self->month
l!l&&r!l&&!r
000
MC/DC0%0/2
$month ||= $self->month
$month $self->month
Truth table0%0/3
A ||= B
A= $monthB= $self->month
ABresult
1X1
011
000
161 0 ▶ $year ||= $self->year;
Condition0%0/3
$year ||= $self->year
l!l&&r!l&&!r
000
MC/DC0%0/2
$year ||= $self->year
$year $self->year
Truth table0%0/3
A ||= B
A= $yearB= $self->year
ABresult
1X1
011
000
162 0 Time::Local::timegm(0,0,0,1,$month,$year);
163 }
164  
165 307 ▶sub _skips {
Subroutine _skips: called CC=2 SCAR=7.2
166 307 my $self = shift;
167 307 ▶ @_ ? $self->{skips} = shift : $self->{skips};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 307 307
168 }
169  
170 307 ▶sub dow1st { (shift->dow1st_and_lastday)[0] }
Subroutine dow1st: called CC=1 SCAR=0.0
Pod documented
171  
172 614 ▶sub lastday { (shift->dow1st_and_lastday)[1] }
Subroutine lastday: called CC=1 SCAR=0.0
Pod documented
173  
174 308 ▶sub _dmy_now {
Subroutine _dmy_now: called CC=2 SCAR=6.9
175 308 my $self = shift;
176 308 ▶ my $ts = @_ ? shift : time;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 307 1 308
177 308 my($d, $m, $y) = (localtime($ts))[3,4,5];
178 308 ++$m; $y += 1900;
179 308 ($d, $m, $y);
180 }
181  
182 307 ▶sub _dom_now {
Subroutine _dom_now: called CC=9 SCAR=31.4
183 307 my $self = shift;
184 307 ▶ my $ts = @_ ? shift : time;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 307 307
185 307 my($d, $m, $y);
186 307 ▶ if ($ts =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ts =~ /^\d+$/) { } 307 0 307
187 307 ▶ if (length $ts <= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ts <= 2) { } 0 307 307
188 0 ($d, $m, $y) = ($ts, $self->month, $self->year);
189 0 ▶ croak "invalid day of month (1 .. " . $self->lastday . ") '$ts'"
Branch: 1 branch
BranchTrueFalseTotal
unless $ts >= 1 and $ts <= $self->lastday 0 0 0
Condition0%0/3
$ts >= 1 and $ts <= $self->lastday
!ll&&!rl&&r
000
MC/DC0%0/2
$ts >= 1 and $ts <= $self->lastday
$ts >= 1 $ts <= $self->lastday
Truth table0%0/3
A and B
A= $ts >= 1B= $ts <= $self->lastday
ABresult
0X0
100
111
190 unless $ts >= 1 && $ts <= $self->lastday;
191 }
192 else {
193 307 ($d, $m, $y) = $self->_dmy_now($ts);
194 }
195 }
196 else {
197 0 ($y, $m, $d) = $ts =~ m{^(\d+)/(\d\d)/(\d\d)$};
198 0 ▶ croak "invalid yyyy/mm/dd date string '$ts'" unless defined $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 0 0 0
199 }
200 307 my($cy, $cm) = ($self->year, $self->month);
201 307 my $first = sprintf("%04d/%02d/%02d", $cy, $cm, 1);
202 307 my $last = sprintf("%04d/%02d/%02d", $cy, $cm, $self->lastday);
203 307 my $pivot = sprintf("%04d/%02d/%02d", $y, $m, $d);
204 307 ▶ return -1 if $pivot gt $last;
Branch: 1 branch
BranchTrueFalseTotal
if $pivot gt $last 307 0 307
205 0 ▶ return 0 if $pivot lt $first;
Branch: 1 branch
BranchTrueFalseTotal
if $pivot lt $first 0 0 0
206 0 $d;
207 }
208  
209 310 ▶sub _summon_date_class {
Subroutine _summon_date_class: called CC=7 SCAR=19.5
210 310 my $self = shift;
211 310 my @tools;
212 310 ▶ if (my $c = $self->datetool) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $self->datetool) { } 152 158 310
213 152 ▶ eval "use $c";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
214 152 ▶ die "invalid date tool $c : $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 152 152
215 152 @tools = $c->_name;
216 }
217 else {
218 158 @tools = qw( timelocal datecalc datetime datemanip ncal cal );
219 }
220 310 my($dc, @fails);
221 310 for my $tool (@tools) {
222 310 my $method = join('_', '', lc($tool), 'fails');
223 310 ▶ if (my $f = $self->$method) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $self->$method) { } 2 308 310
224 2 push(@fails, [$tool, $f]);
225 }
226 else {
227 308 $dc = $self->_toolmap($tool);
228 308 last;
229 }
230 }
231 310 ▶ return $dc if $dc;
Branch: 1 branch
BranchTrueFalseTotal
if $dc 308 2 310
232 2 ▶ if (@tools == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tools == 1) { } 2 0 2
233 2 croak "invalid date tool " . join(': ', @{$fails[0]});
234 }
235 else {
236 0 croak join("\n",
237 "no valid date tool found:",
238 map(sprintf("%11s: %s", @$_), @fails),
239 "\n"
240 );
241 }
242 }
243  
244 0 ▶sub _dump_tests {
Subroutine _dump_tests: not called CC=7 SCAR=40.3
245 0 my $self = shift;
246 0 ▶ print "Time::Local : ", $self->_timelocal_fails || 1, "\n";
Condition0%0/2
$self->_timelocal_fails || 1
l!l
00
MC/DC0%0/1
$self->_timelocal_fails || 1
$self->_timelocal_fails
Truth table0%0/2
A
A= $self->_timelocal_fails
Aresult
11
00
247 0 ▶ print " Date::Calc : ", $self->_datecalc_fails || 1, "\n";
Condition0%0/2
$self->_datecalc_fails || 1
l!l
00
MC/DC0%0/1
$self->_datecalc_fails || 1
$self->_datecalc_fails
Truth table0%0/2
A
A= $self->_datecalc_fails
Aresult
11
00
248 0 ▶ print " DateTime : ", $self->_datetime_fails || 1, "\n";
Condition0%0/2
$self->_datetime_fails || 1
l!l
00
MC/DC0%0/1
$self->_datetime_fails || 1
$self->_datetime_fails
Truth table0%0/2
A
A= $self->_datetime_fails
Aresult
11
00
249 0 ▶ print "Date::Manip : ", $self->_datemanip_fails || 1, "\n";
Condition0%0/2
$self->_datemanip_fails || 1
l!l
00
MC/DC0%0/1
$self->_datemanip_fails || 1
$self->_datemanip_fails
Truth table0%0/2
A
A= $self->_datemanip_fails
Aresult
11
00
250 0 ▶ print " ncal : ", $self->_ncal_fails || 1, "\n";
Condition0%0/2
$self->_ncal_fails || 1
l!l
00
MC/DC0%0/1
$self->_ncal_fails || 1
$self->_ncal_fails
Truth table0%0/2
A
A= $self->_ncal_fails
Aresult
11
00
251 0 ▶ print " cal : ", $self->_cal_fails || 1, "\n";
Condition0%0/2
$self->_cal_fails || 1
l!l
00
MC/DC0%0/1
$self->_cal_fails || 1
$self->_cal_fails
Truth table0%0/2
A
A= $self->_cal_fails
Aresult
11
00
252 }
253  
254 0 ▶sub _is_julian {
Subroutine _is_julian: not called CC=3 SCAR=24.8
255 0 my $self = shift;
256 0 my $y = $self->year;
257 0 ▶ $y < 1752 || ($y == 1752 && $self->month <= 9);
Branch: 1 branch
BranchTrueFalseTotal
$y < 1752 or $y == 1752 and $self->month <= 9 0 0 0
Condition0%0/6
$y < 1752 || $y == 1752 && $self->month <= 9
l!l&&r!l&&!r
000
$y == 1752 and $self->month <= 9
!ll&&!rl&&r
000
MC/DC0%0/3
$y < 1752 || $y == 1752 && $self->month <= 9
$y < 1752 $y == 1752 $self->month <= 9
Truth table0%0/4
A || B and C
A= $y < 1752B= $y == 1752C= $self->month <= 9
ABCresult
1XX1
0111
00X0
0100
258 }
259  
260 310 ▶sub _timelocal_fails {
Subroutine _timelocal_fails: called CC=5 SCAR=16.5
261 310 my $self = shift;
262 310 ▶ return "not installed" unless $self->_timelocal_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_timelocal_present 0 310 310
263 310 ▶ return "week-of-year numbering unsupported" if $self->weeknum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->weeknum 0 310 310
264 310 my $y = $self->year;
265 310 ▶ return "only years between 1970 and 2038 supported"
Branch: 1 branch
BranchTrueFalseTotal
if $y < 1970 or $y >= 2038 2 308 310
Condition66%2/3
$y < 1970 or $y >= 2038
l!l&&r!l&&!r
20308
MC/DC50%1/2
$y < 1970 or $y >= 2038
$y < 1970 $y >= 2038
Truth table66%2/3
A or B
A= $y < 1970B= $y >= 2038
ABresult
1X1
011
000
266 if $y < 1970 || $y >= 2038;
267 308 return;
268 }
269  
270 0 ▶sub _ncal_fails {
Subroutine _ncal_fails: not called CC=4 SCAR=30.0
271 0 my $self = shift;
272 0 ▶ return "command not found" unless $self->_ncal_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_ncal_present 0 0 0
273 0 ▶ return "week-of-year numbering not supported prior to 1752/09"
Branch: 1 branch
BranchTrueFalseTotal
if $self->weeknum and $self->_is_julian 0 0 0
Condition0%0/3
$self->weeknum and $self->_is_julian
!ll&&!rl&&r
000
MC/DC0%0/2
$self->weeknum and $self->_is_julian
$self->weeknum $self->_is_julian
Truth table0%0/3
A and B
A= $self->weeknumB= $self->_is_julian
ABresult
0X0
100
111
274 if $self->weeknum && $self->_is_julian;
275 0 return;
276 }
277  
278 0 ▶sub _cal_fails {
Subroutine _cal_fails: not called CC=3 SCAR=24.8
279 0 my $self = shift;
280 0 ▶ return "command not found" unless $self->_cal_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_cal_present 0 0 0
281 0 ▶ return "week-of-year numbering not supported" if $self->weeknum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->weeknum 0 0 0
282 0 return;
283 }
284  
285 0 ▶sub _datecalc_fails {
Subroutine _datecalc_fails: not called CC=4 SCAR=30.0
286 0 my $self = shift;
287 0 ▶ return "not installed" unless $self->_datecalc_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_datecalc_present 0 0 0
288 0 ▶ return "historic mode prior to 1752/09 not supported"
Branch: 1 branch
BranchTrueFalseTotal
if $self->historic and $self->_is_julian 0 0 0
Condition0%0/3
$self->historic and $self->_is_julian
!ll&&!rl&&r
000
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic $self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
ABresult
0X0
100
111
289 if $self->historic && $self->_is_julian;
290 0 return;
291 }
292  
293 0 ▶sub _datetime_fails {
Subroutine _datetime_fails: not called CC=4 SCAR=30.0
294 0 my $self = shift;
295 0 ▶ return "not installed" unless $self->_datetime_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_datetime_present 0 0 0
296 0 ▶ return "historic mode prior to 1752/09 not supported"
Branch: 1 branch
BranchTrueFalseTotal
if $self->historic and $self->_is_julian 0 0 0
Condition0%0/3
$self->historic and $self->_is_julian
!ll&&!rl&&r
000
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic $self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
ABresult
0X0
100
111
297 if $self->historic && $self->_is_julian;
298 0 return;
299 }
300  
301 0 ▶sub _datemanip_fails {
Subroutine _datemanip_fails: not called CC=6 SCAR=37.4
302 0 my $self = shift;
303 0 ▶ return "not installed" unless $self->_datemanip_present;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_datemanip_present 0 0 0
304 0 ▶ return "historic mode prior to 1752/09 not supported"
Branch: 1 branch
BranchTrueFalseTotal
if $self->historic and $self->_is_julian 0 0 0
Condition0%0/3
$self->historic and $self->_is_julian
!ll&&!rl&&r
000
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic $self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
ABresult
0X0
100
111
305 if $self->historic && $self->_is_julian;
306 0 ▶ eval { require Date::Manip && Date::Manip::Date_Init() };
Branch: 1 branch
BranchTrueFalseTotal
require Date::Manip and Date::Manip::Date_Init() 0 0 0
307 0 ▶ return "init failure: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
308 0 return;
309 }
310  
311 310 ▶sub _timelocal_present { eval "require Time::Local"; return !$@ }
Subroutine _timelocal_present: called CC=1 SCAR=0.0
312 0 ▶sub _datecalc_present { eval "require Date::Calc"; return !$@ }
Subroutine _datecalc_present: not called CC=1 SCAR=6.9
313 0 ▶sub _datetime_present { eval "require DateTime"; return !$@ }
Subroutine _datetime_present: not called CC=1 SCAR=6.9
314 0 ▶sub _datemanip_present { eval "require Date::Manip"; return !$@ }
Subroutine _datemanip_present: not called CC=1 SCAR=6.9
315 0 ▶sub _ncal_present { shift->_ncal_cmd }
Subroutine _ncal_present: not called CC=1 SCAR=6.9
316 0 ▶sub _cal_present { shift->_cal_cmd };
Subroutine _cal_present: not called CC=1 SCAR=6.9
317  
318  
319 10 1;
320  
321 __END__
« CalendarMonth/Locale.pm ↑ Summary CalendarMonth/DateTool/DateTime.pm »