line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
778
|
use v5.10; |
|
1
|
|
|
|
|
4
|
|
2
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Business::US::USPS::WebTools::CityStateLookup; |
5
|
1
|
|
|
1
|
|
26
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
5
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use parent qw(Business::US::USPS::WebTools); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
56
|
use subs qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
337
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.125'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Business::US::USPS::WebTools::CityStateLookup - lookup a City and State by Zip Code |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Business::US::USPS::WebTools::AddressStandardization; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $looker_upper = Business::US::USPS::WebTools::CityStateLookup->new( { |
26
|
|
|
|
|
|
|
UserID => $ENV{USPS_WEBTOOLS_USERID}, |
27
|
|
|
|
|
|
|
Password => $ENV{USPS_WEBTOOLS_PASSWORD}, |
28
|
|
|
|
|
|
|
Testing => 1, |
29
|
|
|
|
|
|
|
} ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $hash = $looker_upper->lookup_city_state( |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if( $looker_upper->is_error ) |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
warn "Oh No! $looker_upper->{error}{description}\n"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
print join "\n", map { "$_: $hash->{$_}" } |
41
|
|
|
|
|
|
|
qw(FirmName Address1 Address2 City State Zip5 Zip4); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
*** THIS IS ALPHA SOFTWARE *** |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This module implements the Address Standardization web service from the |
50
|
|
|
|
|
|
|
US Postal Service. It is a subclass of Business::US::USPS::WebTools. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
|
|
sub _fields { qw( FirmName Address1 Address2 City State Zip5 Zip4 ) } |
59
|
0
|
|
|
0
|
|
|
sub _required { qw( Address2 City State ) } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item lookup_city_state( KEY, VALUE, ... ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The C method takes the following keys, which come |
64
|
|
|
|
|
|
|
directly from the USPS web service interface: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
FirmName The name of the company |
67
|
|
|
|
|
|
|
Address1 The suite or apartment |
68
|
|
|
|
|
|
|
Address2 The street address |
69
|
|
|
|
|
|
|
City The name of the city |
70
|
|
|
|
|
|
|
State The two letter state abbreviation |
71
|
|
|
|
|
|
|
Zip5 The 5 digit zip code |
72
|
|
|
|
|
|
|
Zip4 The 4 digit extension to the zip code |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
It returns an anonymous hash with the same keys, but the values are |
75
|
|
|
|
|
|
|
the USPS's canonicalized address. If there is an error, the hash values |
76
|
|
|
|
|
|
|
will be the empty string, and the error flag is set. Check is with C: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$verifier->is_error; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
See the C documentation in Business::US::USPS::WebTools for more |
81
|
|
|
|
|
|
|
details on error information. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub lookup_city_state { |
86
|
0
|
|
|
0
|
1
|
|
my( $self, $zip_code ) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->_make_url( { Zip5 => $zip_code } ); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->_make_request; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->_parse_response; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
|
|
sub _api_name { "CityStateLookup" } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _make_query_xml { |
99
|
0
|
|
|
0
|
|
|
my( $self, $hash ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $user = $self->userid; |
102
|
0
|
|
|
|
|
|
my $pass = $self->password; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $xml = |
105
|
|
|
|
|
|
|
qq|| . |
106
|
|
|
|
|
|
|
qq|$$hash{Zip5}| . |
107
|
|
|
|
|
|
|
qq||; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _parse_response { |
112
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
113
|
|
|
|
|
|
|
#require 'Hash::AsObject'; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my %hash = (); |
116
|
0
|
|
|
|
|
|
foreach my $field ( $self->_fields ) { |
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
|
|
|
|
|
|
|
https://www.usps.com/business/web-tools-apis/address-information-api.pdf |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This source is in GitHub: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
https://github.com/ssimms/business-us-usps-webtools |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
brian d foy |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 MAINTAINER |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Steve Simms |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Copyright © 2020, Steve Simms. All rights reserved. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
156
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |