| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::Async::SmartyStreets::Address; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
90830
|
use strict; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
48
|
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
968
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
WebService::Async::SmartyStreets::Address - object that contains the response from SmartyStreets API |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Mocking a simple response from SmartyStreets API and parses it with WebService::Async::SmartyStreets::Address |
|
15
|
|
|
|
|
|
|
my $response = WebService::Async::SmartyStreets::Address->new( |
|
16
|
|
|
|
|
|
|
metadata => { |
|
17
|
|
|
|
|
|
|
latitude => 101.2131, |
|
18
|
|
|
|
|
|
|
longitude => 180.1223, |
|
19
|
|
|
|
|
|
|
geocode_precision => "Premise", |
|
20
|
|
|
|
|
|
|
}, |
|
21
|
|
|
|
|
|
|
analysis => { |
|
22
|
|
|
|
|
|
|
verification_status => "Partial", |
|
23
|
|
|
|
|
|
|
address_precision => "Premise", |
|
24
|
|
|
|
|
|
|
}); |
|
25
|
|
|
|
|
|
|
# Accessing the attributes |
|
26
|
|
|
|
|
|
|
print ($response->status); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Represents (parses) the return response from SmartyStreets API in an object |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 Construction |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
WebService::Async::SmartyStreets::Address->new( |
|
35
|
|
|
|
|
|
|
input_id => 12345, |
|
36
|
|
|
|
|
|
|
organization => 'Beenary', |
|
37
|
|
|
|
|
|
|
metadata => { |
|
38
|
|
|
|
|
|
|
latitude => 101.2131, |
|
39
|
|
|
|
|
|
|
longitude => 180.1223, |
|
40
|
|
|
|
|
|
|
geocode_precision => "Premise", |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
analysis => { |
|
43
|
|
|
|
|
|
|
verification_status => "Partial", |
|
44
|
|
|
|
|
|
|
address_precision => "Premise", |
|
45
|
|
|
|
|
|
|
}); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
|
50
|
8
|
|
|
8
|
0
|
8727
|
my ($class, %args) = @_; |
|
51
|
8
|
|
|
|
|
57
|
return bless \%args, $class; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 METHODS - Accessors |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 input_id |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
1
|
1
|
7
|
sub input_id { return shift->{input_id} } |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 organization |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
1
|
4
|
sub organization { return shift->{organization} } |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 latitude |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
1
|
4
|
sub latitude { return shift->{metadata}{latitude} } |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 longitude |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
|
|
1
|
1
|
5
|
sub longitude { return shift->{metadata}{longitude} } |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 geocode_precision |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
1
|
|
|
1
|
1
|
4
|
sub geocode_precision { return shift->{metadata}{geocode_precision} } |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 max_geocode_precision |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
0
|
sub max_geocode_precision { return shift->{metadata}{max_geocode_precision} } |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 address_format |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
1
|
|
|
1
|
1
|
4
|
sub address_format { return shift->{metadata}{address_format} } |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 status |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
17
|
|
100
|
17
|
1
|
83
|
sub status { return lc(shift->{analysis}{verification_status} || 'none') } |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 address_precision |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
18
|
|
100
|
18
|
1
|
84
|
sub address_precision { return lc(shift->{analysis}{address_precision} // '') } |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 max_address_precision |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
|
113
|
|
|
|
|
|
|
|
|
114
|
1
|
|
50
|
1
|
1
|
8
|
sub max_address_precision { return lc(shift->{analysis}{max_address_precision} // '') } |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Maps each verification response into a score |
|
117
|
|
|
|
|
|
|
my %status_level = ( |
|
118
|
|
|
|
|
|
|
none => 0, |
|
119
|
|
|
|
|
|
|
partial => 1, |
|
120
|
|
|
|
|
|
|
ambiguous => 2, |
|
121
|
|
|
|
|
|
|
verified => 3 |
|
122
|
|
|
|
|
|
|
); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 status_at_least |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Checks if the returned response at least hits a certain level (in terms of score) |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Example Usage: |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$obj->status_at_least("partial"); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Takes L which consists of verification status ("verified", "partial", "ambiguous", "none") |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns 1 or 0 |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub status_at_least { |
|
139
|
15
|
|
|
15
|
1
|
127
|
my ($self, $target) = @_; |
|
140
|
15
|
|
50
|
|
|
39
|
my $target_level = $status_level{$target} // die 'unknown target status ' . $target; |
|
141
|
15
|
|
50
|
|
|
24
|
my $actual_level = $status_level{$self->status} // die 'unknown status ' . $self->status; |
|
142
|
15
|
|
|
|
|
50
|
return $actual_level >= $target_level; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my %accuracy_level = ( |
|
146
|
|
|
|
|
|
|
none => 0, |
|
147
|
|
|
|
|
|
|
administrativearea => 1, |
|
148
|
|
|
|
|
|
|
locality => 2, |
|
149
|
|
|
|
|
|
|
thoroughfare => 3, |
|
150
|
|
|
|
|
|
|
premise => 4, |
|
151
|
|
|
|
|
|
|
deliverypoint => 5, |
|
152
|
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 accuracy_at_least |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Similar with status at least, checks if the returned response is at least hits a certain accuracy (in terms of score) |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Example Usage: |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$obj->accuracy_at_least("premise"); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Takes L which consists of address accuracy ("none", "administrative_area", "locality", "thoroughfare", "premise", "delivery_point") |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns 0 if the status is lower than 'partial' |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns 1 or 0 |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub accuracy_at_least { |
|
171
|
9
|
|
|
9
|
1
|
161
|
my ($self, $target) = @_; |
|
172
|
9
|
50
|
|
|
|
23
|
$target = 'thoroughfare' if $target eq 'street'; |
|
173
|
9
|
50
|
|
|
|
20
|
return 0 unless $self->status_at_least('partial'); |
|
174
|
9
|
100
|
|
|
|
21
|
return 0 unless $self->address_precision; |
|
175
|
8
|
|
100
|
|
|
43
|
my $target_level = $accuracy_level{$target} // die 'unknown target accuracy ' . $target; |
|
176
|
7
|
|
100
|
|
|
13
|
my $actual_level = $accuracy_level{$self->address_precision} // die 'unknown accuracy ' . $self->address_precision; |
|
177
|
6
|
|
|
|
|
32
|
return $actual_level >= $target_level; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
|
181
|
|
|
|
|
|
|
|