| 1 | package Postal::US::State; | ||||||||||
| 2 | 2 | $VERSION = v0.0.1; | |||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 2 | 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 | 2 | 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 | 4 | ▶ | sub code { | ||||||||
|
Subroutine
code: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 109 | 4 | my $package = shift; | |||||||||
| 110 | 4 | ▶ | my $state = shift or croak("must have state argument"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 4 | 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 | 2 | ▶ | sub state { | ||||||||
|
Subroutine
state: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 124 | 2 | my $package = shift; | |||||||||
| 125 | 2 | ▶ | my $abbr = shift or croak("must have state abbreviation"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | |||||||||||
| 127 | 2 | return $code_state{uc($abbr)}; | |||||||||
| 128 | } # state ############################################################## | ||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | =head1 AUTHOR | ||||||||||
| 133 | |||||||||||
| 134 | Eric Wilhelm @ <ewilhelm at cpan dot org> | ||||||||||
| 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<http://rt.cpan.org>. 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 | 2 | 1; | |||||||||