Coerce/js/To_date/From_str/date_parse.pm

filter: Statementstmt 65.0% 13 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 59.2% 16 / 27 CC 1 SCAR 3.4
CC
1
Cov
65%
meta
2.0
coerce
2.0
BEGIN
1.0
CRAP 1.4
« Coerce/js/To_date/From_obj/date.pm ↑ Summary Coerce/perl/To_float/From_str/percent.pm »
1 package Data::Sah::Coerce::js::To_date::From_str::date_parse;
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 0 ▶sub meta {
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
13 +{
14 0 v => 4,
15 summary => 'Coerce date from string using Date.parse()',
16 might_fail => 1, # we throw exception date is invalid
17 prio => 50,
18 };
19 }
20  
21 0 ▶sub coerce {
Subroutine coerce: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my %args = @_;
23  
24 0 my $dt = $args{data_term};
25  
26 0 my $res = {};
27  
28 0 $res->{expr_match} = join(
29 " && ",
30 "typeof($dt)=='string'",
31 );
32  
33 # note: (function(a,b,c){...})() is a trick to simulate lexical variables
34 0 $res->{expr_coerce} = "(function (_m) { _m = new Date($dt); if (isNaN(_m)) { return ['Invalid date', _m] } else { return [null, _m] } })()";
35  
36 0 $res;
37 }
38  
39 3 1;
40 # ABSTRACT: Coerce date from string using Date.parse()
41  
42 __END__
« Coerce/js/To_date/From_obj/date.pm ↑ Summary Coerce/perl/To_float/From_str/percent.pm »