All/TomTom.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 58 CC 4 SCAR 16.4
CC
4
Cov
0%
geocode_local
12.0
_process_response
6.0
reverse_geocode_local
2.0
CRAP 5.2
1 package Geo::Coder::All::TomTom;
2 use Moose;
3 use namespace::autoclean;
4 use Geo::Coder::TomTom;
5 use Carp;
6 use Data::Dumper;
7 use Locale::Codes::Country;
8 with 'Geo::Coder::Role::Geocode';
9  
10 has 'TomTom' => (
11 is => 'ro',
12 isa => 'Geo::Coder::TomTom',
13 default => sub{ Geo::Coder::TomTom->new();}
14 );
15  
16 sub geocode_local {
17 my ($self,$rh_args) = @_;
18 croak "Location string required" unless ($rh_args->{location});
19 my $rh_response = $self->TomTom->geocode(location => $rh_args->{location} );
20 print STDERR Dumper($rh_response) if($rh_args->{DEBUG});
21 return $self->_process_response($rh_response);
22 }
23  
24 sub reverse_geocode_local{
25 my ($self,$rh_args) = @_;
26 return 'Reverse Geocode is not available for TomTom';
27 }
28  
29 sub _process_response {
30 my ($self,$rh_response) = @_;
31 return undef unless($rh_response);
32 my $rh_data;
33 $rh_data->{geocoder} = 'TomTom';
34 $rh_data->{address} = $rh_response->{formattedAddress};
35 $rh_data->{country} = $rh_response->{country};
36 #TODO: get country code using Locale::Codes module
37 $rh_data->{country_code} = uc(country2code($rh_response->{country},'alpha-2'));
38 $rh_data->{country_code_alpha_3} = uc(country2code($rh_response->{country},'alpha-3'));
39 $rh_data->{coordinates}{lat} = $rh_response->{latitude};
40 $rh_data->{coordinates}{lon} = $rh_response->{longitude};
41 return $rh_data;
42 }
43 __PACKAGE__->meta->make_immutable;
44 1;