File Coverage

blib/lib/Geo/Demo/Zipskinny.pm
Criterion Covered Total %
statement 78 78 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 3 0.0
total 84 88 95.4


line stmt bran cond sub pod time code
1             package Geo::Demo::Zipskinny;
2              
3 1     1   20562 use strict;
  1         3  
  1         43  
4 1     1   850 use LWP::Simple qw();
  1         122741  
  1         2639  
5              
6             our $VERSION = 0.01;
7              
8             sub new {
9 1     1 0 13 my ( $class, %arg ) = @_;
10 1         8 return bless {}, $class;
11             }
12              
13             sub get {
14 1     1 0 2 my ( $self, $zip ) = @_;
15 1 50       5 return undef unless $zip =~ m/^\d{5}$/;
16 1         8 my $content = LWP::Simple::get(qq(http://www.zipskinny.com/index.php?zip=$zip));
17              
18 1         720463 return $self->parse( $content );
19             }
20              
21             sub parse {
22 2     2 0 5 my ( $self, $content ) = @_;
23 2         5 my %res = ();
24              
25             #yeah, it's crap, but it worked when i wrote it. stop complaining.
26              
27 2         14 $content =~ m#"Demographic profile for ZIP Code \d{5} in (.+?), (\w{2})\."#;
28 2         10 $res{'general'}{'city'} = $1;
29 2         7 $res{'general'}{'state'} = $2;
30              
31 2         30 my ( $general ) = $content =~ m#General Information(.+?)
#s; 32 2         12 ( $res{'general'}{'latitude'} ) = $general =~ m#Latitude.+?>([\-\d\.]+)<#; 33 2         14 ( $res{'general'}{'longitude'} ) = $general =~ m#Longitude.+?>([\-\d\.]+)<#; 34 2         12 ( $res{'general'}{'population'} ) = $general =~ m#Population.+?>(\d+)<#; 35 2         13 ( $res{'general'}{'density'} ) = $general =~ m#Density.+?>([\d\.]+)<#; 36 2         11 ( $res{'general'}{'housing'} ) = $general =~ m#Housing Units.+?>(\d+)<#; 37 2         16 ( $res{'general'}{'land_area'} ) = $general =~ m#Land Area.+?>([\d\.]+) sq\. mi\.<#; 38 2         14 ( $res{'general'}{'water_area'} ) = $general =~ m#Water Area.+?>([\d\.]+) sq\. mi\.<#; 39               40 2         58 my ( $social ) = $content =~ m#Social Indicators(.+?)#s; 41 2         29 ( $res{'educational'}{'0-8'} ) = $social =~ m#Less than 9th grade.+?>([\d\.]+)%#; 42 2         26 ( $res{'educational'}{'9-12'} ) = $social =~ m#9th-12th grade.+?>([\d\.]+)%#; 43 2         59 ( $res{'educational'}{'High school graduate'} ) = $social =~ m#High school graduate.+?>([\d\.]+)%#; 44 2         23 ( $res{'educational'}{'Some college'} ) = $social =~ m#Some college.+?>([\d\.]+)%#; 45 2         23 ( $res{'educational'}{'Associate degree'} ) = $social =~ m#Associate.+?>([\d\.]+)%#; 46 2         27 ( $res{'educational'}{'Bachelors degree'} ) = $social =~ m#Bachelors.+?>([\d\.]+)%#; 47 2         22 ( $res{'educational'}{'Graduate/Professional'} ) = $social =~ m#Graduate/Professional.+?>([\d\.]+)%#; 48               49 2         31 ( $res{'marital'}{'Never married'} ) = $social =~ m#Never married.+?>([\d\.]+)%#; 50 2         28 ( $res{'marital'}{'Married'} ) = $social =~ m#Married.+?>([\d\.]+)%#; 51 2         27 ( $res{'marital'}{'Separated'} ) = $social =~ m#Separated.+?>([\d\.]+)%#; 52 2         25 ( $res{'marital'}{'Widowed'} ) = $social =~ m#Widowed.+?>([\d\.]+)%#; 53 2         21 ( $res{'marital'}{'Divorced'} ) = $social =~ m#Divorced.+?>([\d\.]+)%#; 54               55 2         18 ( $res{'stability'}{'Same home 5+ years'} ) = $social =~ m#Same home.+?>([\d\.]+)%#; 56               57 2         46 my ( $eco ) = $content =~ m#Economic Indicators(.+?)#s; 58 2         43 ( $res{'income'}{'000000-009999'} ) = $eco =~ m#<\$10,000.+?> ([\d\.]+)%#; 59 2         30 ( $res{'income'}{'010000-014999'} ) = $eco =~ m#\$10,000-.+?> ([\d\.]+)%#; 60 2         22 ( $res{'income'}{'015000-024999'} ) = $eco =~ m#\$15,000-.+?> ([\d\.]+)%#; 61 2         21 ( $res{'income'}{'025000-034999'} ) = $eco =~ m#\$25,000-.+?> ([\d\.]+)%#; 62 2         21 ( $res{'income'}{'035000-049999'} ) = $eco =~ m#\$35,000-.+?> ([\d\.]+)%#; 63 2         19 ( $res{'income'}{'050000-074999'} ) = $eco =~ m#\$50,000-.+?> ([\d\.]+)%#; 64 2         21 ( $res{'income'}{'075000-099999'} ) = $eco =~ m#\$75,000-.+?> ([\d\.]+)%#; 65 2         20 ( $res{'income'}{'100000-149999'} ) = $eco =~ m#\$100,000-.+?> ([\d\.]+)%#; 66 2         16 ( $res{'income'}{'150000-199999'} ) = $eco =~ m#\$150,000-.+?> ([\d\.]+)%#; 67 2         18 ( $res{'income'}{'200000+'} ) = $eco =~ m#\$200,000\+.+?> ([\d\.]+)%#; 68               69 2         27 ( $res{'occupation'}{'Professional'} ) = $eco =~ m#Mgt\./Professional.+?> ([\d\.]+)%#; 70 2         26 ( $res{'occupation'}{'Service'} ) = $eco =~ m#Service.+?> ([\d\.]+)%#; 71 2         26 ( $res{'occupation'}{'Sales/Office'} ) = $eco =~ m#Sales/Office.+?> ([\d\.]+)%#; 72 2         22 ( $res{'occupation'}{'Agriculture'} ) = $eco =~ m#Farm/Fishing.+?> ([\d\.]+)%#; 73 2         22 ( $res{'occupation'}{'Construction/Extraction'} ) = $eco =~ m#Construction.+?> ([\d\.]+)%#; 74 2         20 ( $res{'occupation'}{'Production/Transportation'} ) = $eco =~ m#Production.+?> ([\d\.]+)%#; 75               76 2         15 ( $res{'occupation'}{'unemployed'} ) = $eco =~ m#Unemployed.+?> ([\d\.]+)%#; 77 2         15 ( $res{'income'}{'below poverty line'} ) = $eco =~ m#Below Poverty Line.+?> ([\d\.]+)%#; 78               79 2         85 my ( $demo ) = $content =~ m#>Race<(.+?)#s; 80 2         23 ( $res{'race'}{'Hispanic'} ) = $demo =~ m#Hispanic/Latino.+?>([\d\.]+)%#; 81 2         16 ( $res{'race'}{'White'} ) = $demo =~ m#White.+?>([\d\.]+)%#; 82 2         14 ( $res{'race'}{'Black'} ) = $demo =~ m#Black.+?>([\d\.]+)%#; 83 2         13 ( $res{'race'}{'Native American'} ) = $demo =~ m#Native.+?>([\d\.]+)%#; 84 2         11 ( $res{'race'}{'Asian'} ) = $demo =~ m#Asian.+?>([\d\.]+)%#; 85 2         11 ( $res{'race'}{'Pacific Islander'} ) = $demo =~ m#Islander.+?>([\d\.]+)%#; 86 2         13 ( $res{'race'}{'Other'} ) = $demo =~ m#Other.+?>([\d\.]+)%#; 87 2         12 ( $res{'race'}{'Multiracial'} ) = $demo =~ m#Multiracial.+?>([\d\.]+)%#; 88               89               90 2         115 my ( $age ) = $content =~ m#>Age<(.+?)#s; 91 2         32 ( $res{'age'}{'male'}{'0-9'} , $res{'age'}{'female'}{'0-9'} ) = $age =~ m#>0-9 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 92 2         19 ( $res{'age'}{'male'}{'10-19'}, $res{'age'}{'female'}{'10-19'} ) = $age =~ m#>10-19 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 93 2         17 ( $res{'age'}{'male'}{'20-29'}, $res{'age'}{'female'}{'20-29'} ) = $age =~ m#>20-29 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 94 2         15 ( $res{'age'}{'male'}{'30-39'}, $res{'age'}{'female'}{'30-39'} ) = $age =~ m#>30-39 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 95 2         16 ( $res{'age'}{'male'}{'40-49'}, $res{'age'}{'female'}{'40-49'} ) = $age =~ m#>40-49 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 96 2         19 ( $res{'age'}{'male'}{'50-59'}, $res{'age'}{'female'}{'50-59'} ) = $age =~ m#>50-59 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 97 2         24 ( $res{'age'}{'male'}{'60-69'}, $res{'age'}{'female'}{'60-69'} ) = $age =~ m#>60-69 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 98 2         20 ( $res{'age'}{'male'}{'70-79'}, $res{'age'}{'female'}{'70-79'} ) = $age =~ m#>70-79 years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 99 2         22 ( $res{'age'}{'male'}{'80+'} , $res{'age'}{'female'}{'80+'} ) = $age =~ m#>80\+ years.+?%.+?>([\d\.]+)%.+?%.+?>([\d\.]+)%#; 100               101 2         17 return \%res; 102             } 103               104             1; 105             __END__