File Coverage

blib/lib/Readonly/Values/Months.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             package Readonly::Values::Months;
2              
3 2     2   327977 use strict;
  2         6  
  2         77  
4 2     2   10 use warnings;
  2         4  
  2         102  
5              
6 2     2   1101 use Readonly::Enum;
  2         9830  
  2         79  
7 2     2   1561 use Readonly;
  2         10876  
  2         142  
8 2     2   15 use Exporter qw(import);
  2         3  
  2         883  
9              
10             =head1 NAME
11              
12             Readonly::Values::Months - Months Constants
13              
14             =head1 VERSION
15              
16             Version 0.03
17              
18             =cut
19              
20             our $VERSION = '0.03';
21              
22             =head1 SYNOPSIS
23              
24             use Readonly::Values::Months;
25              
26             # Simple month constants
27             print "January is month number $JAN\n"; # January is month number 1
28             print "December is month number $DEC\n"; # December is month number 12
29              
30             # Lookup a month number by name (case-insensitive keys)
31             my $num = $months{'april'}; # 4
32             print "April => $num\n";
33              
34             # Iterate full month names
35             for my $name (@month_names) {
36             printf "%-9s => %2d\n", ucfirst($name), $months{$name};
37             }
38              
39             # Short names (first three letters)
40             print 'Abbreviations: ', join(', ', @short_month_names), "\n";
41             # Abbreviations: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
42              
43             # Exported symbols:
44             # $JAN ... $DEC
45             # %months
46             # @month_names
47             # @short_month_names
48              
49             print "December is often shortened to $month_names_to_short{december}\n"; # "dec"
50              
51             =cut
52              
53             Readonly::Enum our ($JAN, $FEB, $MAR, $APR, $MAY, $JUN, $JUL, $AUG, $SEP, $OCT, $NOV, $DEC) => 1;
54              
55             Readonly::Hash our %months => (
56             'jan' => $JAN,
57             'january' => $JAN,
58             'feb' => $FEB,
59             'february' => $FEB,
60             'mar' => $MAR,
61             'march' => $MAR,
62             'apr' => $APR,
63             'april' => $APR,
64             'may' => $MAY,
65             'jun' => $JUN,
66             'june' => $JUN,
67             'jul' => $JUL,
68             'july' => $JUL,
69             'aug' => $AUG,
70             'august' => $AUG,
71             'sep' => $SEP,
72             'september' => $SEP,
73             'oct' => $OCT,
74             'october' => $OCT,
75             'nov' => $NOV,
76             'november' => $NOV,
77             'dec' => $DEC,
78             'december' => $DEC
79             );
80              
81             Readonly::Array our @month_names => (
82             'january',
83             'february',
84             'march',
85             'april',
86             'may',
87             'june',
88             'july',
89             'august',
90             'september',
91             'october',
92             'november',
93             'december'
94             );
95              
96             Readonly::Array our @short_month_names => map { _shorten($_) } @month_names;
97              
98             Readonly::Hash our %month_names_to_short => map { $_ => _shorten($_) } @month_names;
99              
100             our @EXPORT = qw(
101             $JAN $FEB $MAR $APR $MAY $JUN $JUL $AUG $SEP $OCT $NOV $DEC
102             %months
103             @month_names
104             @short_month_names
105             %month_names_to_short
106             );
107              
108             # Helper routine: Shorten strings to their first three characters
109             sub _shorten {
110 48     48   99 return substr(shift, 0, 3);
111             };
112              
113             =head1 AUTHOR
114              
115             Nigel Horne, C<< >>
116              
117             =head1 BUGS
118              
119             =head1 SEE ALSO
120              
121             =head1 SUPPORT
122              
123             This module is provided as-is without any warranty.
124              
125             Please report any bugs or feature requests to C,
126             or through the web interface at
127             L.
128             I will be notified, and then you'll
129             automatically be notified of progress on your bug as I make changes.
130              
131             You can find documentation for this module with the perldoc command.
132              
133             perldoc Readonly::Values::Months
134              
135             You can also look for information at:
136              
137             =over 4
138              
139             =item * MetaCPAN
140              
141             L
142              
143             =item * RT: CPAN's request tracker
144              
145             L
146              
147             =item * CPAN Testers' Matrix
148              
149             L
150              
151             =item * CPAN Testers Dependencies
152              
153             L
154              
155             =back
156              
157             =head1 LICENSE AND COPYRIGHT
158              
159             Copyright 2025 Nigel Horne.
160              
161             Usage is subject to licence terms.
162              
163             The licence terms of this software are as follows:
164              
165             =over 4
166              
167             =item * Personal single user, single computer use: GPL2
168              
169             =item * All other users (including Commercial, Charity, Educational, Government)
170             must apply in writing for a licence for use from Nigel Horne at the
171             above e-mail.
172              
173             =back
174              
175             =cut
176              
177             1;