Skip to content

Commit

Permalink
Croak when input is just a set of numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Jan 3, 2025
1 parent 71cfa5d commit eb4495e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Revision history for Geo-Coder-Free
0.38
Latest as_string return code and Utils.pm from VWF
Added t/config.t, t/utils.t and t/display.t
Croak when input is just a set of numbers

0.37 Wed Oct 23 10:09:54 EDT 2024
Allow new() to take HASH ref
Expand Down
15 changes: 14 additions & 1 deletion lib/Geo/Coder/Free.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Geo::Coder::Free;
# TODO: Don't have Maxmind as a separate database
# TODO: Rename openaddresses.sql as geo_coder_free.sql
# TODO: Consider Data::Dumper::Names instead of Data::Dumper
# TODO: use the cache to store common queries

use strict;
use warnings;
Expand Down Expand Up @@ -56,7 +57,9 @@ sub _normalize($);
=head1 DESCRIPTION
Geo::Coder::Free provides an interface to free databases by acting as a front-end to
Geo::Coder::Free provides an interface
to translate addresses into latitude and longitude
by using to free databases such as
L<Geo::Coder::Free::MaxMind> and L<Geo::Coder::Free::OpenAddresses>.
The cgi-bin directory contains a simple DIY Geo-Coding website.
Expand All @@ -68,6 +71,8 @@ When it's back up you will be able to use this to test it.
curl 'https://geocode.nigelhorne.com/cgi-bin/page.fcgi?page=query&q=1600+Pennsylvania+Avenue+NW+Washington+DC+USA'
Includes functionality for running the module via the command line for testing or ad-hoc geocoding tasks.
=head1 METHODS
=head2 new
Expand Down Expand Up @@ -209,6 +214,12 @@ sub geocode {
$params{'location'} = shift;
}

# Fail when the input is just a set of numbers
if($params{'location'} !~ /D/) {
Carp::croak('Usage: ', __PACKAGE__, ": invalid input to geocode(), $params{location}");
return;
}

if($self->{'openaddr'}) {
if(wantarray) {
my @rc = $self->{'openaddr'}->geocode(\%params);
Expand Down Expand Up @@ -525,6 +536,8 @@ The OpenAddresses data doesn't cover the globe.
Can't parse and handle "London, England".
It would be great to have a set-up wizard to create the database.
The various scripts in NJH-Snippets ought to be in this module.
=head1 SEE ALSO
Expand Down
14 changes: 10 additions & 4 deletions lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ This process will take some time.
$geocoder = Geo::Coder::Free::OpenAddresses->new(openaddr => $ENV{'OPENADDR_HOME'});
Takes an optional parameter directory, which is the directory of the file
Takes an optional parameter "openaddr", which is the directory of the file
openaddresses.sql.
Takes an optional parameter cache, which points to an object that understands get() and set() messages to store data in
Expand All @@ -104,11 +104,11 @@ sub new {
return unless($class);

if(my $openaddr = $param{'openaddr'}) {
Carp::croak("Can't find the directory $openaddr")
Carp::croak(__PACKAGE__, ": Can't find the directory $openaddr")
if((!-d $openaddr) || (!-r $openaddr));
return bless { openaddr => $openaddr, cache => $param{'cache'} }, $class;
}
Carp::croak(__PACKAGE__, ": usage: new(openaddr => '/path/to/openaddresses')");
Carp::croak(__PACKAGE__, ": Usage: new(openaddr => '/path/to/openaddresses')");
}

=head2 geocode
Expand Down Expand Up @@ -1013,13 +1013,19 @@ data from both sources.
The database shouldn't be called $OPENADDR_HOME/openaddresses.sql,
since the datbase now also includes data from WhosOnFirst.
The name openaddresses.sql shouldn't be hardcoded,
add support to "new" for the parameter "dbname".
The argument "openaddr",
would be less confusing if it were called "directory",
=head1 SEE ALSO
VWF, openaddresses.
=head1 LICENSE AND COPYRIGHT
Copyright 2017-2023 Nigel Horne.
Copyright 2017-2025 Nigel Horne.
The program code is released under the following licence: GPL for personal use on a single computer.
All other users (including Commercial, Charity, Educational, Government)
Expand Down

0 comments on commit eb4495e

Please sign in to comment.