diff --git a/Changes b/Changes index 5ba3f0e..786eeca 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ Revision history for Geo-Coder-List Use Test::Needs Error if there's something wrong in the cache Looks like Geo::Coder::US::Census sometimes says it's worked when it hasn't + Set the geocoder to 'cache' rather than undef for cached items 0.32 Sat Oct 7 10:07:45 EDT 2023 Set "geocoder" to "cached" when the values have been retrieved from the L2 cache diff --git a/lib/Geo/Coder/List.pm b/lib/Geo/Coder/List.pm index a799280..71c23ce 100644 --- a/lib/Geo/Coder/List.pm +++ b/lib/Geo/Coder/List.pm @@ -104,7 +104,7 @@ and OpenStreetMap for other places: } # It is also possible to limit the number of enquires used by a particular encoder - $geo_coderlist->push({ geocoder => Geo::Coder::GooglePlaces->new(key => '1234'), limit => 100) }); + $geo_coderlist->push({ geocoder => Geo::Coder::GooglePlaces->new(key => '1234', limit => 100) }); =cut @@ -162,12 +162,12 @@ sub geocode { $rc = $rc->[0]; } if(ref($rc) eq 'HASH') { - delete $rc->{'geocoder'}; + $rc->{'geocoder'} = 'cache'; my $log = { line => $call_details[2], location => $location, timetaken => 0, - gecoder => 'cached', + gecoder => 'cache', wantarray => 0, result => $rc }; @@ -183,13 +183,13 @@ sub geocode { if(ref($_) eq 'HASH') { if(defined($_->{geometry}{location}{lat})) { $allempty = 0; - $_->{'geocoder'} = 'cached'; + $_->{'geocoder'} = 'cache'; } else { delete $_->{'geometry'}; } } elsif(ref($_) eq 'Geo::Location::Point') { $allempty = 0; - $_->{'geocoder'} = 'cached'; + $_->{'geocoder'} = 'cache'; } else { print STDERR Data::Dumper->new([\@rc])->Dump(); Carp::croak(ref($self), " '$location': unexpected item in the cache"); @@ -199,7 +199,7 @@ sub geocode { line => $call_details[2], location => $location, timetaken => 0, - gecoder => 'cached', + gecoder => 'cache', wantarray => wantarray, result => \@rc }; @@ -295,8 +295,7 @@ sub geocode { # FIXME: should consider all locations in the array $l = $l->[0]; } - $l->{'geocoder'} = ref($geocoder); - if(!defined($l)) { + if((!defined($l)) || ($l eq '')) { my $log = { line => $call_details[2], location => $location, @@ -308,6 +307,7 @@ sub geocode { CORE::push @{$self->{'log'}}, $log; next ENCODER; } + $l->{'geocoder'} = ref($geocoder); print ref($geocoder), ': ', Data::Dumper->new([\$l])->Dump() if($self->{'debug'} >= 2); last if(ref($l) eq 'Geo::Location::Point'); diff --git a/t/list.t b/t/list.t index 03cf92b..e633f8c 100644 --- a/t/list.t +++ b/t/list.t @@ -134,7 +134,7 @@ LIST: { ok(ref($location) eq 'HASH'); delta_within($location->{geometry}{location}{lat}, 41.1, 1e-1); delta_within($location->{geometry}{location}{lng}, -85.06, 1e-1); - is($location->{'geocoder'}, undef, 'Verify subsequent scalar reads are cached'); + is($location->{'geocoder'}, 'cache', 'Verify subsequent scalar reads are cached'); @locations = $geocoderlist->geocode({ location => 'Allen, Indiana, USA' }); ok(scalar(@locations) == $count); @@ -142,7 +142,7 @@ LIST: { ok(ref($location) eq 'HASH'); delta_within($location->{geometry}{location}{lat}, 41.1, 1e-1); delta_within($location->{geometry}{location}{lng}, -85.06, 1e-1); - is($location->{'geocoder'}, undef, 'Verify subsequent list reads are cached'); + is($location->{'geocoder'}, 'cache', 'Verify subsequent list reads are cached'); $location = $geocoderlist->geocode('Ramsgate, Kent, England'); ok(defined($location)); diff --git a/t/osm.t b/t/osm.t index 5cda870..3c61312 100644 --- a/t/osm.t +++ b/t/osm.t @@ -111,6 +111,6 @@ OSM: { @locations = $geocoderlist->geocode('Portland, USA'); ok(scalar(@locations) == $count); - is($locations[0]->{'geocoder'}, undef, 'Verify subsequent reads are cached'); + is($locations[0]->{'geocoder'}, 'cache', 'Verify subsequent reads are cached'); } }