line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: CityStateLookup.pm 2360 2007-11-03 04:48:52Z comdog $ |
2
|
|
|
|
|
|
|
package Business::US::USPS::WebTools::CityStateLookup; |
3
|
1
|
|
|
1
|
|
1819
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
83
|
|
4
|
1
|
|
|
1
|
|
6
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw(Business::US::USPS::WebTools); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
132
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use subs qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
533
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.11'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Business::US::USPS::WebTools::CityStateLookup - lookup a City and State by Zip Code |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Business::US::USPS::WebTools::AddressStandardization; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $looker_upper = Business::US::USPS::WebTools::CityStateLookup->new( { |
22
|
|
|
|
|
|
|
UserID => $ENV{USPS_WEBTOOLS_USERID}, |
23
|
|
|
|
|
|
|
Password => $ENV{USPS_WEBTOOLS_PASSWORD}, |
24
|
|
|
|
|
|
|
Testing => 1, |
25
|
|
|
|
|
|
|
} ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $hash = $looker_upper->lookup_city_state( |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if( $looker_upper->is_error ) |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
warn "Oh No! $looker_upper->{error}{description}\n"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
print join "\n", map { "$_: $hash->{$_}" } |
37
|
|
|
|
|
|
|
qw(FirmName Address1 Address2 City State Zip5 Zip4); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
*** THIS IS ALPHA SOFTWARE *** |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This module implements the Address Standardization web service from the |
46
|
|
|
|
|
|
|
US Postal Service. It is a subclass of Business::US::USPS::WebTools. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
|
|
sub _fields { qw( FirmName Address1 Address2 City State Zip5 Zip4 ) } |
55
|
0
|
|
|
0
|
|
|
sub _required { qw( Address2 City State ) } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item lookup_city_state( KEY, VALUE, ... ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The C method takes the following keys, which come |
60
|
|
|
|
|
|
|
directly from the USPS web service interface: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
FirmName The name of the company |
63
|
|
|
|
|
|
|
Address1 The suite or apartment |
64
|
|
|
|
|
|
|
Address2 The street address |
65
|
|
|
|
|
|
|
City The name of the city |
66
|
|
|
|
|
|
|
State The two letter state abbreviation |
67
|
|
|
|
|
|
|
Zip5 The 5 digit zip code |
68
|
|
|
|
|
|
|
Zip4 The 4 digit extension to the zip code |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
It returns an anonymous hash with the same keys, but the values are |
71
|
|
|
|
|
|
|
the USPS's canonicalized address. If there is an error, the hash values |
72
|
|
|
|
|
|
|
will be the empty string, and the error flag is set. Check is with C: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$verifier->is_error; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
See the C documentation in Business::US::USPS::WebTools for more |
77
|
|
|
|
|
|
|
details on error information. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lookup_city_state |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
0
|
1
|
|
my( $self, $zip_code ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->_make_url( { Zip5 => $zip_code } ); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->_make_request; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->_parse_response; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
|
|
sub _api_name { "CityStateLookup" } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _make_query_xml |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
|
|
my( $self, $hash ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $user = $self->userid; |
100
|
0
|
|
|
|
|
|
my $pass = $self->password; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $xml = |
103
|
|
|
|
|
|
|
qq|| . |
104
|
|
|
|
|
|
|
qq|$$hash{Zip5}| . |
105
|
|
|
|
|
|
|
qq||; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _parse_response |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
112
|
|
|
|
|
|
|
#require 'Hash::AsObject'; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my %hash = (); |
115
|
0
|
|
|
|
|
|
foreach my $field ( $self->_fields ) |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
|
|
|
my( $value ) = $self->response =~ m|<$field>(.*?)$field>|g; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
0
|
|
|
|
$hash{$field} = $value || ''; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
bless \%hash, ref $self; # 'Hash::AsObject'; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 TO DO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SEE ALSO |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The WebTools API is documented on the US Postal Service's website: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
http://www.usps.com/webtools/htm/Address-Information.htm |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This source is part of a SourceForge project which always has the |
140
|
|
|
|
|
|
|
latest sources in CVS, as well as all of the previous releases. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
http://sourceforge.net/projects/brian-d-foy/ |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
If, for some reason, I disappear from the world, one of the other |
145
|
|
|
|
|
|
|
members of the project can shepherd this module appropriately. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
brian d foy, C<< >> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Copyright (c) 2006-2007, brian d foy, All Rights Reserved. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |