All/Google.pm

filter: Statementstmt 53.7% 29 / 54 Branchbran 23.0% 6 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 46.7% 43 / 92 CC 15 SCAR 27.0
CC
15
Cov
44%
_process_response
42.0
reverse_geocode_local
12.0
_make_google_geocoder
8.6
CRAP 14.9
« All/Bing.pm ↑ Summary All/OSM.pm »
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
BranchTrueFalseTotal
unless $rh_args->{"location"} 0 1 1
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
BranchTrueFalseTotal
if $rh_args->{"DEBUG"} 0 0 0
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
BranchTrueFalseTotal
unless $rh_args->{"latlng"} 0 0 0
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
BranchTrueFalseTotal
if $rh_args->{"DEBUG"} 0 0 0
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
BranchTrueFalseTotal
$rh_args->{'key'} ? : 0 1 1
$rh_args->{'google_encoding'} ? : 1 0 1
$rh_args->{'google_country_code'} ? : 0 1 1
$rh_args->{'google_sensor'} ? : 0 1 1
$rh_args->{'google_client'} ? : 0 1 1
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
BranchTrueFalseTotal
unless $rh_response 0 0 0
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
BranchTrueFalseTotal
if ($component->{"types"}[0] =~ /country/) 0 0 0
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
BranchTrueFalseTotal
if $component->{"short_name"} 0 0 0
56 }
57 0 ▶ if($component->{types}[0] =~ /postal_code/){
Branch: 1 branch
BranchTrueFalseTotal
if ($component->{"types"}[0] =~ /postal_code/) 0 0 0
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;
« All/Bing.pm ↑ Summary All/OSM.pm »