blib/lib/Mojolicious/Plugin/GeoCoder.pm

filter: Statementstmt 48.2% 14 / 29 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 57.1% 4 / 7 Podpod 100% 1 / 1 totaltotal 20.4% 19 / 93 CC 17 SCAR 42.6
CC
17
Cov
20%
__ANON__
90.0
__ANON__
90.0
register
2.0
CRAP 70.7
↑ Summary
1 package Mojolicious::Plugin::GeoCoder;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Geo::Coder::Google;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod documented
11 0 my ($self,$app,$rh_conf) = @_;
12 0 ▶ $app->helper(geocode => sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
13 0 my ($self,$rh_args) = @_;
14
15 0 ▶ return { } unless($rh_args->{location});
Branch: 1 branch
BranchTrueFalseTotal
unless $rh_args->{"location"} 0 0 0
16  
17 my $geocoder = Geo::Coder::Google->new(
18 apiver => 3,
19 ( $rh_args->{country_code} || $rh_conf->{country_code} ?
20 (gl => $rh_args->{country_code} || $rh_conf->{country_code}) : ()),
21 0 ▶ language => $rh_args->{language_code} || $rh_conf->{language_code} || 'en',
Branch: 1 branch
BranchTrueFalseTotal
$rh_args->{'country_code'} || $rh_conf->{'country_code'} ? : 0 0 0
Condition0%0/11
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
l!l&&r!l&&!r
000
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
l!l&&r!l&&!r
000
$rh_args->{'language_code'} || $rh_conf->{'language_code'} || 'en'
l!l
00
$rh_args->{"language_code"} or $rh_conf->{"language_code"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
$rh_args->{"country_code"} $rh_conf->{"country_code"}
MC/DC0%0/2
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
$rh_args->{"country_code"} $rh_conf->{"country_code"}
MC/DC0%0/2
$rh_args->{'language_code'} || $rh_conf->{'language_code'} || 'en'
$rh_args->{"language_code"} $rh_conf->{"language_code"}
Truth table0%0/3
A or B
A= $rh_args->{"country_code"}B= $rh_conf->{"country_code"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $rh_args->{"country_code"}B= $rh_conf->{"country_code"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $rh_args->{"language_code"}B= $rh_conf->{"language_code"}
ABresult
1X1
011
000
22 );
23  
24 0 my $rh_response = $geocoder->geocode(location=> $rh_args->{location});
25  
26 0 ▶ return $rh_response if($rh_conf->{raw_response} || $rh_conf->{raw_response});
Branch: 1 branch
BranchTrueFalseTotal
if $rh_conf->{"raw_response"} or $rh_conf->{"raw_response"} 0 0 0
Condition0%0/3
$rh_conf->{"raw_response"} or $rh_conf->{"raw_response"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$rh_conf->{"raw_response"} or $rh_conf->{"raw_response"}
$rh_conf->{"raw_response"} $rh_conf->{"raw_response"}
Truth table0%0/3
A or B
A= $rh_conf->{"raw_response"}B= $rh_conf->{"raw_response"}
ABresult
1X1
011
000
27  
28 return {
29 address => $rh_response->{formatted_address},
30 lat => $rh_response->{geometry}{location}{lat},
31 lng => $rh_response->{geometry}{location}{lng},
32 0 };
33 0 });
34  
35 0 ▶ $app->helper(reverse_geocode=> sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
36 0 my ($self,$rh_args) =@_;
37  
38 0 ▶ return { } unless($rh_args->{latlng});
Branch: 1 branch
BranchTrueFalseTotal
unless $rh_args->{"latlng"} 0 0 0
39  
40 my $geocoder = Geo::Coder::Google->new(
41 apiver => 3,
42 ( $rh_args->{country_code} || $rh_conf->{country_code} ?
43 (gl => $rh_args->{country_code} || $rh_conf->{country_code}) : ()),
44 0 ▶ language => $rh_args->{language_code} || $rh_conf->{language_code} || 'en',
Branch: 1 branch
BranchTrueFalseTotal
$rh_args->{'country_code'} || $rh_conf->{'country_code'} ? : 0 0 0
Condition0%0/11
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
l!l&&r!l&&!r
000
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
l!l&&r!l&&!r
000
$rh_args->{'language_code'} || $rh_conf->{'language_code'} || 'en'
l!l
00
$rh_args->{"language_code"} or $rh_conf->{"language_code"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
$rh_args->{"country_code"} $rh_conf->{"country_code"}
MC/DC0%0/2
$rh_args->{"country_code"} or $rh_conf->{"country_code"}
$rh_args->{"country_code"} $rh_conf->{"country_code"}
MC/DC0%0/2
$rh_args->{'language_code'} || $rh_conf->{'language_code'} || 'en'
$rh_args->{"language_code"} $rh_conf->{"language_code"}
Truth table0%0/3
A or B
A= $rh_args->{"country_code"}B= $rh_conf->{"country_code"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $rh_args->{"country_code"}B= $rh_conf->{"country_code"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $rh_args->{"language_code"}B= $rh_conf->{"language_code"}
ABresult
1X1
011
000
45 );
46 0 my $rh_response = $geocoder->reverse_geocode(latlng => $rh_args->{latlng});
47  
48 0 ▶ return $rh_response if($rh_conf->{raw_response} || $rh_conf->{raw_response});
Branch: 1 branch
BranchTrueFalseTotal
if $rh_conf->{"raw_response"} or $rh_conf->{"raw_response"} 0 0 0
Condition0%0/3
$rh_conf->{"raw_response"} or $rh_conf->{"raw_response"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$rh_conf->{"raw_response"} or $rh_conf->{"raw_response"}
$rh_conf->{"raw_response"} $rh_conf->{"raw_response"}
Truth table0%0/3
A or B
A= $rh_conf->{"raw_response"}B= $rh_conf->{"raw_response"}
ABresult
1X1
011
000
49  
50 return {
51 address => $rh_response->{formatted_address},
52 lat => $rh_response->{geometry}{location}{lat},
53 lng => $rh_response->{geometry}{location}{lng},
54 }
55 0 });
56 }
57 =head1 GeoCoder
58  
59 Mojolicious::Plugin::GeoCoder - Plugin for geocoding and reverse geocoding features!
60  
61 =head1 VERSION
62  
63 Version 0.05
64  
65 =cut
66  
67 =head1 SYNOPSIS
68  
69  
70 #Mojolicious lite
71  
72 plugin 'GeoCoder' => { language_code=> 'es' }; #by default language code 'en'
73  
74 #or you could do
75  
76 my $rh_conf = {
77 language_code => 'en',
78 encoding => 'latin1' #by default its utf-8
79 };
80  
81 plugin 'GeoCoder' => $rh_conf;
82  
83 #in controller
84 my $rh_location = $self->geocode({location=> 'London'});
85  
86 my $rh_location = $self->reverse_geocode({latlng=> '18.234686,73.446444'});
87  
88 #to get raw response from geocoder
89 my $rh_location = $self->geocode({location=> 'London',raw_response => 1 });
90  
91 #To change language to fr and country to canada only for one request
92 #Now following will return London from Canada instead of real London from UK
93 my $rh_location = $self->geocode({location=> 'London',language_code=>'fr',country_code => 'ca' });
94  
95 #default response
96 {
97 'lat' => '51.5073509',
98 'address' => 'London, UK',
99 'lng' => '-0.1277583'
100 };
101
102 =cut
103  
104  
105 =head1 AUTHOR
106  
107 Rohit Deshmukh, C<< <raigad1630 at gmail.com> >>
108  
109 =head1 BUGS
110  
111 Please report any bugs or feature requests to https://github.com/raigad/mojolicious-plugin-geocoder/issues
112  
113 =head1 SUPPORT
114  
115 You can find documentation for this module with the perldoc command.
116  
117 perldoc Mojolicious::Plugin::GeoCoder
118  
119  
120 =head1 ACKNOWLEDGEMENTS
121  
122  
123 =head1 LICENSE AND COPYRIGHT
124  
125 Copyright 2014 Rohit Deshmukh.
126  
127 =cut
128  
129 1 1; # End of Mojolicious::Plugin::GeoCoder
↑ Summary