| 1 | package Data::Sah::Coerce::perl::To_duration::From_obj::datetime_duration; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use 5.010001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||
| 8 | 3 | our $DATE = '2023-10-24'; # DATE | |||||||||||||
| 9 | 3 | our $DIST = 'Data-Sah-Coerce'; # DIST | |||||||||||||
| 10 | 3 | our $VERSION = '0.054'; # VERSION | |||||||||||||
| 11 | |||||||||||||||
| 12 | 3 | ▶ | sub meta { | ||||||||||||
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 13 | +{ | ||||||||||||||
| 14 | 3 | v => 4, | |||||||||||||
| 15 | summary => 'Coerce duration from DateTime::Duration object', | ||||||||||||||
| 16 | prio => 50, | ||||||||||||||
| 17 | }; | ||||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 3 | ▶ | sub coerce { | ||||||||||||
|
Subroutine
coerce: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||
| 21 | 3 | my %args = @_; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 3 | my $dt = $args{data_term}; | |||||||||||||
| 24 | 3 | ▶ | my $coerce_to = $args{coerce_to} // 'float(secs)'; | ||||||||||||
|
Condition50%1/2
$args{"coerce_to"} // "float(secs)"
MC/DC0%0/1
$args{"coerce_to"} // "float(secs)"
$args{"coerce_to"}
Truth table50%1/2
A
A= $args{"coerce_to"}
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 3 | my $res = {}; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 3 | ▶ | $res->{modules}{'Scalar::Util'} //= 0; | ||||||||||||
|
Condition50%1/2
$res->{"modules"}{"Scalar::Util"} //= 0
MC/DC0%0/1
$res->{"modules"}{"Scalar::Util"} //= 0
$res->{"modules"}{"Scalar::Util"}
Truth table50%1/2
A
A= $res->{"modules"}{"Scalar::Util"}
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | 3 | $res->{expr_match} = join( | |||||||||||||
| 31 | " && ", | ||||||||||||||
| 32 | "Scalar::Util::blessed($dt)", | ||||||||||||||
| 33 | "$dt\->isa('DateTime::Duration')", | ||||||||||||||
| 34 | ); | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 3 | ▶ | if ($coerce_to eq 'float(secs)') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 37 | # approximation | ||||||||||||||
| 38 | 2 | $res->{expr_coerce} = "($dt\->years * 365.25*86400 + $dt\->months * 30.4375*86400 + $dt\->weeks * 7*86400 + $dt\->days * 86400 + $dt\->hours * 3600 + $dt\->minutes * 60 + $dt\->seconds + $dt\->nanoseconds * 1e-9)"; | |||||||||||||
| 39 | } elsif ($coerce_to eq 'DateTime::Duration') { | ||||||||||||||
| 40 | 1 | $res->{expr_coerce} = $dt; | |||||||||||||
| 41 | } else { | ||||||||||||||
| 42 | 0 | die "BUG: Unknown coerce_to value '$coerce_to', ". | |||||||||||||
| 43 | "please use float(secs) or DateTime::Duration"; | ||||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 3 | $res; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 3 | 1; | |||||||||||||
| 50 | # ABSTRACT: Coerce duration from DateTime::Duration object | ||||||||||||||
| 51 | |||||||||||||||
| 52 | __END__ | ||||||||||||||