| 1 | package Net::WhitePages; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | $VERSION = '1.05'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::Simple qw($ua get); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Params::Validate qw(validate); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant API_BASE => 'http://api.whitepages.com'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Constructor -- simply stores everything given to it | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | my $args = @_ && ref($_[0]) eq 'HASH' ? shift : { @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | $ua->agent("$class/$VERSION (" . $ua->agent . ")"); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | bless { | ||||||||||||||||||||||||||||
| 22 | DEBUG => 0, | ||||||||||||||||||||||||||||
| 23 | 1 | TOKEN => $ENV{'WHITEPAGES_TOKEN'}, | |||||||||||||||||||||||||||
| 24 | API_VERSION => '1.0', | ||||||||||||||||||||||||||||
| 25 | %$args, | ||||||||||||||||||||||||||||
| 26 | } => $class; | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 30 | # find_person() | ||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||
| 32 | # http://developer.whitepages.com/docs/Methods/find_person | ||||||||||||||||||||||||||||
| 33 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub find_person { | ||||||||||||||||||||||||||
|
Subroutine
find_person: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 0 | return $self->_request( | |||||||||||||||||||||||||||
| 37 | validate(@_, { | ||||||||||||||||||||||||||||
| 38 | 'firstname' => 0, | ||||||||||||||||||||||||||||
| 39 | 'lastname' => 1, | ||||||||||||||||||||||||||||
| 40 | 'house' => 0, | ||||||||||||||||||||||||||||
| 41 | 'street' => 0, | ||||||||||||||||||||||||||||
| 42 | 'city' => 0, | ||||||||||||||||||||||||||||
| 43 | 'state' => 0, | ||||||||||||||||||||||||||||
| 44 | 'zip' => 0, | ||||||||||||||||||||||||||||
| 45 | 'areacode' => 0, | ||||||||||||||||||||||||||||
| 46 | 'metro' => 0, | ||||||||||||||||||||||||||||
| 47 | }) | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 52 | # reverse_phone | ||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||
| 54 | # http://developer.whitepages.com/docs/Methods/reverse_phone | ||||||||||||||||||||||||||||
| 55 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub reverse_phone { | ||||||||||||||||||||||||||
|
Subroutine
reverse_phone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 0 | return $self->_request( | |||||||||||||||||||||||||||
| 59 | validate(@_, { | ||||||||||||||||||||||||||||
| 60 | 'phone' => 1, | ||||||||||||||||||||||||||||
| 61 | 'state' => 0, | ||||||||||||||||||||||||||||
| 62 | }), | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 67 | # reverse_address | ||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||
| 69 | # http://developer.whitepages.com/docs/Methods/reverse_address | ||||||||||||||||||||||||||||
| 70 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub reverse_address { | ||||||||||||||||||||||||||
|
Subroutine
reverse_address: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | 0 | return $self->_request( | |||||||||||||||||||||||||||
| 74 | validate(@_, { | ||||||||||||||||||||||||||||
| 75 | 'house' => 0, | ||||||||||||||||||||||||||||
| 76 | 'apt' => 0, | ||||||||||||||||||||||||||||
| 77 | 'street' => 1, | ||||||||||||||||||||||||||||
| 78 | 'city' => 0, | ||||||||||||||||||||||||||||
| 79 | 'state' => 0, | ||||||||||||||||||||||||||||
| 80 | 'zip' => 0, | ||||||||||||||||||||||||||||
| 81 | 'areacode' => 0, | ||||||||||||||||||||||||||||
| 82 | }), | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Make the URI | ||||||||||||||||||||||||||||
| 87 | # Takes API_BASE, $self->{ API_VERSION }, and caller | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub _uri { | ||||||||||||||||||||||||||
|
Subroutine
_uri: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 0 | my $meth = shift; | |||||||||||||||||||||||||||
| 91 | 0 | my %p = @_; | |||||||||||||||||||||||||||
| 92 | 0 | my $uri = URI->new(API_BASE . '/' . $meth . '/' . $self->{ API_VERSION }); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | my $t = $self->{ TOKEN } || | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | die "No token defined; can't make a request without a token!\n"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'TOKEN'} || die("No token defined; can't make a request without a token!\n")
MC/DC0%0/1
$self->{'TOKEN'} || die("No token defined; can't make a request without a token!\n")
$self->{'TOKEN'}
Truth table0%0/2
A
A= $self->{'TOKEN'}
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | $p{'api_key'} = $t; | |||||||||||||||||||||||||||
| 98 | 0 | $p{'outputtype'} = 'Perl'; | |||||||||||||||||||||||||||
| 99 | 0 | $uri->query_form(%p); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | return $uri; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Do the actual request against the whitepages.com server | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | 0 | my @meth = caller(1); | |||||||||||||||||||||||||||
| 108 | 0 | (my $meth = $meth[3]) =~ s/.*:://; | |||||||||||||||||||||||||||
| 109 | 0 | my $uri = $self->_uri($meth, @_); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($self->{ DEBUG }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | warn "[DEBUG] Calling `", $uri->canonical, "'\n"; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $data = get($uri->canonical); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return eval($data); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||