Skip to content

Commit

Permalink
Improving handling of failures
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Feb 25, 2018
1 parent f510ac9 commit ea703ff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Version 0.05

Geo::Coder::Free provides an interface to free databases.

Refer to the source URL for licencing information for these files
cities.csv is from https://www.maxmind.com/en/free-world-cities-database
admin1.db is from http://download.geonames.org/export/dump/admin1CodesASCII.txt
admin2.db is from http://download.geonames.org/export/dump/admin2Codes.txt
openaddress data can be downloaded from http://results.openaddresses.io/
Refer to the source URL for licencing information for these files:
cities.csv is from https://www.maxmind.com/en/free-world-cities-database;
admin1.db is from http://download.geonames.org/export/dump/admin1CodesASCII.txt;
admin2.db is from http://download.geonames.org/export/dump/admin2Codes.txt;
openaddress data can be downloaded from http://results.openaddresses.io/.

See also http://download.geonames.org/export/dump/allCountries.zip

Expand All @@ -44,6 +44,9 @@ gunzip cities.csv and run it through the db2sql script to create an SQLite file.

$geocoder = Geo::Coder::Free->new();

Takes one optional parameter, openaddr, which is the base directory of
the OpenAddresses data downloaded from http://results.openaddresses.io.

## geocode

$location = $geocoder->geocode(location => $location);
Expand Down Expand Up @@ -76,9 +79,17 @@ it under the same terms as Perl itself.

Lots of lookups fail at the moment.

The openaddresses.io code has yet to be compeleted. There are die()s where the code path has yet to be written.
The openaddresses.io code has yet to be compeleted.
There are die()s where the code path has yet to be written.

The MaxMind data only contains cities.
The openaddresses data doesn't cover the globe.

Can't parse and handle "London, England".

The MaxMind data only contains cities. The openaddresses data doesn't cover the globe.
Openaddresses look up is slow.
If you rebuild the csv databases as SQLite it will be much quicker.
This should work, but I haven't tested it yet.

# SEE ALSO

Expand Down
19 changes: 11 additions & 8 deletions lib/Geo/Coder/Free.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ our $VERSION = '0.05';
Geo::Coder::Free provides an interface to free databases.
Refer to the source URL for licencing information for these files
cities.csv is from https://www.maxmind.com/en/free-world-cities-database
admin1.db is from http://download.geonames.org/export/dump/admin1CodesASCII.txt
admin2.db is from http://download.geonames.org/export/dump/admin2Codes.txt
openaddress data can be downloaded from http://results.openaddresses.io/
Refer to the source URL for licencing information for these files:
cities.csv is from https://www.maxmind.com/en/free-world-cities-database;
admin1.db is from http://download.geonames.org/export/dump/admin1CodesASCII.txt;
admin2.db is from http://download.geonames.org/export/dump/admin2Codes.txt;
openaddress data can be downloaded from http://results.openaddresses.io/.
See also http://download.geonames.org/export/dump/allCountries.zip
Expand All @@ -73,6 +73,9 @@ gunzip cities.csv and run it through the db2sql script to create an SQLite file.
$geocoder = Geo::Coder::Free->new();
Takes one optional parameter, openaddr, which is the base directory of
the OpenAddresses data downloaded from http://results.openaddresses.io.
=cut

sub new {
Expand All @@ -92,9 +95,9 @@ sub new {
cache => CHI->new(driver => 'Memory', datastore => { })
});

# TODO: This has not been written yet, so it isn't documented
if(my $openaddr = $param{'openaddr'}) {
die "Can't find the directory $openaddr" if((!-d $openaddr) || (!-r $openaddr));
Carp::carp "Can't find the directory $openaddr"
if((!-d $openaddr) || (!-r $openaddr));
return bless { openaddr => $openaddr}, $class;
}

Expand Down Expand Up @@ -230,7 +233,7 @@ sub geocode {
$country = undef;
}
} else {
# TODO: Parse full postal address
# For example, just a country or state has been given
Carp::croak(__PACKAGE__, "Can't parse '$location'");
return;
}
Expand Down
8 changes: 6 additions & 2 deletions t/openaddr.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use warnings;
use strict;
use Test::Most tests => 41;
use Test::Most tests => 43;
use Test::Number::Delta;
use Test::Carp;
use lib 't/lib';
Expand Down Expand Up @@ -99,9 +99,13 @@ OPENADDR: {
does_croak(sub {
$location = $geocoder->reverse_geocode();
});

does_carp(sub {
$geocoder = new_ok('Geo::Coder::Free' => [ openaddr => 'not/there' ]);
});
} else {
diag('Set OPENADDR_HOME to enable openaddresses.io testing');
skip 'OPENADDR_HOME not defined', 40;
skip 'OPENADDR_HOME not defined', 42;
}
}
}

0 comments on commit ea703ff

Please sign in to comment.