File Coverage

blib/lib/Locale/US/CensusDivisions.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 28 30 93.3


line stmt bran cond sub pod time code
1             package Locale::US::CensusDivisions;
2              
3 1     1   84690 use strict;
  1         1  
  1         21  
4 1     1   3 use warnings;
  1         1  
  1         16  
5              
6 1     1   3 use Exporter;
  1         1  
  1         26  
7 1     1   2 use Carp qw(croak);
  1         1  
  1         234  
8              
9             our @ISA = qw(Exporter);
10             our @EXPORT_OK = qw( state2division );
11              
12             # ABSTRACT: Locale::US::CensusDivisions - module to get US Census Divisions
13             our $VERSION = '1.0.0'; # VERSION 1.0.0
14              
15             =pod
16              
17             =encoding utf8
18              
19             =head1 NAME
20              
21             Locale::US::CensusDivisions - Module to provide Census Bureau Divisions
22              
23             =head1 SYNOPSIS
24              
25             use strict;
26             use warnings;
27              
28             use Locale::US::CensusDivisions qw(state2division);
29              
30             my $division = state2division('TX');
31              
32             print "The division for that state is $division \n";
33              
34             =head1 DESCRIPTION
35              
36             This module takes a US state abbreviation and returns the division number associated with that state.
37              
38             =head1 METHODS
39              
40             =head2 state2division
41              
42             See Synopsis
43              
44             =head1 BUGS AND LIMITATIONS
45              
46             This module currently only supports US states and District of Columbia.
47             It does not support US territories.
48              
49             =head1 AUTHOR
50              
51             Daniel Culver, C<< perlsufi@cpan.org >>
52              
53             =head1 ACKNOWLEDGEMENTS
54              
55             Wikipedia L
56              
57             HostGator
58              
59             =head1 CONTRIBUTORS
60              
61             William Seymour
62              
63             Doug Schrag
64              
65             =head1 LICENSE AND COPYRIGHT
66              
67             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
68              
69             =cut
70              
71             our %divisions = (
72             1 => [ 'CT', 'ME', 'MA', 'NH', 'RI', 'VT' ],
73             2 => [ 'NJ', 'NY', 'PA' ],
74             3 => [ 'IL', 'IN', 'WI', 'MI', 'OH' ],
75             4 => [ 'MN', 'KS', 'IA', 'MO', 'NE', 'ND', 'SD' ],
76             5 => [ 'DE', 'FL', 'GA', 'MD', 'NC', 'SC', 'VA', 'DC', 'WV' ],
77             6 => [ 'AL', 'KY', 'MS', 'TN' ],
78             7 => [ 'AR', 'LA', 'OK', 'TX' ],
79             8 => [ 'AZ', 'CO', 'ID', 'MT', 'NV', 'NM', 'UT', 'WY', ],
80             9 => [ 'CA', 'WA', 'HI', 'OR', 'AK' ],
81             );
82              
83             sub state2division {
84 53   33 53 1 4320 my $code = shift
85             || croak 'state2division requires a state abbreviation string';
86              
87 53         86 while ( my ( $key, $value ) = each %divisions ) {
88 295 100       208 if ( ( grep { $code eq $_ } @$value ) ) {
  1519         1660  
89 52         34 keys %divisions; # reset the iterator
90 52         87 return $key;
91             }
92             }
93              
94 1         18 croak "The state abbreviation ($code) you provided was not found";
95             }
96              
97             1;