adjustments
authorMark Wells <mark@freeside.biz>
Sun, 30 Nov 2014 21:01:27 +0000 (13:01 -0800)
committerMark Wells <mark@freeside.biz>
Sun, 30 Nov 2014 21:01:27 +0000 (13:01 -0800)
Geocoding.pm
Geocoding/Match.pm
debian/rules
t/01-lookup.t

index c64c590..a7e5ba1 100644 (file)
@@ -19,7 +19,7 @@ Version 0.01
 =cut
 
 our $VERSION = '0.01';
-our $DEBUG = 1;
+our $DEBUG = 0;
 
 =head1 SYNOPSIS
 
@@ -34,6 +34,8 @@ our $DEBUG = 1;
       # optional fields
       benchmark => 'Public_AR_ACS2013', # default is "Public_AR_Current"
       vintage   => 'Census2010_ACS2013', # default is "Current_Current"
+
+      debug => 1,                   # will print the URL and some other info
     };
     my $result = Geo::USCensus::Geocoding->query($request);
 
@@ -62,8 +64,8 @@ my $api_uri = 'http://geocoding.geo.census.gov/geocoder/geographies/address';
 sub query {
   my $class = shift;
   my %opt = (
-    benchmark => 'Public_AR_Current',
-    vintage   => 'Current_Current',
+    benchmark => 'Public_AR_Census2010',
+    vintage   => 'Census2010_Census2010',
   );
   if (ref $_[0] eq 'HASH') {
     %opt = (%opt, %{ $_[0] });
@@ -71,6 +73,7 @@ sub query {
     %opt = (%opt, @_);
   }
 
+  $DEBUG = $opt{debug} || 0;
   $opt{format} = 'json';
 
   foreach (qw(street city state zip)) {
index 6584203..b4a7675 100644 (file)
@@ -1,6 +1,7 @@
 package Geo::USCensus::Geocoding::Match;
 
 use strict;
+use Data::Dumper;
 
 sub new {
   my $class = shift;
@@ -31,13 +32,23 @@ sub geographies {
   $self->{geographies};
 }
 
+sub block_info {
+  my $self = shift;
+  my $geo = $self->{geographies};
+  my $block_info = $geo->{'2010 Census Blocks'}; # XXX change this in 2020
+  if ($block_info and exists($block_info->[0])) {
+    return $block_info->[0];
+  } else {
+    warn "2010 Census Blocks element not found in response\n";
+    warn Dumper $self->{geographies};
+    return '';
+  }
+}
+
 sub censustract {
   my $self = shift;
-  return '' unless $self->geographies
-                and exists($self->geographies->{'Census Tracts'})
-                and exists($self->geographies->{'Census Tracts'}->[0]);
-  my $ct = $self->geographies->{'Census Tracts'}->[0];
-  return $ct->{STATE} . $ct->{COUNTY} . $ct->{TRACT};
+  my $block = $self->block_info or return '';
+  return $block->{STATE} . $block->{COUNTY} . $block->{TRACT};
 }
 
 1;
index 2d33f6a..eb511c7 100755 (executable)
@@ -2,3 +2,6 @@
 
 %:
        dh $@
+override_dh_auto_install:
+       dh_auto_install
+       rm -f `find debian/ -name perllocal.pod`
index 11c8b37..ad780e2 100644 (file)
@@ -6,7 +6,7 @@ use Geo::USCensus::Geocoding;
 
 diag( "Testing lookup of a known good address" );
 my $result = Geo::USCensus::Geocoding->query(
-  street  => '1526 H St', # the California Governor's Mansion
+  street  => '1400 J St', # the Sacramento Convention Center
   city    => 'Sacramento',
   state   => 'CA',
   zip     => '95814',