Skip to content

Commit

Permalink
Fix reverse_coding argument parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 9, 2019
1 parent f29ca95 commit 4933f0f
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -31,7 +31,7 @@ Revision history for Geo-Coder-List
0.19 Sun Apr 15 20:42:05 EDT 2018 0.19 Sun Apr 15 20:42:05 EDT 2018
Support Geo::GeoNames Support Geo::GeoNames
Explicit about which loop to finish Explicit about which loop to finish
Fix ununinitialized variable Fix uninitialized variable
Fix https://github.com/Humanstate/html-googlemaps-v3/issues/17 Fix https://github.com/Humanstate/html-googlemaps-v3/issues/17


0.18 Tue Dec 26 08:18:54 EST 2017 0.18 Tue Dec 26 08:18:54 EST 2017
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST
@@ -1,3 +1,4 @@
bin/address_lookup
Changes Changes
ignore.txt ignore.txt
lib/Geo/Coder/List.pm lib/Geo/Coder/List.pm
Expand All @@ -24,9 +25,12 @@ t/google.t
t/googleplaces.t t/googleplaces.t
t/gv.t t/gv.t
t/kwalitee.t t/kwalitee.t
t/links.t
t/list.t t/list.t
t/manifest.t t/manifest.t
t/no404s.t
t/noplan.t t/noplan.t
t/online.enabled
t/opencage.t t/opencage.t
t/osm.t t/osm.t
t/ovi.t t/ovi.t
Expand Down
4 changes: 4 additions & 0 deletions bin/address_lookup
Expand Up @@ -19,6 +19,7 @@ use Geo::Coder::Free;
use Geo::Coder::Free::Local; use Geo::Coder::Free::Local;
use Geo::Coder::GooglePlaces; use Geo::Coder::GooglePlaces;
use Geo::Coder::List; use Geo::Coder::List;
use Geo::Coder::OpenCage;
use Geo::Coder::OSM; use Geo::Coder::OSM;
use Geo::Coder::Ovi; use Geo::Coder::Ovi;
use Geo::Coder::Postcodes; use Geo::Coder::Postcodes;
Expand Down Expand Up @@ -71,6 +72,9 @@ $geocoder->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder:
->push(Geo::Coder::Ovi->new()); ->push(Geo::Coder::Ovi->new());
# ->push(Geo::Coder::GeocodeFarm->new()); # Needs GT#1 to be fixed # ->push(Geo::Coder::GeocodeFarm->new()); # Needs GT#1 to be fixed


if(my $key = $ENV{'GEO_CODER_OPENCAGE_API_KEY'}) {
$geocoder->push({ limit => 200, geocoder => Geo::Coder::OpenCage->new(api_key => $key) });
}
if(my $key = $ENV{'GMAP_KEY'}) { if(my $key = $ENV{'GMAP_KEY'}) {
$geocoder->push({ limit => 200, geocoder => Geo::Coder::GooglePlaces->new(key => $key, api_key => $key) }); $geocoder->push({ limit => 200, geocoder => Geo::Coder::GooglePlaces->new(key => $key, api_key => $key) });
} }
Expand Down
14 changes: 6 additions & 8 deletions lib/Geo/Coder/List.pm
Expand Up @@ -417,12 +417,12 @@ Similar to geocode except it expects a latitude/longitude parameter.


sub reverse_geocode { sub reverse_geocode {
my $self = shift; my $self = shift;
my %params = @_; my %params;


if(ref($_[0]) eq 'HASH') { if(ref($_[0]) eq 'HASH') {
%params = %{$_[0]}; %params = %{$_[0]};
} elsif(ref($_[0])) { } elsif(ref($_[0])) {
Carp::croak('Usage: geocode(location => $location)'); Carp::croak('Usage: reverse_geocode(location => $location)');
} elsif(@_ % 2 == 0) { } elsif(@_ % 2 == 0) {
%params = @_; %params = @_;
} else { } else {
Expand Down Expand Up @@ -598,12 +598,14 @@ sub _cache {
foreach my $item(@{$value}) { foreach my $item(@{$value}) {
if(ref($item) eq 'HASH') { if(ref($item) eq 'HASH') {
foreach my $key(keys(%{$item})) { foreach my $key(keys(%{$item})) {
delete $item->{$key} unless ($key eq 'geometry'); # while(my($key, $value) = each %{$item}) {
delete $item->{$key} unless($key eq 'geometry');
} }
} }
} }
} elsif(ref($value) eq 'HASH') { } elsif(ref($value) eq 'HASH') {
foreach my $key(keys(%{$value})) { foreach my $key(keys(%{$value})) {
# while(my($key, $value) = each %{$value}) {
delete $value->{$key} unless ($key eq 'geometry'); delete $value->{$key} unless ($key eq 'geometry');
} }
} }
Expand Down Expand Up @@ -637,9 +639,9 @@ reverse_geocode() should support L<Geo::Location::Point> objects.
=head1 SEE ALSO =head1 SEE ALSO
L<Geo::Coder::Many>
L<Geo::Coder::All> L<Geo::Coder::All>
L<Geo::Coder::GooglePlaces> L<Geo::Coder::GooglePlaces>
L<Geo::Coder::Many>
=head1 SUPPORT =head1 SUPPORT
Expand All @@ -655,10 +657,6 @@ You can also look for information at:
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Geo-Coder-List> L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Geo-Coder-List>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Geo-Coder-List>
=item * CPAN Ratings =item * CPAN Ratings
L<http://cpanratings.perl.org/d/Geo-Coder-List> L<http://cpanratings.perl.org/d/Geo-Coder-List>
Expand Down
16 changes: 16 additions & 0 deletions t/links.t
@@ -0,0 +1,16 @@
#!perl -w

use strict;
use warnings;
use Test::Most;

if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

eval "use Test::Pod::LinkCheck";
if($@) {
plan(skip_all => 'Test::Pod::LinkCheck required for testing POD');
} else {
Test::Pod::LinkCheck->new->all_pod_ok();
}
16 changes: 16 additions & 0 deletions t/no404s.t
@@ -0,0 +1,16 @@
#!perl -wT

use strict;
use warnings;
use Test::Most;

if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

eval "use Test::Pod::No404s";
if($@) {
plan(skip_all => 'Test::Pod::No404s required for testing POD');
} else {
all_pod_files_ok();
}
62 changes: 62 additions & 0 deletions t/opencage.t
@@ -0,0 +1,62 @@
#!perl -wT

use strict;
use warnings;
use Test::Most tests => 16;
use Test::NoWarnings;

eval 'use autodie qw(:all)'; # Test for open/close failures

BEGIN {
use_ok('Geo::Coder::List');
}

BING: {
SKIP: {
skip 'Test requires Internet access', 14 unless(-e 't/online.enabled');

eval {
require Geo::Coder::OpenCage;

Geo::Coder::OpenCage->import();

require Test::Number::Delta;

Test::Number::Delta->import();
};

if($@) {
diag('Geo::Coder::OpenCage not installed - skipping tests');
skip 'Geo::Coder::OpenCage not installed', 14;
} else {
diag("Using Geo::Coder::OpenCage $Geo::Coder::OpenCage::VERSION");
}

if(my $key = $ENV{'GEO_CODER_OPENCAGE_API_KEY'}) {
my $geocoderlist = new_ok('Geo::Coder::List');
my $geocoder = new_ok('Geo::Coder::OpenCage' => [ api_key => $key ]);
$geocoderlist->push($geocoder);

my $location = $geocoderlist->geocode('Silver Spring, MD, USA');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 38.991, 1e-1);
delta_within($location->{geometry}{location}{lng}, -77.026, 1e-1);

$location = $geocoderlist->geocode('Wisdom Hospice, Rochester, England');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 51.396, 1e-1);
delta_within($location->{geometry}{location}{lng}, 0.488, 1e-1);

$location = $geocoderlist->geocode('St Mary The Virgin, Minster, Thanet, Kent, England');
ok(defined($location));
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 51.330, 1e-1);
delta_within($location->{geometry}{location}{lng}, 1.31596, 1e-1);
} else {
diag('Set BMAP_KEY to enable more tests');
skip 'BMAP_KEY not set', 14;
}
}
}
6 changes: 3 additions & 3 deletions t/spelling.t
Expand Up @@ -5,13 +5,13 @@ use warnings;


use Test::Most; use Test::Most;


unless($ENV{RELEASE_TESTING}) { unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" ); plan(skip_all => 'Author tests not required for installation');
} }


eval 'use Test::Spelling'; eval 'use Test::Spelling';
if($@) { if($@) {
plan skip_all => 'Test::Spelling required for testing POD spelling'; plan(skip_all => 'Test::Spelling required for testing POD spelling');
} else { } else {
add_stopwords(<DATA>); add_stopwords(<DATA>);
all_pod_files_spelling_ok(); all_pod_files_spelling_ok();
Expand Down

0 comments on commit 4933f0f

Please sign in to comment.