| 1 | package Geo::Coder::All::Google; | ||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Locale::Codes::Country; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Geo::Coder::Google; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 8 | 1 | with 'Geo::Coder::Role::Geocode'; | |||||||||||||||||||||||||
| 9 | 1 | has 'GOOGLE' =>( | |||||||||||||||||||||||||
| 10 | is => 'rw', | ||||||||||||||||||||||||||
| 11 | isa => 'Object', | ||||||||||||||||||||||||||
| 12 | writer => 'set_google_geocoder' | ||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub geocode_local { | ||||||||||||||||||||||||
|
Subroutine
geocode_local: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||||||||||||||
| 15 | 1 | my ($self,$rh_args)= @_; | |||||||||||||||||||||||||
| 16 | 1 | ▶ | croak "Location string needed" unless ($rh_args->{location}); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 17 | 1 | my $rh_data; | |||||||||||||||||||||||||
| 18 | 1 | $self->_make_google_geocoder($rh_args); | |||||||||||||||||||||||||
| 19 | 1 | my $rh_response = $self->GOOGLE->geocode(location => $rh_args->{location}); | |||||||||||||||||||||||||
| 20 | 0 | ▶ | print STDERR Dumper($rh_response) if($rh_args->{DEBUG}); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 21 | 0 | return $self->_process_response($rh_response); | |||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub reverse_geocode_local{ | ||||||||||||||||||||||||
|
Subroutine
reverse_geocode_local: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||
| 24 | 0 | my ($self,$rh_args) = @_; | |||||||||||||||||||||||||
| 25 | 0 | ▶ | croak 'latlng needed to reverse geocode' unless($rh_args->{latlng}); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 26 | 0 | $self->_make_google_geocoder($rh_args); | |||||||||||||||||||||||||
| 27 | 0 | my $rh_response = $self->GOOGLE->reverse_geocode(latlng => $rh_args->{latlng}); | |||||||||||||||||||||||||
| 28 | 0 | ▶ | print STDERR Dumper($rh_response) if($rh_args->{DEBUG}); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 29 | 0 | return $self->_process_response($rh_response); | |||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub _make_google_geocoder { | ||||||||||||||||||||||||
|
Subroutine
_make_google_geocoder: called CC=6 SCAR=21.5
| |||||||||||||||||||||||||||
| 32 | 1 | my ($self,$rh_args)= @_; | |||||||||||||||||||||||||
| 33 | $self->set_google_geocoder(Geo::Coder::Google->new( | ||||||||||||||||||||||||||
| 34 | language => $rh_args->{language}, | ||||||||||||||||||||||||||
| 35 | apiver => 3, | ||||||||||||||||||||||||||
| 36 | ($rh_args->{key} ? ( key => $rh_args->{key}):()), | ||||||||||||||||||||||||||
| 37 | ($rh_args->{google_encoding} ? ( oe => $rh_args->{google_encoding}):()), | ||||||||||||||||||||||||||
| 38 | ($rh_args->{google_country_code} ? ( region => $rh_args->{google_country_code}):()), | ||||||||||||||||||||||||||
| 39 | ($rh_args->{google_sensor} ? ( sensor => $rh_args->{google_sensor}):()), | ||||||||||||||||||||||||||
| 40 | 1 | ▶ | ($rh_args->{google_client} ? ( client => $rh_args->{google_client}):()), | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 41 | )); | ||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||
| 43 | #TODO:implement this method as private_method/protected using MooseX::Privacy | ||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub _process_response { | ||||||||||||||||||||||||
|
Subroutine
_process_response: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||
| 45 | 0 | my ($self,$rh_response) = @_; | |||||||||||||||||||||||||
| 46 | 0 | ▶ | return undef unless($rh_response); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 47 | 0 | my $rh_data; | |||||||||||||||||||||||||
| 48 | 0 | $rh_data->{geocoder} = 'Google'; | |||||||||||||||||||||||||
| 49 | 0 | $rh_data->{address} = $rh_response->{formatted_address} ; | |||||||||||||||||||||||||
| 50 | 0 | @{$rh_data->{coordinates}}{qw/lat lon/} = @{$rh_response->{geometry}{location}}{qw/lat lng/} ; | |||||||||||||||||||||||||
| 51 | 0 | foreach my $component (@{$rh_response->{address_components}}){ | |||||||||||||||||||||||||
| 52 | 0 | ▶ | if($component->{types}->[0] =~ /country/){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 53 | 0 | $rh_data->{country_code} = $component->{short_name}; | |||||||||||||||||||||||||
| 54 | 0 | $rh_data->{country} = $component->{long_name}; | |||||||||||||||||||||||||
| 55 | 0 | ▶ | $rh_data->{country_code_alpha_3} = uc(country2code(code2country($rh_data->{country_code}),'alpha-3')) if($component->{short_name}); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($component->{types}[0] =~ /postal_code/){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 58 | 0 | $rh_data->{postal_code} = $component->{long_name}; | |||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||
| 61 | 0 | return $rh_data; | |||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||||||||||