blib/lib/Readonly/Values/Months.pm

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