diff --git a/Changes b/Changes index cdc44f4..cf3559f 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/MANIFEST b/MANIFEST index 7774a24..209c9a2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 diff --git a/bin/address_lookup b/bin/address_lookup index 51210ef..dcb11ba 100755 --- a/bin/address_lookup +++ b/bin/address_lookup @@ -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) }); } diff --git a/lib/Geo/Coder/List.pm b/lib/Geo/Coder/List.pm index 1b059f3..caa65dc 100644 --- a/lib/Geo/Coder/List.pm +++ b/lib/Geo/Coder/List.pm @@ -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 objects. =head1 SEE ALSO -L L L +L =head1 SUPPORT @@ -655,10 +657,6 @@ You can also look for information at: L -=item * AnnoCPAN: Annotated CPAN documentation - -L - =item * CPAN Ratings L diff --git a/t/links.t b/t/links.t new file mode 100644 index 0000000..4c1438c --- /dev/null +++ b/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(); +} diff --git a/t/no404s.t b/t/no404s.t new file mode 100644 index 0000000..d4e393f --- /dev/null +++ b/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(); +} diff --git a/t/opencage.t b/t/opencage.t new file mode 100644 index 0000000..9fd8f0e --- /dev/null +++ b/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; + } + } +} diff --git a/t/spelling.t b/t/spelling.t index 29971a3..ed2b1e6 100644 --- a/t/spelling.t +++ b/t/spelling.t @@ -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(); all_pod_files_spelling_ok();