diff options
author | Mark Wells <mark@freeside.biz> | 2015-03-04 13:15:22 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-03-04 13:15:22 -0800 |
commit | c349113913af257d59ac7c59296a41a0a0b51f28 (patch) | |
tree | 703f880c875076b9806dcd3b522789b7e823d47a | |
parent | c16e8ca7ab01db1321d407a8eba212440b0c97c9 (diff) |
allow omitting state/city or zip
-rw-r--r-- | Geocoding.pm | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Geocoding.pm b/Geocoding.pm index 04605ad..b1f3ea7 100644 --- a/Geocoding.pm +++ b/Geocoding.pm @@ -29,9 +29,9 @@ our $DEBUG = 0; # required fields street => '123 Main Street', city => 'San Francisco', # city - state => 'CA', # state/province - zip => '93102', # zip/postal code + state => 'CA', # state # optional fields + zip => '93102', # zip code benchmark => 'Public_AR_ACS2013', # default is "Public_AR_Current" vintage => 'Census2010_ACS2013', # default is "Current_Current" @@ -89,12 +89,16 @@ sub query { my @row = ( 1 ); # first element = row identifier # at some point support multiple rows in a single query? + if (!$opt{street}) { + $result->error_message("Street address is required."); + return $result; + } + if (!$opt{zip} and (!$opt{city} or !$opt{state})) { + $result->error_message("Either city/state or zip code is required."); + return $result; + } foreach (qw(street city state zip)) { - if (!length($opt{$_})) { - $result->error_message("$_ required"); - return $result; - } - push @row, $opt{$_}; + push @row, $opt{$_} || ''; } $csv->combine(@row); |