Skip to content

Commit

Permalink
GeoApify doesn't give an error if a location is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 5, 2024
1 parent 64302c7 commit f53ff85
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Geo-Coder-List

0.35
GeoApify doesn't give an error if a location is not found

0.34 Sat Oct 26 20:42:57 EDT 2024
Turn off on-line tests for smokers
Use Test::DescribeMe to simplify tests
Expand Down
6 changes: 6 additions & 0 deletions lib/Geo/Coder/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,16 @@ sub geocode {
$lat = $l->{'features'}[0]{'geometry'}{'coordinates'}[1];
$long = $l->{'features'}[0]{'geometry'}{'coordinates'}[0];
$l->{'debug'} = __LINE__;
} else {
# GeoApify doesn't give an error if a location is not found
next ENCODER;
}
} else {
$l->{'debug'} = __LINE__;
}

if(defined($lat) && defined($long)) {
print __LINE__, "\n";
$l->{geometry}{location}{lat} = $lat;
$l->{geometry}{location}{lng} = $long;
} else {
Expand All @@ -414,6 +418,7 @@ sub geocode {
}
}
if(defined($l->{geometry}{location}{lat})) {
print __LINE__, "\n";
print $l->{geometry}{location}{lat}, '/', $l->{geometry}{location}{lng}, "\n" if($self->{'debug'});
$l->{geocoder} = $geocoder;
$l->{'lat'} //= $l->{geometry}{location}{lat};
Expand All @@ -429,6 +434,7 @@ sub geocode {
CORE::push @{$self->{'log'}}, $log;
last POSSIBLE_LOCATION;
}
print __LINE__, "\n";
}
}

Expand Down
34 changes: 32 additions & 2 deletions t/10-new.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@

use strict;

use Test::Most tests => 4;
use Scalar::Util qw(blessed);
use Test::Most tests => 13;

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

isa_ok(Geo::Coder::List->new(), 'Geo::Coder::List', 'Creating Geo::Coder::List object');
isa_ok(Geo::Coder::List::new(), 'Geo::Coder::List', 'Creating Geo::Coder::List object');
isa_ok(Geo::Coder::List->new()->new(), 'Geo::Coder::List', 'Cloning Geo::Coder::List object');
# ok(!defined(Geo::Coder::List::new()));

# Test 1: Basic object instantiation
my $object = Geo::Coder::List->new();
isa_ok($object, 'Geo::Coder::List', 'Object created with ->new() is of correct class');

# Test 2: Passing arguments as hash
my $object_with_args = Geo::Coder::List->new(debug => 1, geo_coders => ['Google']);
is($object_with_args->{debug}, 1, 'debug flag set correctly');
is_deeply($object_with_args->{geo_coders}, ['Google'], 'geo_coders set correctly from hash');

# Test 3: Passing arguments as hashref
my $args_ref = { debug => 1, geo_coders => ['Bing'] };
my $object_with_hashref_args = Geo::Coder::List->new($args_ref);
is($object_with_hashref_args->{debug}, 1, 'debug flag set correctly from hashref');
is_deeply($object_with_hashref_args->{geo_coders}, ['Bing'], 'geo_coders set correctly from hashref');

# Test 4: Cloning an object with new arguments
my $cloned_object = $object_with_args->new(debug => 0);
ok(blessed($cloned_object), 'Cloned object is blessed');
is($cloned_object->{debug}, 0, 'Cloned object has new debug value');
cmp_ok($cloned_object->{geo_coders}[0], 'eq', 'Google', 'Cloned object retains original geo_coders value');

# Test 5: Using ::new() syntax
eval {
my $incorrect_object = Geo::Coder::List::new();
isa_ok($incorrect_object, 'Geo::Coder::List', 'Object created with ::new() is of correct class');
};

0 comments on commit f53ff85

Please sign in to comment.