| 1 | package Data::Sah::Coerce::js::To_duration::From_float::seconds; | ||
| 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 | 2 | ▶ | sub meta { |
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 13 | +{ | ||
| 14 | 2 | v => 4, | |
| 15 | summary => 'Coerce duration from number (assumed to be number of seconds)', | ||
| 16 | prio => 50, | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | 2 | ▶ | sub coerce { |
|
Subroutine
coerce: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 21 | 2 | my %args = @_; | |
| 22 | |||
| 23 | 2 | my $dt = $args{data_term}; | |
| 24 | 2 | my $coerce_to = $args{coerce_to}; | |
| 25 | |||
| 26 | 2 | my $res = {}; | |
| 27 | |||
| 28 | 2 | $res->{expr_match} = join( | |
| 29 | " && ", | ||
| 30 | "(typeof($dt)=='number' || typeof($dt)=='string' && $dt.match(/^[0-9]+(?:\\.[0-9]+)?\$/))", | ||
| 31 | "parseFloat($dt) >= 0", # we don't allow negative duration | ||
| 32 | "!isNaN(parseFloat($dt))", | ||
| 33 | "isFinite(parseFloat($dt))", # we don't allow infinite duration | ||
| 34 | ); | ||
| 35 | |||
| 36 | 2 | $res->{expr_coerce} = "parseFloat($dt)"; | |
| 37 | |||
| 38 | 2 | $res; | |
| 39 | } | ||
| 40 | |||
| 41 | 3 | 1; | |
| 42 | # ABSTRACT: Coerce duration from number (assumed to be number of seconds) | ||
| 43 | |||
| 44 | __END__ | ||