Pad/Type/Duration.pm

filter: Statementstmt 90.2% 37 / 41 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 87.5% 7 / 8 Podpod 75.0% 3 / 4 totaltotal 85.9% 55 / 64 CC 5 SCAR 7.9
CC
5
Cov
88%
span
4.0
check
2.0
label
1.5
CRAP 2.2
« Pad/Result.pm ↑ Summary Pad/Type.pm »
1 23 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 23 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 23 ▶use Getopt::Pad::Type::Temporal;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Type::Duration :isa(Getopt::Pad::Type::Temporal) :strict(params) {
7 23 ▶ use constant NAMES => ['duration'];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 our $VERSION = '0.06';
10  
11 0 ▶ method label() { return 'Duration' }
Subroutine label: not called CC=1 SCAR=4.1
Pod documented
12  
13 2 ▶ method check($value) {
Subroutine check: called CC=2 SCAR=7.0
Pod documented
14 2 ▶ return defined $self->span($value) ? undef : sprintf("'%s' is not a duration", $value);
Branch: 1 branch
BranchTrueFalseTotal
defined $self->span($value) ? : 0 2 2
15 23 }
16  
17 2 ▶ method coerce($value) {
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
18 2 my ($start, $end) = $self->span($value)->@*;
19 2 return $end->subtract_datetime($start);
20 23 }
21  
22 # The start and end of $value counted from now, or undef. A bare length
23 # gets the 'for' DateTime::Format::Natural expects. Both ends count from
24 # one pinned now, so the length carries no stray fraction of a second.
25 4 ▶ method span($value) {
Subroutine span: called CC=4 SCAR=13.9
Pod undocumented
26 4 my $parser = $self->newParser(datetime => DateTime->now(time_zone => $self->zone));
27 4 ▶ my @ends = $parser->parse_datetime_duration($value =~ /\A\s*for\b/i ? $value : "for $value");
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\A\s*for\b/iu ? : 1 3 4
28 4 ▶ return undef if !$parser->success || @ends != 2;
Branch: 1 branch
BranchTrueFalseTotal
if not $parser->success or @ends != 2 2 2 4
Condition66%2/3
not $parser->success or @ends != 2
l!l&&r!l&&!r
202
MC/DC50%1/2
not $parser->success or @ends != 2
not $parser->success @ends != 2
Truth table66%2/3
not(A) or B
A= not $parser->successB= @ends != 2
ABresult
1X1
011
000
29 2 return \@ends;
30 23 }
31 }
32  
33 23 1;
34  
35 __END__
« Pad/Result.pm ↑ Summary Pad/Type.pm »