Skip to content

Commit

Permalink
Fix errors found by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed May 15, 2024
1 parent dd356c9 commit 96aa4d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/Geo/Coder/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
};
Expand All @@ -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");
Expand All @@ -199,7 +199,7 @@ sub geocode {
line => $call_details[2],
location => $location,
timetaken => 0,
gecoder => 'cached',
gecoder => 'cache',
wantarray => wantarray,
result => \@rc
};
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions t/list.t
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ 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);
$location = $locations[0];
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));
Expand Down
2 changes: 1 addition & 1 deletion t/osm.t
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 96aa4d5

Please sign in to comment.