File Coverage

blib/lib/Data/Sah/Coerce/perl/To_int/From_str/convert_en_month_name_to_num.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 21 23 91.3


line stmt bran cond sub pod time code
1              
2             use 5.010001;
3 1     1   1784 use strict;
  1         3  
4 1     1   5 use warnings;
  1         2  
  1         17  
5 1     1   4  
  1         2  
  1         166  
6             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7             our $DATE = '2022-10-12'; # DATE
8             our $DIST = 'Sah-Schemas-Date'; # DIST
9             our $VERSION = '0.018'; # VERSION
10              
11             +{
12             v => 4,
13             summary => 'Convert English month name (e.g. Dec, april) to number (1-12)',
14 1     1 0 11 prio => 50,
15             };
16             }
17              
18             my %args = @_;
19              
20             my $dt = $args{data_term};
21 1     1 0 17  
22             my $res = {};
23 1         2 my $pkg = __PACKAGE__;
24              
25 1         2 $res->{expr_match} = "!ref($dt)";
26 1         1 $res->{expr_coerce} = join(
27             "",
28 1         3 "do { ",
29 1         5  
30             # since this is a small translation table we put it inline, but for
31             # larger translation table we should move it to a separate perl module
32             "\$$pkg\::month_nums ||= {",
33             " jan=>1, january=>1, ",
34             " feb=>2, february=>2, ",
35             " mar=>3, march=>3, ",
36             " apr=>4, april=>4, ",
37             " may=>5, ",
38             " jun=>6, june=>6, ",
39             " jul=>7, july=>7, ",
40             " aug=>8, august=>8, ",
41             " sep=>9, sept=>9, september=>9, ",
42             " oct=>10, october=>10, ",
43             " nov=>11, november=>11, ",
44             " dec=>12, december=>12, ",
45             "}; ",
46             "\$$pkg\::month_nums->{lc $dt} || $dt; ",
47             "}",
48             );
49              
50             $res;
51             }
52              
53 1         4 1;
54             # ABSTRACT: Convert English month name (e.g. Dec, april) to number (1-12)
55              
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Data::Sah::Coerce::perl::To_int::From_str::convert_en_month_name_to_num - Convert English month name (e.g. Dec, april) to number (1-12)
64              
65             =head1 VERSION
66              
67             This document describes version 0.018 of Data::Sah::Coerce::perl::To_int::From_str::convert_en_month_name_to_num (from Perl distribution Sah-Schemas-Date), released on 2022-10-12.
68              
69             =head1 SYNOPSIS
70              
71             To use in a Sah schema:
72              
73             ["int",{"x.perl.coerce_rules"=>["From_str::convert_en_month_name_to_num"]}]
74              
75             =head1 DESCRIPTION
76              
77             This rule can convert English month names like:
78              
79             Jan
80             april
81             JUN
82              
83             to corresponding month numbers (i.e. 1, 4, 6 in the examples above).
84             Unrecognized strings will just be passed as-is.
85              
86             =for Pod::Coverage ^(meta|coerce)$
87              
88             =head1 HOMEPAGE
89              
90             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Date>.
91              
92             =head1 SOURCE
93              
94             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Date>.
95              
96             =head1 AUTHOR
97              
98             perlancar <perlancar@cpan.org>
99              
100             =head1 CONTRIBUTING
101              
102              
103             To contribute, you can send patches by email/via RT, or send pull requests on
104             GitHub.
105              
106             Most of the time, you don't need to build the distribution yourself. You can
107             simply modify the code, then test via:
108              
109             % prove -l
110              
111             If you want to build the distribution (e.g. to try to install it locally on your
112             system), you can install L<Dist::Zilla>,
113             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
114             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
115             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
116             that are considered a bug and can be reported to me.
117              
118             =head1 COPYRIGHT AND LICENSE
119              
120             This software is copyright (c) 2022, 2020, 2019 by perlancar <perlancar@cpan.org>.
121              
122             This is free software; you can redistribute it and/or modify it under
123             the same terms as the Perl 5 programming language system itself.
124              
125             =head1 BUGS
126              
127             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Date>
128              
129             When submitting a bug or request, please include a test-file or a
130             patch to an existing test-file that illustrates the bug or desired
131             feature.
132              
133             =cut