| 1 | package WebService::Async::SmartyStreets::Address; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | 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 | 8 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 50 | 8 | my ($class, %args) = @_; | |||||||||||
| 51 | 8 | return bless \%args, $class; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | =head2 METHODS - Accessors | ||||||||||||
| 55 | |||||||||||||
| 56 | =head2 input_id | ||||||||||||
| 57 | |||||||||||||
| 58 | =cut | ||||||||||||
| 59 | |||||||||||||
| 60 | 1 | ▶ | sub input_id { return shift->{input_id} } | ||||||||||
|
Subroutine
input_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 61 | |||||||||||||
| 62 | =head2 organization | ||||||||||||
| 63 | |||||||||||||
| 64 | =cut | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | ▶ | sub organization { return shift->{organization} } | ||||||||||
|
Subroutine
organization: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 67 | |||||||||||||
| 68 | =head2 latitude | ||||||||||||
| 69 | |||||||||||||
| 70 | =cut | ||||||||||||
| 71 | |||||||||||||
| 72 | 1 | ▶ | sub latitude { return shift->{metadata}{latitude} } | ||||||||||
|
Subroutine
latitude: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 73 | |||||||||||||
| 74 | =head2 longitude | ||||||||||||
| 75 | |||||||||||||
| 76 | =cut | ||||||||||||
| 77 | |||||||||||||
| 78 | 1 | ▶ | sub longitude { return shift->{metadata}{longitude} } | ||||||||||
|
Subroutine
longitude: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 79 | |||||||||||||
| 80 | =head2 geocode_precision | ||||||||||||
| 81 | |||||||||||||
| 82 | =cut | ||||||||||||
| 83 | |||||||||||||
| 84 | 1 | ▶ | sub geocode_precision { return shift->{metadata}{geocode_precision} } | ||||||||||
|
Subroutine
geocode_precision: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 85 | |||||||||||||
| 86 | =head2 max_geocode_precision | ||||||||||||
| 87 | |||||||||||||
| 88 | =cut | ||||||||||||
| 89 | |||||||||||||
| 90 | 0 | ▶ | sub max_geocode_precision { return shift->{metadata}{max_geocode_precision} } | ||||||||||
|
Subroutine
max_geocode_precision: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 91 | |||||||||||||
| 92 | =head2 address_format | ||||||||||||
| 93 | |||||||||||||
| 94 | =cut | ||||||||||||
| 95 | |||||||||||||
| 96 | 1 | ▶ | sub address_format { return shift->{metadata}{address_format} } | ||||||||||
|
Subroutine
address_format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 97 | |||||||||||||
| 98 | =head2 status | ||||||||||||
| 99 | |||||||||||||
| 100 | =cut | ||||||||||||
| 101 | |||||||||||||
| 102 | 17 | ▶ | sub status { return lc(shift->{analysis}{verification_status} || 'none') } | ||||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
+(shift())->{'analysis'}{'verification_status'} || 'none'
MC/DC100%1/1
+(shift())->{'analysis'}{'verification_status'} || 'none'
+(shift())->{'analysis'}{'verification_status'}
Truth table100%2/2
A
A= +(shift())->{'analysis'}{'verification_status'}
| |||||||||||||
| 103 | |||||||||||||
| 104 | =head2 address_precision | ||||||||||||
| 105 | |||||||||||||
| 106 | =cut | ||||||||||||
| 107 | |||||||||||||
| 108 | 18 | ▶ | sub address_precision { return lc(shift->{analysis}{address_precision} // '') } | ||||||||||
|
Subroutine
address_precision: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
+(shift())->{"analysis"}{"address_precision"} // ""
MC/DC100%1/1
+(shift())->{"analysis"}{"address_precision"} // ""
+(shift())->{"analysis"}{"address_precision"}
Truth table100%2/2
A
A= +(shift())->{"analysis"}{"address_precision"}
| |||||||||||||
| 109 | |||||||||||||
| 110 | =head2 max_address_precision | ||||||||||||
| 111 | |||||||||||||
| 112 | =cut | ||||||||||||
| 113 | |||||||||||||
| 114 | 1 | ▶ | sub max_address_precision { return lc(shift->{analysis}{max_address_precision} // '') } | ||||||||||
|
Subroutine
max_address_precision: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
+(shift())->{"analysis"}{"max_address_precision"} // ""
MC/DC0%0/1
+(shift())->{"analysis"}{"max_address_precision"} // ""
+(shift())->{"analysis"}{"max_address_precision"}
Truth table50%1/2
A
A= +(shift())->{"analysis"}{"max_address_precision"}
| |||||||||||||
| 115 | |||||||||||||
| 116 | # Maps each verification response into a score | ||||||||||||
| 117 | 4 | 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<String> which consists of verification status ("verified", "partial", "ambiguous", "none") | ||||||||||||
| 133 | |||||||||||||
| 134 | Returns 1 or 0 | ||||||||||||
| 135 | |||||||||||||
| 136 | =cut | ||||||||||||
| 137 | |||||||||||||
| 138 | 15 | ▶ | sub status_at_least { | ||||||||||
|
Subroutine
status_at_least: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 139 | 15 | my ($self, $target) = @_; | |||||||||||
| 140 | 15 | ▶ | my $target_level = $status_level{$target} // die 'unknown target status ' . $target; | ||||||||||
|
Condition50%1/2
$status_level{$target} // die('unknown target status ' . $target)
MC/DC0%0/1
$status_level{$target} // die('unknown target status ' . $target)
$status_level{$target}
Truth table50%1/2
A
A= $status_level{$target}
| |||||||||||||
| 141 | 15 | ▶ | my $actual_level = $status_level{$self->status} // die 'unknown status ' . $self->status; | ||||||||||
|
Condition50%1/2
$status_level{$self->status} // die('unknown status ' . $self->status)
MC/DC0%0/1
$status_level{$self->status} // die('unknown status ' . $self->status)
$status_level{$self->status}
Truth table50%1/2
A
A= $status_level{$self->status}
| |||||||||||||
| 142 | 15 | return $actual_level >= $target_level; | |||||||||||
| 143 | } | ||||||||||||
| 144 | |||||||||||||
| 145 | 4 | 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<String> 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 | 9 | ▶ | sub accuracy_at_least { | ||||||||||
|
Subroutine
accuracy_at_least: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||
| 171 | 9 | my ($self, $target) = @_; | |||||||||||
| 172 | 9 | ▶ | $target = 'thoroughfare' if $target eq 'street'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 173 | 9 | ▶ | return 0 unless $self->status_at_least('partial'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 174 | 9 | ▶ | return 0 unless $self->address_precision; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 175 | 8 | ▶ | my $target_level = $accuracy_level{$target} // die 'unknown target accuracy ' . $target; | ||||||||||
|
Condition100%2/2
$accuracy_level{$target} // die('unknown target accuracy ' . $target)
MC/DC100%1/1
$accuracy_level{$target} // die('unknown target accuracy ' . $target)
$accuracy_level{$target}
Truth table100%2/2
A
A= $accuracy_level{$target}
| |||||||||||||
| 176 | 7 | ▶ | my $actual_level = $accuracy_level{$self->address_precision} // die 'unknown accuracy ' . $self->address_precision; | ||||||||||
|
Condition100%2/2
$accuracy_level{$self->address_precision} // die('unknown accuracy ' . $self->address_precision)
MC/DC100%1/1
$accuracy_level{$self->address_precision} // die('unknown accuracy ' . $self->address_precision)
$accuracy_level{$self->address_precision}
Truth table100%2/2
A
A= $accuracy_level{$self->address_precision}
| |||||||||||||
| 177 | 6 | return $actual_level >= $target_level; | |||||||||||
| 178 | } | ||||||||||||
| 179 | |||||||||||||
| 180 | 4 | 1; | |||||||||||
| 181 | |||||||||||||