| 1 | package Geo::Coder::GoogleMaps::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | G_GEO_SUCCESS => 200, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | G_GEO_BAD_REQUEST => 400, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | G_GEO_SERVER_ERROR => 500, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | G_GEO_MISSING_QUERY => 601, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | G_GEO_MISSING_ADDRESS => 601, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | G_GEO_UNKNOWN_ADDRESS => 602, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | G_GEO_UNAVAILABLE_ADDRESS => 603, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | G_GEO_UNKNOWN_DIRECTIONS => 604, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | G_GEO_BAD_KEY => 610, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | G_GEO_TOO_MANY_QUERIES => 620, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | Geo::Coder::GoogleMaps::Response - Response object for the L<Geo::Coder::GoogleMaps> module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | Version 0.4 (follow L<Geo::Coder::GoogleMaps> version number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | our $VERSION = '0.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | This module provides a convenient way to represent a response for a geocoding request to Google's servers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =head1 CONSTANTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Those constants are giving hints about the status of a geocoding request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | G_GEO_SUCCESS: No errors occurred; the address was successfully parsed and its geocode has been returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | G_GEO_BAD_REQUEST: A directions request could not be successfully parsed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | G_GEO_SERVER_ERROR: A geocoding, directions or maximum zoom level request could not be successfully processed, yet the exact reason for the failure is not known. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | G_GEO_MISSING_QUERY: The "location" parameter was either missing or had no value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | G_GEO_MISSING_ADDRESS: Synonym for G_GEO_MISSING_QUERY. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | G_GEO_UNKNOWN_ADDRESS: No corresponding geographic location could be found for the specified address. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | G_GEO_UNAVAILABLE_ADDRESS: The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | G_GEO_BAD_KEY: The given key is either invalid or does not match the domain for which it was given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | G_GEO_TOO_MANY_QUERIES: The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | The object constructor it takes no parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my($class, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if( (exists($param{status_code}) && defined($param{status_code}) ) && (exists($param{status_request}) && defined($param{status_request}) ) ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
exists $param{"status_code"} and defined $param{"status_code"} and (exists $param{"status_request"} and defined $param{"status_request"})
exists $param{"status_code"} and defined $param{"status_code"}
exists $param{"status_request"} and defined $param{"status_request"}
MC/DC0%0/4
exists $param{"status_code"} and defined $param{"status_code"} and (exists $param{"status_request"} and defined $param{"status_request"})
exists $param{"status_code"}
defined $param{"status_code"}
exists $param{"status_request"}
defined $param{"status_request"}
Truth table0%0/5
A and B and C and D
A= exists $param{"status_code"}B= defined $param{"status_code"}C= exists $param{"status_request"}D= defined $param{"status_request"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | bless { status => {code=>$param{status_code},request=>$param{status_request}}, placemarks => [] }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | bless { status => {code=>-1,request=>""}, placemarks => [] }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =head2 is_success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Return true if the the request was successfull and there is actually some placemarks in the list, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | If the exact failure reason is needed, please use Geo::Coder::GoogleMaps::Response::status_code() and check with the available constants. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | unless( $response->is_success() ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | print "WARNING: Address is unknown by Google's server !\n" if( $response->status_code() == G_GEO_UNKNOWN_ADDRESS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub is_success { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_success: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return ($self->{status}->{code} == G_GEO_SUCCESS && scalar(@{$self->{placemarks}}) >= 1) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'status'}{'code'} == 200 && scalar @{$self->{'placemarks'};} >= 1
MC/DC0%0/2
$self->{'status'}{'code'} == 200 && scalar @{$self->{'placemarks'};} >= 1
$self->{'status'}{'code'} == 200
scalar @{$self->{'placemarks'};} >= 1
Truth table0%0/3
A && B
A= $self->{'status'}{'code'} == 200B= scalar @{$self->{'placemarks'};} >= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head2 status_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Returns the response status code. This code can be tested against the G_GEO_* constants. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | if( $response->status_code() == Geo::Coder::GoogleMaps::Response::G_GEO_BAD_KEY ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | print "Please provide a valid Google Maps API key and try again.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub status_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_code: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $self->{status}->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =head2 status | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Returns the complete response status. The status is a hashref which looks like that : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | status => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | code => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | request => "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $self->{status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | =head2 add_placemark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | Adds the placemark (a L<Geo::Coder::GoogleMaps::Location> object) given in parameter to the list of placemarks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | This methods croak on errors (like if you did not give a proper object in argument). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub add_placemark { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_placemark: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $location = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if( defined($location) && UNIVERSAL::isa( $location, "Geo::Coder::GoogleMaps::Location") ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $location and UNIVERSAL::isa($location, "Geo::Coder::GoogleMaps::Location")
MC/DC0%0/2
defined $location and UNIVERSAL::isa($location, "Geo::Coder::GoogleMaps::Location")
defined $location
UNIVERSAL::isa($location, "Geo::Coder::GoogleMaps::Location")
Truth table0%0/3
A and B
A= defined $locationB= UNIVERSAL::isa($location, "Geo::Coder::GoogleMaps::Location")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | push @{$self->{placemarks}},$location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | Carp::croak("add_placemark() : takes a Geo::Coder::GoogleMaps::Location as mandatory argument.\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =head2 placemarks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | Return the complete list of placemarks, or an arrayref depending on the context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | In any case the array contains a list of L<Geo::Coder::GoogleMaps::Location> objects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub placemarks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
placemarks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | wantarray ? @{$self->{placemarks}} : [@{$self->{placemarks}}]; # I voluntarly create a new reference to prevent (at last a little...) the deletion of placemarks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =head2 clean_placemarks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | Remove all the placemarks from the response object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub clean_placemarks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_placemarks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->{placemarks} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =head2 clean_status | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | Reset the response object's status to its initial state (undefined). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub clean_status { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->{status} = {code=>-1,request=>""}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||