File Coverage

blib/lib/Postal/US/State.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 24 26 92.3


line stmt bran cond sub pod time code
1             package Postal::US::State;
2             $VERSION = v0.0.1;
3              
4 2     2   24258 use warnings;
  2         5  
  2         61  
5 2     2   10 use strict;
  2         3  
  2         57  
6 2     2   18 use Carp;
  2         4  
  2         702  
7              
8             =head1 NAME
9              
10             Postal::US::State - State names and codes
11              
12             =head1 SYNOPSIS
13              
14             use Postal::US::State;
15              
16             my $code = Postal::US::State->code('Texas');
17             my $state = Postal::US::State->state('TX');
18              
19             =head1 About
20              
21             State names/codes data are built-in to this module (generated from
22             http://www.usps.com/ncsc/lookups/abbr_state.txt by the build process).
23              
24             =cut
25              
26              
27             my %code_state = (
28             ### STATES REGEN {{{
29             AL => 'Alabama',
30             AK => 'Alaska',
31             AS => 'American Samoa',
32             AZ => 'Arizona',
33             AR => 'Arkansas',
34             CA => 'California',
35             CO => 'Colorado',
36             CT => 'Connecticut',
37             DE => 'Delaware',
38             DC => 'District of Columbia',
39             FM => 'Federated States of Micronesia',
40             FL => 'Florida',
41             GA => 'Georgia',
42             GU => 'Guam',
43             HI => 'Hawaii',
44             ID => 'Idaho',
45             IL => 'Illinois',
46             IN => 'Indiana',
47             IA => 'Iowa',
48             KS => 'Kansas',
49             KY => 'Kentucky',
50             LA => 'Louisiana',
51             ME => 'Maine',
52             MH => 'Marshall Islands',
53             MD => 'Maryland',
54             MA => 'Massachusetts',
55             MI => 'Michigan',
56             MN => 'Minnesota',
57             MS => 'Mississippi',
58             MO => 'Missouri',
59             MT => 'Montana',
60             NE => 'Nebraska',
61             NV => 'Nevada',
62             NH => 'New Hampshire',
63             NJ => 'New Jersey',
64             NM => 'New Mexico',
65             NY => 'New York',
66             NC => 'North Carolina',
67             ND => 'North Dakota',
68             MP => 'Northern Mariana Islands',
69             OH => 'Ohio',
70             OK => 'Oklahoma',
71             OR => 'Oregon',
72             PW => 'Palau',
73             PA => 'Pennsylvania',
74             PR => 'Puerto Rico',
75             RI => 'Rhode Island',
76             SC => 'South Carolina',
77             SD => 'South Dakota',
78             TN => 'Tennessee',
79             TX => 'Texas',
80             UT => 'Utah',
81             VT => 'Vermont',
82             VI => 'Virgin Islands',
83             VA => 'Virginia',
84             WA => 'Washington',
85             WV => 'West Virginia',
86             WI => 'Wisconsin',
87             WY => 'Wyoming',
88             AE => 'Armed Forces Africa',
89             AA => 'Armed Forces Americas',
90             AE => 'Armed Forces Canada',
91             AE => 'Armed Forces Europe',
92             AE => 'Armed Forces Middle East',
93             AP => 'Armed Forces Pacific',
94             ### STATES REGEN }}}
95             );
96             my %state_code = map({lc($code_state{$_}) => $_} keys %code_state);
97              
98              
99             =head2 code
100              
101             Retrieve the two-letter code for the given state name (case
102             insensitive.) Returns undefined if the state is unknown.
103              
104             my $code = Postal::US::State->code('Texas');
105              
106             =cut
107              
108             sub code {
109 4     4 1 18 my $package = shift;
110 4 50       10 my $state = shift or croak("must have state argument");
111              
112 4         24 return $state_code{lc($state)};
113             } # code ###############################################################
114              
115             =head2 state
116              
117             Returns the state name for the given code.
118              
119             my $state = Postal::US::State->state('TX');
120              
121             =cut
122              
123             sub state {
124 2     2 1 4 my $package = shift;
125 2 50       7 my $abbr = shift or croak("must have state abbreviation");
126              
127 2         11 return $code_state{uc($abbr)};
128             } # state ##############################################################
129              
130              
131              
132             =head1 AUTHOR
133              
134             Eric Wilhelm @
135              
136             http://scratchcomputing.com/
137              
138             =head1 BUGS
139              
140             If you found this module on CPAN, please report any bugs or feature
141             requests through the web interface at L. I will be
142             notified, and then you'll automatically be notified of progress on your
143             bug as I make changes.
144              
145             If you pulled this development version from my /svn/, please contact me
146             directly.
147              
148             =head1 COPYRIGHT
149              
150             Copyright (C) 2010 Eric L. Wilhelm, All Rights Reserved.
151              
152             =head1 NO WARRANTY
153              
154             Absolutely, positively NO WARRANTY, neither express or implied, is
155             offered with this software. You use this software at your own risk. In
156             case of loss, no person or entity owes you anything whatsoever. You
157             have been warned.
158              
159             =head1 LICENSE
160              
161              
162              
163             =cut
164              
165             # vi:ts=2:sw=2:et:sta
166             1;