| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | 4 | ▶ | return undef if !$parser->success || @ends != 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $parser->success or @ends != 2
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
| |||||||||||||||||||||||||||||
| 29 | 2 | return \@ends; | |||||||||||||||||||||||||||
| 30 | 23 | } | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 23 | 1; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | __END__ | ||||||||||||||||||||||||||||