From: Mark Wells Date: Wed, 4 Mar 2015 21:15:22 +0000 (-0800) Subject: allow omitting state/city or zip X-Git-Url: http://git.freeside.biz/gitweb/?p=Geo-USCensus-Geocoding.git;a=commitdiff_plain;h=c349113913af257d59ac7c59296a41a0a0b51f28 allow omitting state/city or zip --- 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);