Data/Sah/Coerce/perl/To_int/From_str/convert_en_dow_name_to_num.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 92.8% 26 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Sah/SchemaR/date/tz_name.pm ↑ Summary Data/Sah/Coerce/perl/To_int/From_str/convert_en_month_name_to_num.pm »
1 package Data::Sah::Coerce::perl::To_int::From_str::convert_en_dow_name_to_num;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2023-12-09'; # DATE
9 2 our $DIST = 'Sah-Schemas-Date'; # DIST
10 2 our $VERSION = '0.019'; # VERSION
11  
12 1 ▶sub meta {
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
13 +{
14 1 v => 4,
15 summary => 'Convert English day-of-week name (e.g. su, MON, Tuesday) to number (1-7, 1=Monday)',
16 prio => 50,
17 };
18 }
19  
20 1 ▶sub coerce {
Subroutine coerce: called CC=1 SCAR=0.0
Pod undocumented
21 1 my %args = @_;
22  
23 1 my $dt = $args{data_term};
24  
25 1 my $res = {};
26 1 my $pkg = __PACKAGE__;
27  
28 1 $res->{expr_match} = "!ref($dt)";
29 1 $res->{expr_coerce} = join(
30 "",
31 "do { ",
32  
33 # since this is a small translation table we put it inline, but for
34 # larger translation table we should move it to a separate perl module
35 "\$$pkg\::dow_nums ||= {",
36 " mo=>1, mon=>1, monday=>1, ",
37 " tu=>2, tue=>2, tuesday=>2, ",
38 " we=>3, wed=>3, wednesday=>3, ",
39 " th=>4, thu=>4, thursday=>4, ",
40 " fr=>5, fri=>5, friday=>5, ",
41 " sa=>6, sat=>6, saturday=>6, ",
42 " su=>7, sun=>7, sunday=>7, ",
43 "}; ",
44 "\$$pkg\::dow_nums->{lc $dt} || $dt; ",
45 "}",
46 );
47  
48 1 $res;
49 }
50  
51 2 1;
52 # ABSTRACT: Convert English day-of-week name (e.g. su, MON, Tuesday) to number (1-7, 1=Monday)
53  
54 __END__
« Sah/SchemaR/date/tz_name.pm ↑ Summary Data/Sah/Coerce/perl/To_int/From_str/convert_en_month_name_to_num.pm »