blib/lib/DateTime/Format/Duration/ConciseHMS.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 4 / 4 Conditioncond 72.2% 13 / 18 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 83.3% 50 / 60 CC 9 SCAR 19.1
CC
9
Cov
89%
format_duration
9.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.8
↑ Summary
1 package DateTime::Format::Duration::ConciseHMS;
2  
3 2 our $DATE = '2019-06-19'; # DATE
4 2 our $VERSION = '0.001'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 1 my ($class, %args) = @_;
12  
13 1 return bless \%args, $class;
14 }
15  
16 5 ▶sub format_duration {
Subroutine format_duration: called CC=9 SCAR=22.3
Pod documented
17 5 my ($self, $dtdur) = @_;
18  
19 5 ▶ unless (eval { $dtdur->isa('DateTime::Duration') }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $dtdur->isa("DateTime::Duration") } }) 1 4 5
20 1 die "'$dtdur' not a DateTime::Duration instance";
21 }
22  
23 4 my ($y, $m, $w, $d, $H, $M, $S, $ns) = (
24 $dtdur->years,
25 $dtdur->months,
26 $dtdur->weeks,
27 $dtdur->days,
28 $dtdur->hours,
29 $dtdur->minutes,
30 $dtdur->seconds,
31 $dtdur->nanoseconds,
32 );
33  
34 4 $d += $w * 7;
35  
36 4 ▶ my $has_date = $y || $m || $w || $d;
Condition66%6/9
$y || $m || $w || $d
l!l&&r!l&&!r
202
$y or $m or $w
l!l&&r!l&&!r
202
$y or $m
l!l&&r!l&&!r
202
MC/DC25%1/4
$y || $m || $w || $d
$y $m $w $d
Truth table40%2/5
A or B or C || D
A= $yB= $mC= $wD= $d
ABCDresult
1XXX1
01XX1
001X1
00011
00000
37 4 ▶ my $has_time = $H || $M || $S;
Condition66%4/6
$H || $M || $S
l!l&&r!l&&!r
202
$H or $M
l!l&&r!l&&!r
202
MC/DC33%1/3
$H || $M || $S
$H $M $S
Truth table50%2/4
A or B || C
A= $HB= $MC= $S
ABCresult
1XX1
01X1
0011
0000
38  
39 4 ▶ join(
Branch: 1 branch
BranchTrueFalseTotal
$ns ? : 1 3 4
Condition100%3/3
$has_time || !$has_date
l!l&&r!l&&!r
211
MC/DC100%2/2
$has_time || !$has_date
$has_time !$has_date
Truth table100%3/3
A || not(B)
A= $has_timeB= !$has_date
ABresult
1X1
011
000
40 " ",
41 ("${y}y") x !!$y,
42 ("${m}mo") x !!$m,
43 ("${d}d") x !!$d,
44 (
45 sprintf("%02d:%02d:%02d%s", $H, $M, $S,
46 $ns ? sprintf(".%03d", $ns/1e6) : "")
47 ) x !!($has_time || !$has_date),
48  
49 );
50 }
51  
52 2 1;
53 # ABSTRACT: Format DateTime::Duration object as concise HMS format
54  
55 __END__
↑ Summary