All.pm

filter: Statementstmt 90.9% 40 / 44 Branchbran 50.0% 6 / 12 Conditioncond 28.5% 6 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 59.1% 58 / 98 CC 14 SCAR 27.5
CC
14
Cov
68%
_process_args
26.1
_build_geocoder_engine
5.0
__ANON__
2.0
CRAP 15.7
↑ Summary All/Bing.pm »
1 package Geo::Coder::All;
2 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Module::Runtime qw(require_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 my %VALID_GEOCODER_LIST = map { $_ => 1} qw(
7 Google
8 OSM
9 TomTom
10 Ovi
11 Bing
12 );
13 5 has 'geocoder' => (is=>'rw',isa=>'Str',default=>'Google');
14 5 has 'key' => (is=>'rw',isa=>'Str',default=>'', reader=>'get_key');
15 5 has 'langauge' => (is=>'rw',isa=>'Str',default=>'en', reader=>'get_language', init_arg=>'language');
16 5 has 'google_client' => (is=>'rw',isa=>'Str',default=>'', reader=>'get_google_client', init_arg=>'client');
17 5 has 'google_apiver' => (is=>'rw',isa=>'Num',default=>3, reader=>'get_google_apiver', init_arg=>'apiver');
18 5 has 'google_encoding' => (is=>'rw',isa=>'Str',default=>'utf8',reader=>'get_google_encoding', init_arg=>'encoding');
19 5 has 'google_country_code' => (is=>'rw',isa=>'Str',default=>'', reader=>'get_google_country_code', init_arg=>'country_code');
20 5 has 'google_sensor' => (is=>'rw',isa=>'Str',default=>'', reader=>'get_google_sensor', init_arg=>'sensor');
21  
22 5 has 'geocoder_engine' => (
23 is => 'rw',
24 init_arg => undef,
25 lazy => 1,
26 isa => 'Object',
27 builder => '_build_geocoder_engine',
28 handles =>{
29 geocode => 'geocode_local',
30 reverse_geocode => 'reverse_geocode_local'
31 }
32 );
33  
34 1 ▶sub _build_geocoder_engine {
Subroutine _build_geocoder_engine: called CC=4 SCAR=16.1
35 1 my $self = shift;
36 1 my $geocoder = $self->geocoder;
37
38 1 ▶ if(!$VALID_GEOCODER_LIST{$geocoder} && $geocoder !~ /::/ ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($VALID_GEOCODER_LIST{$geocoder} or $geocoder =~ /::/) 0 1 1
Condition33%1/3
$VALID_GEOCODER_LIST{$geocoder} or $geocoder =~ /::/
l!l&&r!l&&!r
100
MC/DC0%0/2
$VALID_GEOCODER_LIST{$geocoder} or $geocoder =~ /::/
$VALID_GEOCODER_LIST{$geocoder} $geocoder =~ /::/
Truth table33%1/3
A or B
A= $VALID_GEOCODER_LIST{$geocoder}B= $geocoder =~ /::/
ABresult
1X1
011
000
39 0 $geocoder = 'Google';
40 0 $self->geocoder('Google');
41 }
42
43 1 ▶ my $class = ($geocoder =~ /::/ ? $geocoder : 'Geo::Coder::All::'.$geocoder);
Branch: 1 branch
BranchTrueFalseTotal
$geocoder =~ /::/ ? : 0 1 1
44 1 require_module($class);
45 1 return $class->new();
46 }
47  
48 1 ▶around 'geocode' => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
49 1 my ($orig,$class,$rh_args) = @_;
50 1 return $class->$orig($class->_process_args($rh_args));
51 5 };
52  
53 0 ▶around 'reverse_geocode' => sub{
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 my ($orig,$class,$rh_args) = @_;
55 0 return $class->$orig($class->_process_args($rh_args));
56 5 };
57 #process the args passed to create new Geo::Coder::Google
58 1 ▶sub _process_args {
Subroutine _process_args: called CC=11 SCAR=32.6
59 1 my ($self,$rh_args) =@_;
60 1 ▶ $rh_args->{key} ||= $self->get_key;
Condition33%1/3
$rh_args->{"key"} ||= $self->get_key
l!l&&r!l&&!r
001
MC/DC0%0/2
$rh_args->{"key"} ||= $self->get_key
$rh_args->{"key"} $self->get_key
Truth table33%1/3
A ||= B
A= $rh_args->{"key"}B= $self->get_key
ABresult
1X1
011
000
61 1 ▶ $rh_args->{language} ||= $self->get_language;
Condition33%1/3
$rh_args->{"language"} ||= $self->get_language
l!l&&r!l&&!r
010
MC/DC0%0/2
$rh_args->{"language"} ||= $self->get_language
$rh_args->{"language"} $self->get_language
Truth table33%1/3
A ||= B
A= $rh_args->{"language"}B= $self->get_language
ABresult
1X1
011
000
62 1 ▶ $rh_args->{google_apiver}= $self->get_google_apiver || $rh_args->{apiver} if($self->geocoder eq 'Gooole');
Branch: 1 branch
BranchTrueFalseTotal
if $self->geocoder eq "Gooole" 0 1 1
Condition0%0/3
$self->get_google_apiver || $rh_args->{'apiver'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_google_apiver || $rh_args->{'apiver'}
$self->get_google_apiver $rh_args->{'apiver'}
Truth table0%0/3
A || B
A= $self->get_google_apiverB= $rh_args->{'apiver'}
ABresult
1X1
011
000
63 1 ▶ $rh_args->{google_client}= $self->get_google_client || $rh_args->{client} if($self->geocoder eq 'Google');
Branch: 1 branch
BranchTrueFalseTotal
if $self->geocoder eq "Google" 1 0 1
Condition33%1/3
$self->get_google_client || $rh_args->{'client'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->get_google_client || $rh_args->{'client'}
$self->get_google_client $rh_args->{'client'}
Truth table33%1/3
A || B
A= $self->get_google_clientB= $rh_args->{'client'}
ABresult
1X1
011
000
64 1 ▶ $rh_args->{google_encoding}= $self->get_google_encoding || $rh_args->{encoding} if($self->geocoder eq 'Google');
Branch: 1 branch
BranchTrueFalseTotal
if $self->geocoder eq "Google" 1 0 1
Condition33%1/3
$self->get_google_encoding || $rh_args->{'encoding'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->get_google_encoding || $rh_args->{'encoding'}
$self->get_google_encoding $rh_args->{'encoding'}
Truth table33%1/3
A || B
A= $self->get_google_encodingB= $rh_args->{'encoding'}
ABresult
1X1
011
000
65 1 ▶ $rh_args->{google_country_code}= $self->get_google_country_code || $rh_args->{country_code} if($self->geocoder eq 'Google');
Branch: 1 branch
BranchTrueFalseTotal
if $self->geocoder eq "Google" 1 0 1
Condition33%1/3
$self->get_google_country_code || $rh_args->{'country_code'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->get_google_country_code || $rh_args->{'country_code'}
$self->get_google_country_code $rh_args->{'country_code'}
Truth table33%1/3
A || B
A= $self->get_google_country_codeB= $rh_args->{'country_code'}
ABresult
1X1
011
000
66 1 return $rh_args;
67 }
68  
69 =head1 NAME
70  
71 Geo::Coder::All - Geo::Coder::All
72  
73 =head1 VERSION
74  
75 Version 0.06
76  
77 =cut
78  
79 5 our $VERSION = '0.06';
80  
81  
82 =head1 DESCRIPTION
83  
84 Geo::Coder::All is wrapper for other geocoder cpan modules such as Geo::Coder::Google,Geo::Coder::Bing,Geo::Coder::Ovi,Geo::Coder::OSM and Geo::Coder::TomTom. Geo::Coder::All provides common geocode output format for all geocoder.
85  
86  
87 =head1 SYNOPSIS
88  
89 use Geo::Coder::All;
90 #For google geocoder
91 my $google_geocoder = Geo::Coder::All->new();#geocoder defaults to Geo::Coder::Google::V3
92 #You can also use optional params for google api
93 my $google_geocoder = Geo::Coder::All->new(key=>'GMAP_KEY',client=>'GMAP_CLIENT');
94  
95 #For Bing
96 my $bing_geocoder = Geo::Coder::All->new(geocoder=>'Bing',key=>'BING_API_KEY');
97  
98 #For Ovi
99 my $ovi_geocoder = Geo::Coder::All->new(geocoder=>'Ovi');
100  
101 #For OSM
102 my $osm_geocoder = Geo::Coder::All->new(geocoder=>'OSM');
103  
104 #For TomTom
105 my $tomtom_geocoder = Geo::Coder::All->new(geocoder=>'TomTom');
106  
107 #Currently supported geocoders are
108 Geo::Coder::Google
109 Geo::Coder::Bing
110 Geo::Coder::TomTom
111 Geo::Coder::Ovi
112 Geo::Coder::OSM
113 #only Geo::Coder::Google is installed by default if you need to use other then you should install them manually
114  
115 #IF you want use geocder that is not listed above then you can now specify fully qualified class wrapper name to add your own custom handling for response. Please have look at how Geo::Coder::All::Google is working.
116  
117 =head1 METHODS
118  
119 Geo::Coder::All offers geocode and reverse_geocode methods
120  
121 =over 2
122  
123 =item geocode
124  
125 For Google geocoder , we can directly set the different geocoding options when calling geocode and reverse_geocode methods. i.e If you use Geo::Coder::Google you will have to create new instance every single time you need to change geocoding options
126  
127 $rh_location = $google_geocoder->geocode({location => 'London'});
128 #above will return London from United Kingdom
129 #With geocoding options
130 #Following will return London from Canada as we used country_code is ca (country_code is ISO 3166-1 )
131 $rh_location = $google_geocoder->geocode({location => 'London',language=>'en',country_code=>'ca',encoding=>'utf8',sensor=>1});
132 #in spanish
133 $rh_location = $google_geocoder->geocode({location => 'London',language=>'es',country_code=>'ca',encoding=>'utf8',sensor=>1});
134 #default encodings is set to 'utf8' you can change to other such as 'latin1'
135 #You can also set DEGUB=>1 to dump raw response from the geocoder api
136  
137 You cal also set GMAP_KEY and GMAP_CLIENT directly from geocode/reverse_geocode method and it will just work
138  
139 =item reverse_geocode
140  
141 For Google reverse_geocoder
142  
143 $rh_location = $google_geocoder->reverse_geocode({latlng=>'51.508515,-0.1254872',language=>'en',encoding=>'utf8',sensor=>1})
144 #in spanish
145 $rh_location = $google_geocoder->reverse_geocode({latlng=>'51.508515,-0.1254872',language=>'es',encoding=>'utf8',sensor=>1})
146
147 =back
148  
149 =head1 SEE ALSO
150  
151 L<Geo::Coder::Many>,
152 L<Geo::Coder::Google>,
153 L<Geo::Coder::Bing>,
154 L<Geo::Coder::Ovi>,
155 L<Geo::Coder::OSM> and
156 L<Geo::Coder::TomTom>.
157  
158 =head1 AUTHOR
159  
160 Rohit Deshmukh, C<< <raigad1630 at gmail.com> >>
161  
162 =head1 BUGS
163  
164 Please report any bugs or feature requests to C<bug-geo-coder-all at rt.cpan.org>, or through
165 the web interface at L<https://github.com/raigad/geo-coder-all/issues>. I will be notified, and then you'll
166 automatically be notified of progress on your bug as I make changes.
167  
168 =head1 SUPPORT
169  
170 You can find documentation for this module with the perldoc command.
171  
172 perldoc Geo::Coder::All
173  
174 =head1 ACKNOWLEDGEMENTS
175  
176 Peter Sergeant, C<< <sargie@cpan.org> >>
177  
178 Neil Bowers, C<< <neilb@cpan.org> >>
179  
180 =head1 LICENSE AND COPYRIGHT
181  
182 Copyright 2014 Rohit Deshmukh.
183  
184 =cut
185  
186 5 1; # End of Geo::Coder::All
↑ Summary All/Bing.pm »