line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
806
|
use v5.10; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Business::US::USPS::WebTools::ZipCodeLookup; |
5
|
1
|
|
|
1
|
|
27
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
6
|
1
|
|
|
1
|
|
4
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
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
|
|
|
|
|
15
|
|
11
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
350
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.125'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Business::US::USPS::WebTools::ZipCodeLookup - lookup a Zip Code using the USPS Web Tools |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Business::US::USPS::WebTools::ZipCodeLookup; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $looker_upper = Business::US::USPS::WebTools::ZipCodeLookup->new( { |
26
|
|
|
|
|
|
|
UserID => $ENV{USPS_WEBTOOLS_USERID}, |
27
|
|
|
|
|
|
|
Password => $ENV{USPS_WEBTOOLS_PASSWORD}, |
28
|
|
|
|
|
|
|
Testing => 1, |
29
|
|
|
|
|
|
|
} ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $hash = $looker_upper->lookup_zipcode( |
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 Zip Code Lookup 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) } |
59
|
0
|
|
|
0
|
|
|
sub _required { qw( Address2 City State ) } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item lookup_zipcode( KEY, VALUE, ... ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The C method takes the following keys, which come |
64
|
|
|
|
|
|
|
directly from the USPS web service interface: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Address2 The street address |
67
|
|
|
|
|
|
|
City The name of the city |
68
|
|
|
|
|
|
|
State The two letter state abbreviation |
69
|
|
|
|
|
|
|
Zip5 The 5 digit zip code |
70
|
|
|
|
|
|
|
Zip4 The 4 digit extension to the zip code |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
It returns an anonymous hash with the same keys, but the values are |
73
|
|
|
|
|
|
|
the USPS's canonicalized address. If there is an error, the hash |
74
|
|
|
|
|
|
|
values will be the empty string, and the error flag is set. Check is |
75
|
|
|
|
|
|
|
with C: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$verifier->is_error; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
See the C documentation in Business::US::USPS::WebTools for more |
80
|
|
|
|
|
|
|
details on error information. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub lookup_zipcode { |
85
|
0
|
|
|
0
|
1
|
|
my( $self, %hash ) = @_; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->_make_url( \%hash ); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->_make_request; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->_parse_response; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
|
|
sub _api_name { "ZipCodeLookup" } |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _make_query_xml { |
98
|
0
|
|
|
0
|
|
|
my( $self, $hash ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $user = $self->userid; |
101
|
0
|
|
|
|
|
|
my $pass = $self->password; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $xml = |
104
|
|
|
|
|
|
|
qq|| . |
105
|
|
|
|
|
|
|
qq||; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
foreach my $field ( $self->_fields ) |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
|
|
|
$xml .= "<$field>$$hash{$field}$field>"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$xml .= qq||; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $xml; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _parse_response { |
118
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
119
|
|
|
|
|
|
|
#require 'Hash::AsObject'; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my %hash = (); |
122
|
0
|
|
|
|
|
|
foreach my $field ( $self->_fields, qw( Zip5 Zip4 ) ) { |
123
|
0
|
|
|
|
|
|
my( $value ) = $self->response =~ m|<$field>(.*?)$field>|g; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
0
|
|
|
|
$hash{$field} = $value || ''; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
bless \%hash, ref $self; # 'Hash::AsObject'; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 TO DO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SEE ALSO |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The WebTools API is documented on the US Postal Service's website: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
http://www.usps.com/webtools/htm/Address-Information.htm |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This source is in GitHub: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
https://github.com/ssimms/business-us-usps-webtools |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
brian d foy |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright © 2020, Steve Simms. All rights reserved. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
158
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |