- $hash{house_number} = $location_hash->{number};
- $hash{house_number_suffix} = ''; # we don't support this, do we?
- $hash{prefix_directional} = $location_hash->{prefix};
- $hash{street_name} = $location_hash->{street};
- $hash{street_suffix} = $location_hash->{type};
- $hash{post_directional} = $location_hash->{suffix};
- $hash{community_name} = $location_hash->{city};
- $hash{state} = $location_hash->{state};
- if ($location_hash->{sec_unit_type}) {
- $hash{location} = $location_hash->{sec_unit_type} . ' ' .
- $location_hash->{sec_unit_num};
+ if ( length($address2) ) {
+ # be careful how we handle this
+ if ( !defined $location_hash ) {
+ # then it did successfully parse. BUT.
+ # if there's no sec_unit_type, then the address2 was parsed as part
+ # of the street name, which is wrong. Then reparse.
+ if ( !$location_hash->{sec_unit_type} ) {
+ undef $location_hash;
+ }
+ }
+ # then parsing failed. Try again without the address2.
+ $location_hash = Geo::StreetAddress::US->parse_address(
+ uc( join(', ',
+ $cust_location->address1,
+ $cust_location->city,
+ $cust_location->state,
+ $cust_location->zip
+ ) )
+ );
+ # this should not produce an address with sec_unit_type,
+ # so 'location' will be set to address2
+ }
+ if ( $location_hash ) {
+ # then store it
+ $hash{house_number} = $location_hash->{number};
+ $hash{house_number_suffix} = ''; # we don't support this, do we?
+ $hash{prefix_directional} = $location_hash->{prefix};
+ $hash{street_name} = $location_hash->{street};
+ $hash{community_name} = $location_hash->{city};
+ $hash{state} = $location_hash->{state};
+
+ if ($location_hash->{sec_unit_type}) {
+ $hash{location} = $location_hash->{sec_unit_type} . ' ' .
+ $location_hash->{sec_unit_num};
+ } else {
+ # if sec_unit_type was not set, then put address2 in 'location'
+ $hash{location} = $address2;
+ }
+
+ if ( $self->option('no_street_suffix') and $location_hash->{type} ) {
+ my $type = $location_hash->{type};
+ $hash{street_name} .= ' ' . uc($location_hash->{type});
+ } else {
+ $hash{street_suffix} = uc($location_hash->{type});
+ }
+
+ if ( $self->option('no_postdir') and $location_hash->{suffix} ) {
+ $hash{street_name} .= ' ' . $location_hash->{suffix};
+ } else {
+ $hash{post_directional} = $location_hash->{suffix};
+ }
+