Skip to content
Permalink
Browse files

Fix reverse_coding argument parser

  • Loading branch information...
nigelhorne committed Oct 9, 2019
1 parent f29ca95 commit 4933f0f904240691ce53ffd5ad47b862acc4f83d
Showing with 112 additions and 12 deletions.
  1. +1 −1 Changes
  2. +4 −0 MANIFEST
  3. +4 −0 bin/address_lookup
  4. +6 −8 lib/Geo/Coder/List.pm
  5. +16 −0 t/links.t
  6. +16 −0 t/no404s.t
  7. +62 −0 t/opencage.t
  8. +3 −3 t/spelling.t
@@ -31,7 +31,7 @@ Revision history for Geo-Coder-List
0.19 Sun Apr 15 20:42:05 EDT 2018
Support Geo::GeoNames
Explicit about which loop to finish
Fix ununinitialized variable
Fix uninitialized variable
Fix https://github.com/Humanstate/html-googlemaps-v3/issues/17

0.18 Tue Dec 26 08:18:54 EST 2017
@@ -1,3 +1,4 @@
bin/address_lookup
Changes
ignore.txt
lib/Geo/Coder/List.pm
@@ -24,9 +25,12 @@ t/google.t
t/googleplaces.t
t/gv.t
t/kwalitee.t
t/links.t
t/list.t
t/manifest.t
t/no404s.t
t/noplan.t
t/online.enabled
t/opencage.t
t/osm.t
t/ovi.t
@@ -19,6 +19,7 @@ use Geo::Coder::Free;
use Geo::Coder::Free::Local;
use Geo::Coder::GooglePlaces;
use Geo::Coder::List;
use Geo::Coder::OpenCage;
use Geo::Coder::OSM;
use Geo::Coder::Ovi;
use Geo::Coder::Postcodes;
@@ -71,6 +72,9 @@ $geocoder->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder:
->push(Geo::Coder::Ovi->new());
# ->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'}) {
$geocoder->push({ limit => 200, geocoder => Geo::Coder::GooglePlaces->new(key => $key, api_key => $key) });
}
@@ -417,12 +417,12 @@ Similar to geocode except it expects a latitude/longitude parameter.

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

if(ref($_[0]) eq 'HASH') {
%params = %{$_[0]};
} elsif(ref($_[0])) {
Carp::croak('Usage: geocode(location => $location)');
Carp::croak('Usage: reverse_geocode(location => $location)');
} elsif(@_ % 2 == 0) {
%params = @_;
} else {
@@ -598,12 +598,14 @@ sub _cache {
foreach my $item(@{$value}) {
if(ref($item) eq 'HASH') {
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') {
foreach my $key(keys(%{$value})) {
# while(my($key, $value) = each %{$value}) {
delete $value->{$key} unless ($key eq 'geometry');
}
}
@@ -637,9 +639,9 @@ reverse_geocode() should support L<Geo::Location::Point> objects.
=head1 SEE ALSO
L<Geo::Coder::Many>
L<Geo::Coder::All>
L<Geo::Coder::GooglePlaces>
L<Geo::Coder::Many>
=head1 SUPPORT
@@ -655,10 +657,6 @@ You can also look for information at:
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
L<http://cpanratings.perl.org/d/Geo-Coder-List>
@@ -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();
}
@@ -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();
}
@@ -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;
}
}
}
@@ -5,13 +5,13 @@ use warnings;

use Test::Most;

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

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

0 comments on commit 4933f0f

Please sign in to comment.
You can’t perform that action at this time.