diff --git a/Changes b/Changes index 9e428cc..463f1a9 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/Geo/Coder/List.pm b/lib/Geo/Coder/List.pm index 94e7772..e1b673f 100644 --- a/lib/Geo/Coder/List.pm +++ b/lib/Geo/Coder/List.pm @@ -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 { @@ -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}; @@ -429,6 +434,7 @@ sub geocode { CORE::push @{$self->{'log'}}, $log; last POSSIBLE_LOCATION; } + print __LINE__, "\n"; } } diff --git a/t/10-new.t b/t/10-new.t index e2d2f38..9375e43 100644 --- a/t/10-new.t +++ b/t/10-new.t @@ -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'); +};