blib/lib/App/datecalc.pm

filter: Statementstmt 95.0% 134 / 141 Branchbran 85.5% 101 / 118 Conditioncond 83.3% 10 / 12 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 25 / 25 Podpod 100% 2 / 2 totaltotal 90.8% 277 / 305 CC 64 SCAR 20.8
CC
64
Cov
90%
__ANON__
16.3
__fmtduriso
12.3
__ANON__
10.0
CRAP 8.0
↑ Summary
1 package App::datecalc;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MarpaX::Simple qw(gen_parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 2 our $DATE = '2023-02-18'; # DATE
14 2 our $DIST = 'App-datecalc'; # DIST
15 2 our $VERSION = '0.090'; # VERSION
16  
17 # XXX there should already be an existing module that does this
18 10 ▶sub __fmtduriso {
Subroutine __fmtduriso: called CC=12 SCAR=25.1
19 10 my $dur = shift;
20 10 ▶ my $res = join(
Branch: 4 branches
BranchTrueFalseTotal
$dur->years ? : 0 10 10
$dur->months ? : 0 10 10
$dur->weeks ? : 4 6 10
$dur->days ? : 9 1 10
21 '',
22 "P",
23 ($dur->years ? $dur->years . "Y" : ""),
24 ($dur->months ? $dur->months . "M" : ""),
25 ($dur->weeks ? $dur->weeks . "W" : ""),
26 ($dur->days ? $dur->days . "D" : ""),
27 );
28 10 ▶ if ($dur->hours || $dur->minutes || $dur->seconds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dur->hours or $dur->minutes or $dur->seconds) 3 7 10
Condition83%5/6
$dur->hours or $dur->minutes or $dur->seconds
l!l&&r!l&&!r
307
$dur->hours or $dur->minutes
l!l&&r!l&&!r
217
MC/DC66%2/3
$dur->hours or $dur->minutes or $dur->seconds
$dur->hours $dur->minutes $dur->seconds
Truth table75%3/4
A or B or C
A= $dur->hoursB= $dur->minutesC= $dur->seconds
ABCresult
1XX1
01X1
0011
0000
29 3 ▶ $res .= join(
Branch: 3 branches
BranchTrueFalseTotal
$dur->hours ? : 2 1 3
$dur->minutes ? : 2 1 3
$dur->seconds ? : 1 2 3
30 '',
31 'T',
32 ($dur->hours ? $dur->hours . "H" : ""),
33 ($dur->minutes ? $dur->minutes . "M" : ""),
34 ($dur->seconds ? $dur->seconds . "S" : ""),
35 );
36 }
37  
38 10 ▶ $res = "P0Y" if $res eq 'P';
Branch: 1 branch
BranchTrueFalseTotal
if $res eq "P" 0 10 10
39  
40 10 $res;
41 }
42  
43 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
44 state $parser = gen_parser(
45 grammar => <<'_',
46 :default ::= action=>::first
47 lexeme default = latm=>1
48 :start ::= answer
49  
50 answer ::= date_expr
51 | dur_expr
52 # | str_expr
53 | num_expr
54  
55 num_expr ::= num_add
56 num_add ::= num_mult
57 | num_add op_addsub num_add action=>num_add
58 num_mult ::= num_unary
59 | num_mult op_multdiv num_mult action=>num_mult
60 num_unary ::= num_pow
61 || op_unary num_unary action=>num_unary assoc=>right
62 num_pow ::= num_term
63 || num_pow '**' num_pow action=>num_pow assoc=>right
64 num_term ::= num_literal
65 | func_inum_onum
66 | func_idate_onum
67 | func_idur_onum
68 | ('(') num_expr (')')
69  
70 date_expr ::= date_add_dur
71 date_add_dur ::= date_term
72 | date_add_dur op_addsub dur_term action=>date_add_dur
73 date_term ::= date_literal
74 # | date_variable
75 # | func_idate_odate
76 | ('(') date_expr (')')
77  
78 func_inum_onum_names ~ 'abs' | 'round'
79 func_inum_onum ::= func_inum_onum_names ('(') num_expr (')') action=>func_inum_onum
80  
81 func_idate_onum_names ~ 'year' | 'month' | 'day' | 'dow' | 'quarter'
82 | 'doy' | 'wom' | 'woy' | 'doq'
83 | 'hour' | 'minute' | 'second'
84 func_idate_onum ::= func_idate_onum_names ('(') date_expr (')') action=>func_idate_onum
85  
86 func_idur_onum_names ~ 'years' | 'months' | 'weeks' | 'days'
87 | 'hours' | 'minutes' | 'seconds'
88 | 'totdays'
89 func_idur_onum ::= func_idur_onum_names ('(') dur_expr (')') action=>func_idur_onum
90  
91 date_literal ::= iso_date_literal action=>datelit_iso
92 | 'now' action=>datelit_special
93 | 'today' action=>datelit_special
94 | 'yesterday' action=>datelit_special
95 | 'tomorrow' action=>datelit_special
96  
97 year4 ~ [\d][\d][\d][\d]
98 mon2 ~ [\d][\d]
99 day2 ~ [\d][\d]
100 iso_date_literal ~ year4 '-' mon2 '-' day2
101  
102 dur_expr ::= dur_add_dur
103 | date_sub_date
104 dur_add_dur ::= dur_mult_num
105 | dur_add_dur op_addsub dur_add_dur action=>dur_add_dur
106 date_sub_date ::= date_add_dur
107 | date_sub_date '-' date_sub_date action=>date_sub_date
108  
109 dur_mult_num ::= dur_term
110 | dur_mult_num op_multdiv num_expr action=>dur_mult_num
111 | num_expr op_mult dur_mult_num action=>dur_mult_num
112 dur_term ::= dur_literal
113 # | dur_variable
114 | '(' dur_expr ')'
115 dur_literal ::= nat_dur_literal
116 | iso_dur_literal
117  
118 unit_year ~ 'year' | 'years' | 'y'
119 unit_month ~ 'month' | 'months' | 'mon' | 'mons'
120 unit_week ~ 'week' | 'weeks' | 'w'
121 unit_day ~ 'day' | 'days' | 'd'
122 unit_hour ~ 'hour' | 'hours' | 'h'
123 unit_minute ~ 'minute' | 'minutes' | 'min' | 'mins'
124 unit_second ~ 'second' | 'seconds' | 'sec' | 'secs' | 's'
125  
126 ndl_year ~ num ws_opt unit_year
127 ndl_year_opt ~ num ws_opt unit_year
128 ndl_year_opt ~
129  
130 ndl_month ~ num ws_opt unit_month
131 ndl_month_opt ~ num ws_opt unit_month
132 ndl_month_opt ~
133  
134 ndl_week ~ num ws_opt unit_week
135 ndl_week_opt ~ num ws_opt unit_week
136 ndl_week_opt ~
137  
138 ndl_day ~ num ws_opt unit_day
139 ndl_day_opt ~ num ws_opt unit_day
140 ndl_day_opt ~
141  
142 ndl_hour ~ num ws_opt unit_hour
143 ndl_hour_opt ~ num ws_opt unit_hour
144 ndl_hour_opt ~
145  
146 ndl_minute ~ num ws_opt unit_minute
147 ndl_minute_opt ~ num ws_opt unit_minute
148 ndl_minute_opt ~
149  
150 ndl_second ~ num ws_opt unit_second
151 ndl_second_opt ~ num ws_opt unit_second
152 ndl_second_opt ~
153  
154 # need at least one element specified. XXX not happy with this
155 nat_dur_literal ::= nat_dur_literal0 action=>durlit_nat
156 nat_dur_literal0 ~ ndl_year ws_opt ndl_month_opt ws_opt ndl_week_opt ws_opt ndl_day_opt ws_opt ndl_hour_opt ws_opt ndl_minute_opt ws_opt ndl_second_opt
157 | ndl_year_opt ws_opt ndl_month ws_opt ndl_week_opt ws_opt ndl_day_opt ws_opt ndl_hour_opt ws_opt ndl_minute_opt ws_opt ndl_second_opt
158 | ndl_year_opt ws_opt ndl_month_opt ws_opt ndl_week ws_opt ndl_day_opt ws_opt ndl_hour_opt ws_opt ndl_minute_opt ws_opt ndl_second_opt
159 | ndl_year_opt ws_opt ndl_month_opt ws_opt ndl_week_opt ws_opt ndl_day ws_opt ndl_hour_opt ws_opt ndl_minute_opt ws_opt ndl_second_opt
160 | ndl_year_opt ws_opt ndl_month_opt ws_opt ndl_week_opt ws_opt ndl_day_opt ws_opt ndl_hour ws_opt ndl_minute_opt ws_opt ndl_second_opt
161 | ndl_year_opt ws_opt ndl_month_opt ws_opt ndl_week_opt ws_opt ndl_day_opt ws_opt ndl_hour_opt ws_opt ndl_minute ws_opt ndl_second_opt
162 | ndl_year_opt ws_opt ndl_month_opt ws_opt ndl_week_opt ws_opt ndl_day_opt ws_opt ndl_hour_opt ws_opt ndl_minute_opt ws_opt ndl_second
163  
164 idl_year ~ posnum 'Y'
165 idl_year_opt ~ posnum 'Y'
166 idl_year_opt ~
167  
168 idl_month ~ posnum 'M'
169 idl_month_opt ~ posnum 'M'
170 idl_month_opt ~
171  
172 idl_week ~ posnum 'W'
173 idl_week_opt ~ posnum 'W'
174 idl_week_opt ~
175  
176 idl_day ~ posnum 'D'
177 idl_day_opt ~ posnum 'D'
178 idl_day_opt ~
179  
180 idl_hour ~ posnum 'H'
181 idl_hour_opt ~ posnum 'H'
182 idl_hour_opt ~
183  
184 idl_minute ~ posnum 'M'
185 idl_minute_opt ~ posnum 'M'
186 idl_minute_opt ~
187  
188 idl_second ~ posnum 'S'
189 idl_second_opt ~ posnum 'S'
190 idl_second_opt ~
191  
192 # also need at least one element specified like in nat_dur_literal
193 iso_dur_literal ::= iso_dur_literal0 action=>durlit_iso
194 iso_dur_literal0 ~ 'P' idl_year idl_month_opt idl_week_opt idl_day_opt
195 | 'P' idl_year_opt idl_month idl_week_opt idl_day_opt
196 | 'P' idl_year_opt idl_month_opt idl_week idl_day_opt
197 | 'P' idl_year_opt idl_month_opt idl_week_opt idl_day
198 | 'P' idl_year_opt idl_month_opt idl_week_opt idl_day_opt 'T' idl_hour idl_minute_opt idl_second_opt
199 | 'P' idl_year_opt idl_month_opt idl_week_opt idl_day_opt 'T' idl_hour_opt idl_minute idl_second_opt
200 | 'P' idl_year_opt idl_month_opt idl_week_opt idl_day_opt 'T' idl_hour_opt idl_minute_opt idl_second
201  
202 sign ~ [+-]
203 digits ~ [\d]+
204 num_literal ~ num
205 num ~ digits
206 | sign digits
207 | digits '.' digits
208 | sign digits '.' digits
209 posnum ~ digits
210 | digits '.' digits
211  
212 op_unary ~ [+-]
213 op_addsub ~ [+-]
214  
215 op_mult ~ [*]
216 op_multdiv ~ [*/]
217  
218 :discard ~ ws
219 ws ~ [\s]+
220 ws_opt ~ [\s]*
221  
222 _
223 actions => {
224 15 ▶ datelit_iso => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
225 15 my $h = shift;
226 15 my @date = split /-/, $_[0];
227 15 DateTime->new(year=>$date[0], month=>$date[1], day=>$date[2]);
228 },
229 1 ▶ date_sub_date => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
230 1 my $h = shift;
231 1 $_[0]->delta_days($_[2]);
232 },
233 4 ▶ datelit_special => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
234 4 my $h = shift;
235 4 ▶ if ($_[0] eq 'now') {
Branch: 4 branches
BranchTrueFalseTotal
if ($_[0] eq 'now') { } 1 3 4
elsif ($_[0] eq 'today') { } 1 2 3
elsif ($_[0] eq 'yesterday') { } 1 1 2
elsif ($_[0] eq 'tomorrow') { } 1 0 1
236 1 DateTime->now;
237 } elsif ($_[0] eq 'today') {
238 1 DateTime->today;
239 } elsif ($_[0] eq 'yesterday') {
240 1 DateTime->today->subtract(days => 1);
241 } elsif ($_[0] eq 'tomorrow') {
242 1 DateTime->today->add(days => 1);
243 } else {
244 0 die "BUG: Unknown date literal '$_[0]'";
245 }
246 },
247 2 ▶ date_add_dur => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
248 2 my $h = shift;
249 2 ▶ if ($_[1] eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq '+') { } 1 1 2
250 1 $_[0] + $_[2];
251 } else {
252 1 $_[0] - $_[2];
253 }
254 },
255 1 ▶ dur_add_dur => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
256 1 my $h = shift;
257 1 $_[0] + $_[2];
258 },
259 4 ▶ dur_mult_num => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
260 4 my $h = shift;
261 4 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 2 2 4
262 2 my $d0 = $_[0];
263 2 ▶ if ($_[1] eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq '*') { } 1 1 2
264 # dur*num
265 1 DateTime::Duration->new(
266 years => $d0->years * $_[2],
267 months => $d0->months * $_[2],
268 weeks => $d0->weeks * $_[2],
269 days => $d0->days * $_[2],
270 hours => $d0->hours * $_[2],
271 minutes => $d0->minutes * $_[2],
272 seconds => $d0->seconds * $_[2],
273 );
274 } else {
275 # dur/num
276 1 DateTime::Duration->new(
277 years => $d0->years / $_[2],
278 months => $d0->months / $_[2],
279 weeks => $d0->weeks / $_[2],
280 days => $d0->days / $_[2],
281 hours => $d0->hours / $_[2],
282 minutes => $d0->minutes / $_[2],
283 seconds => $d0->seconds / $_[2],
284 );
285 }
286 } else {
287 2 my $d0 = $_[2];
288 # num * dur
289 2 DateTime::Duration->new(
290 years => $d0->years * $_[0],
291 months => $d0->months * $_[0],
292 weeks => $d0->weeks * $_[0],
293 days => $d0->days * $_[0],
294 hours => $d0->hours * $_[0],
295 minutes => $d0->minutes * $_[0],
296 seconds => $d0->seconds * $_[0],
297 );
298 }
299 },
300 4 ▶ durlit_nat => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
301 4 my $h = shift;
302 4 local $_ = $_[0];
303 4 my %params;
304 4 ▶ $params{years} = $1 if /(-?\d+(?:\.\d+)?)\s*(years?|y)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(years?|y)/ 0 4 4
305 4 ▶ $params{months} = $1 if /(-?\d+(?:\.\d+)?)\s*(mons?|months?)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(mons?|months?)/ 0 4 4
306 4 ▶ $params{weeks} = $1 if /(-?\d+(?:\.\d+)?)\s*(weeks?|w)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(weeks?|w)/ 1 3 4
307 4 ▶ $params{days} = $1 if /(-?\d+(?:\.\d+)?)\s*(days?|d)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(days?|d)/ 2 2 4
308 4 ▶ $params{hours} = $1 if /(-?\d+(?:\.\d+)?)\s*(hours?|h)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(hours?|h)/ 1 3 4
309 4 ▶ $params{minutes} = $1 if /(-?\d+(?:\.\d+)?)\s*(mins?|minutes?)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(mins?|minutes?)/ 1 3 4
310 4 ▶ $params{seconds} = $1 if /(-?\d+(?:\.\d+)?)\s*(s|secs?|seconds?)/;
Branch: 1 branch
BranchTrueFalseTotal
if /(-?\d+(?:\.\d+)?)\s*(s|secs?|seconds?)/ 1 3 4
311 4 DateTime::Duration->new(%params);
312 },
313 16 ▶ durlit_iso => sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
314 16 my $h = shift;
315 # split between date and time
316 16 ▶ my $d = $_[0] =~ /P(.+?)(?:T|\z)/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /P(.+?)(?:T|\z)/ ? : 16 0 16
317 16 ▶ my $t = $_[0] =~ /T(.*)/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /T(.*)/ ? : 4 12 16
318 #say "D = $d, T = $t";
319 16 my %params;
320 16 ▶ $params{years} = $1 if $d =~ /(-?\d+(?:\.\d+)?)Y/i;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /(-?\d+(?:\.\d+)?)Y/i 2 14 16
321 16 ▶ $params{months} = $1 if $d =~ /(-?\d+(?:\.\d+)?)M/i;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /(-?\d+(?:\.\d+)?)M/i 3 13 16
322 16 ▶ $params{weeks} = $1 if $d =~ /(-?\d+(?:\.\d+)?)W/;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /(-?\d+(?:\.\d+)?)W/ 0 16 16
323 16 ▶ $params{days} = $1 if $d =~ /(-?\d+(?:\.\d+)?)D/;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /(-?\d+(?:\.\d+)?)D/ 11 5 16
324 16 ▶ $params{hours} = $1 if $t =~ /(-?\d+(?:\.\d+)?)H/i;
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /(-?\d+(?:\.\d+)?)H/i 2 14 16
325 16 ▶ $params{minutes} = $1 if $t =~ /(-?\d+(?:\.\d+)?)M/i;
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /(-?\d+(?:\.\d+)?)M/i 2 14 16
326 16 ▶ $params{seconds} = $1 if $t =~ /(-?\d+(?:\.\d+)?)S/i;
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /(-?\d+(?:\.\d+)?)S/i 1 15 16
327 16 DateTime::Duration->new(%params);
328 },
329 3 ▶ func_inum_onum => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
330 3 my $h = shift;
331 3 my $fn = $_[0];
332 3 my $num = $_[1];
333 3 ▶ if ($fn eq 'abs') {
Branch: 2 branches
BranchTrueFalseTotal
if ($fn eq 'abs') { } 1 2 3
elsif ($fn eq 'round') { } 2 0 2
334 1 abs($num);
335 } elsif ($fn eq 'round') {
336 2 sprintf("%.0f", $num);
337 } else {
338 0 die "BUG: Unknown number function $fn";
339 }
340 },
341 9 ▶ func_idate_onum => sub {
Subroutine __ANON__: called CC=13 SCAR=27.9
342 9 my $h = shift;
343 9 my $fn = $_[0];
344 9 my $d = $_[1];
345 9 ▶ if ($fn eq 'year') {
Branch: 12 branches
BranchTrueFalseTotal
if ($fn eq 'year') { } 1 8 9
elsif ($fn eq 'month') { } 1 7 8
elsif ($fn eq 'day') { } 1 6 7
elsif ($fn eq 'dow') { } 1 5 6
elsif ($fn eq 'quarter') { } 1 4 5
elsif ($fn eq 'doy') { } 1 3 4
elsif ($fn eq 'wom') { } 1 2 3
elsif ($fn eq 'woy') { } 1 1 2
elsif ($fn eq 'doq') { } 1 0 1
elsif ($fn eq 'hour') { } 0 0 0
elsif ($fn eq 'minute') { } 0 0 0
elsif ($fn eq 'second') { } 0 0 0
346 1 $d->year;
347 } elsif ($fn eq 'month') {
348 1 $d->month;
349 } elsif ($fn eq 'day') {
350 1 $d->day;
351 } elsif ($fn eq 'dow') {
352 1 $d->day_of_week;
353 } elsif ($fn eq 'quarter') {
354 1 $d->quarter;
355 } elsif ($fn eq 'doy') {
356 1 $d->day_of_year;
357 } elsif ($fn eq 'wom') {
358 1 $d->week_of_month;
359 } elsif ($fn eq 'woy') {
360 1 $d->week_number;
361 } elsif ($fn eq 'doq') {
362 1 $d->day_of_quarter;
363 } elsif ($fn eq 'hour') {
364 0 $d->hour;
365 } elsif ($fn eq 'minute') {
366 0 $d->minute;
367 } elsif ($fn eq 'second') {
368 0 $d->second;
369 } else {
370 0 die "BUG: Unknown date function $fn";
371 }
372 },
373 8 ▶ func_idur_onum => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
374 8 my $h = shift;
375 8 my $fn = $_[0];
376 8 my $dur = $_[1];
377 8 ▶ if ($fn eq 'years') {
Branch: 8 branches
BranchTrueFalseTotal
if ($fn eq 'years') { } 1 7 8
elsif ($fn eq 'months') { } 1 6 7
elsif ($fn eq 'weeks') { } 1 5 6
elsif ($fn eq 'days') { } 1 4 5
elsif ($fn eq 'totdays') { } 1 3 4
elsif ($fn eq 'hours') { } 1 2 3
elsif ($fn eq 'minutes') { } 1 1 2
elsif ($fn eq 'seconds') { } 1 0 1
378 1 $dur->years;
379 } elsif ($fn eq 'months') {
380 1 $dur->months;
381 } elsif ($fn eq 'weeks') {
382 1 $dur->weeks;
383 } elsif ($fn eq 'days') {
384 1 $dur->days;
385 } elsif ($fn eq 'totdays') {
386 1 $dur->in_units("days");
387 } elsif ($fn eq 'hours') {
388 1 $dur->hours;
389 } elsif ($fn eq 'minutes') {
390 1 $dur->minutes;
391 } elsif ($fn eq 'seconds') {
392 1 $dur->seconds;
393 } else {
394 0 die "BUG: Unknown duration function $fn";
395 }
396 },
397 2 ▶ num_add => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
398 2 my $h = shift;
399 2 ▶ if ($_[1] eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq '+') { } 1 1 2
400 1 $_[0] + $_[2];
401 } else {
402 1 $_[0] - $_[2];
403 }
404 },
405 6 ▶ num_mult => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
406 6 my $h = shift;
407 6 ▶ if ($_[1] eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq '*') { } 5 1 6
408 5 $_[0] * $_[2];
409 } else {
410 1 $_[0] / $_[2];
411 }
412 },
413 2 ▶ num_unary => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
414 2 my $h = shift;
415 2 my $op = $_[0];
416 2 my $num = $_[1];
417 2 ▶ if ($op eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '+') { } 1 1 2
418 1 $num;
419 } else {
420 # -
421 1 -$num;
422 }
423 },
424 2 ▶ num_pow => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
425 2 my $h = shift;
426 2 $_[0] ** $_[2];
427 },
428 },
429 trace_terminals => $ENV{DEBUG},
430 trace_values => $ENV{DEBUG},
431 1 );
432  
433 1 bless {parser=>$parser}, shift;
434 }
435  
436 46 ▶sub eval {
Subroutine eval: called CC=5 SCAR=16.1
Pod documented
437 46 my ($self, $str) = @_;
438 46 my $res = $self->{parser}->($str);
439  
440 43 ▶ if (blessed($res) && $res->isa('DateTime::Duration')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($res) and $res->isa('DateTime::Duration')) { } 10 33 43
elsif (builtin::blessed($res) and $res->isa('DateTime')) { } 7 26 33
Condition100%3/3
builtin::blessed($res) and $res->isa("DateTime::Duration")
!ll&&!rl&&r
26710
MC/DC100%2/2
builtin::blessed($res) and $res->isa("DateTime::Duration")
builtin::blessed($res) $res->isa("DateTime::Duration")
Truth table100%3/3
A and B
A= builtin::blessed($res)B= $res->isa("DateTime::Duration")
ABresult
0X0
100
111
441 10 __fmtduriso($res);
442 ▶ } elsif (blessed($res) && $res->isa('DateTime')) {
Condition66%2/3
builtin::blessed($res) and $res->isa("DateTime")
!ll&&!rl&&r
2607
MC/DC50%1/2
builtin::blessed($res) and $res->isa("DateTime")
builtin::blessed($res) $res->isa("DateTime")
Truth table66%2/3
A and B
A= builtin::blessed($res)B= $res->isa("DateTime")
ABresult
0X0
100
111
443 7 $res->ymd . "#".$res->day_abbr;
444 } else {
445 26 "$res";
446 }
447 }
448  
449 2 1;
450 # ABSTRACT: Date calculator
451  
452 __END__
↑ Summary