File Coverage

blib/lib/Parse/Date/Month/ID.pm
Criterion Covered Total %
statement 16 16 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 23 24 95.8


line stmt bran cond sub pod time code
1             package Parse::Date::Month::ID;
2              
3 1     1   69128 use 5.010001;
  1         11  
4 1     1   6 use strict;
  1         1  
  1         21  
5 1     1   5 use warnings;
  1         2  
  1         47  
6              
7 1     1   7 use Exporter qw(import);
  1         2  
  1         385  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2023-06-16'; # DATE
11             our $DIST = 'Parse-Date-Month-ID'; # DIST
12             our $VERSION = '0.002'; # VERSION
13              
14             our @EXPORT_OK = qw(parse_date_month_id $Pat);
15              
16             our %month_values = (
17             jn => 1,
18             jan => 1,
19             januari => 1,
20             january => 1,
21              
22             fe => 2,
23             pe => 2,
24             feb => 2,
25             peb => 2,
26             februari => 2,
27             pebruari => 2,
28             february => 2,
29              
30             mr => 3,
31             mar => 3,
32             mrt => 3,
33             maret => 3,
34             march => 3,
35              
36             ap => 4,
37             apr => 4,
38             april => 4,
39              
40             my => 5,
41             me => 5,
42             mei => 5,
43             may => 5,
44              
45             jn => 6,
46             jun => 6,
47             juni => 6,
48             june => 6,
49              
50             jl => 7,
51             jul => 7,
52             juli => 7,
53             july => 7,
54              
55             au => 8,
56             ag => 8,
57             agu => 8,
58             aug => 8,
59             agt => 8,
60             agustus => 8,
61             august => 8,
62              
63             se => 9,
64             sep => 9,
65             sept => 9,
66             september => 9,
67              
68             oc => 10,
69             ok => 10,
70             okt => 10,
71             oct => 10,
72             oktober => 10,
73             october => 10,
74              
75             nv => 11,
76             np => 11,
77             nov => 11,
78             nop => 11,
79             november => 11,
80             nopember => 11,
81              
82             de => 12,
83             des => 12,
84             dec => 12,
85             desember => 12,
86             december => 12,
87             );
88              
89             our $Pat = join("|", sort keys %month_values); $Pat = qr/(?:$Pat)/;
90              
91             our %SPEC;
92              
93             $SPEC{parse_date_month_id} = {
94             v => 1.1,
95             summary => 'Parse month name from Indonesian text',
96             description => <<'_',
97              
98             Returns undef when month name is unrecognized.
99              
100             _
101             args => {
102             text => {
103             summary => 'The input text that contains month name',
104             schema => 'str*',
105             pos => 0,
106             req => 1,
107             },
108             },
109             result_naked => 1,
110             };
111             sub parse_date_month_id {
112 6     6 1 117 my %args = @_;
113 6         15 my $text = $args{text};
114              
115 6         23 $text =~ s/^\s+//s;
116 6 50       17 return undef unless length($text); ## no critic: Subroutines::ProhibitExplicitReturnUndef
117              
118 6         37 $month_values{lc $text};
119             }
120              
121             1;
122             # ABSTRACT: Parse month name from Indonesian text
123              
124             __END__