| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Sah::Coerce::perl::To_int::From_str::convert_en_month_name_to_num; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# AUTHOR |
|
4
|
|
|
|
|
|
|
our $DATE = '2021-08-04'; # DATE |
|
5
|
|
|
|
|
|
|
our $DIST = 'Sah-Schemas-Date'; # DIST |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.017'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
2276
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
17
|
|
|
|
1
|
|
|
|
|
199
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { |
|
13
|
|
|
|
|
|
|
+{ |
|
14
|
1
|
|
|
1
|
0
|
17
|
v => 4, |
|
15
|
|
|
|
|
|
|
summary => 'Convert English month name (e.g. Dec, april) to number (1-12)', |
|
16
|
|
|
|
|
|
|
prio => 50, |
|
17
|
|
|
|
|
|
|
}; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub coerce { |
|
21
|
1
|
|
|
1
|
0
|
19
|
my %args = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
3
|
my $dt = $args{data_term}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
my $res = {}; |
|
26
|
1
|
|
|
|
|
2
|
my $pkg = __PACKAGE__; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
3
|
$res->{expr_match} = "!ref($dt)"; |
|
29
|
1
|
|
|
|
|
7
|
$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\::month_nums ||= {", |
|
36
|
|
|
|
|
|
|
" jan=>1, january=>1, ", |
|
37
|
|
|
|
|
|
|
" feb=>2, february=>2, ", |
|
38
|
|
|
|
|
|
|
" mar=>3, march=>3, ", |
|
39
|
|
|
|
|
|
|
" apr=>4, april=>4, ", |
|
40
|
|
|
|
|
|
|
" may=>5, ", |
|
41
|
|
|
|
|
|
|
" jun=>6, june=>6, ", |
|
42
|
|
|
|
|
|
|
" jul=>7, july=>7, ", |
|
43
|
|
|
|
|
|
|
" aug=>8, august=>8, ", |
|
44
|
|
|
|
|
|
|
" sep=>9, sept=>9, september=>9, ", |
|
45
|
|
|
|
|
|
|
" oct=>10, october=>10, ", |
|
46
|
|
|
|
|
|
|
" nov=>11, november=>11, ", |
|
47
|
|
|
|
|
|
|
" dec=>12, december=>12, ", |
|
48
|
|
|
|
|
|
|
"}; ", |
|
49
|
|
|
|
|
|
|
"\$$pkg\::month_nums->{lc $dt} || $dt; ", |
|
50
|
|
|
|
|
|
|
"}", |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
4
|
$res; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
|
57
|
|
|
|
|
|
|
# ABSTRACT: Convert English month name (e.g. Dec, april) to number (1-12) |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
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) |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This document describes version 0.017 of Data::Sah::Coerce::perl::To_int::From_str::convert_en_month_name_to_num (from Perl distribution Sah-Schemas-Date), released on 2021-08-04. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
To use in a Sah schema: |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
["int",{"x.perl.coerce_rules"=>["From_str::convert_en_month_name_to_num"]}] |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This rule can convert English month names like: |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Jan |
|
84
|
|
|
|
|
|
|
april |
|
85
|
|
|
|
|
|
|
JUN |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
to corresponding month numbers (i.e. 1, 4, 6 in the examples above). |
|
88
|
|
|
|
|
|
|
Unrecognized strings will just be passed as-is. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=for Pod::Coverage ^(meta|coerce)$ |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 HOMEPAGE |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Date>. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SOURCE |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Date>. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 BUGS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Date> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
105
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
106
|
|
|
|
|
|
|
feature. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2021, 2020, 2019 by perlancar@cpan.org. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
117
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |