blib/lib/Phone/Info.pm

filter: Statementstmt 6.0% 11 / 183 Branchbran 0.0% 0 / 82 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 100% 6 / 6 totaltotal 7.1% 20 / 280 CC 42 SCAR 55.0
CC
42
Cov
4%
resFormat
506.0
reverse_phone
56.0
find_person
42.0
CRAP 243.7
↑ Summary
1 package Phone::Info;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Net::WhitePages;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Phone::Info - Fetches phone info.
10  
11 =head1 VERSION
12  
13 Version 0.0.1
14  
15 =cut
16  
17 2 our $VERSION = '0.0.1';
18  
19  
20 =head1 SYNOPSIS
21  
22 Quick summary of what the module does.
23  
24 Perhaps a little code snippet.
25  
26 use Phone::Info;
27  
28 my $pi = Phone::Info->new();
29 ...
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 =head3 args hash
36  
37 =head4 token
38  
39 This is the API key to use. Get one at "http://www.whitepages.com/".
40  
41 If this is not defined $ENV{WHITEPAGESTOKEN} is used.
42  
43 =cut
44  
45 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
46 0 my %args;
47 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
48 0 %args= %{$_[1]};
49 }
50  
51 0 my $self={error=>undef, errorString=>''};
52 0 bless $self;
53  
54 #get the token
55 0 ▶ if (!defined($args{token})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'token'}) { } 0 0 0
56 0 ▶ if (!defined($ENV{WHITEPAGESTOKEN})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ENV{"WHITEPAGESTOKEN"}) 0 0 0
57 0 $self->{error}=1;
58 0 $self->{errorString}='$args{token} is not defined and $ENV{WHITEPAGESTOKEN} is also not defined';
59 0 warn('Phone-Info new:1: '.$self->{errorString});
60 0 return $self;
61 }
62 0 $self->{token}=$ENV{WHITEPAGESTOKEN};
63 }else {
64 0 $self->{token}=$args{token};
65 }
66  
67 #create the object
68 0 $self->{wp}=Net::WhitePages->new(TOKEN =>$self->{token});
69 0 ▶ if (!defined($self->{wp})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"wp"}) 0 0 0
70 0 $self->{error}=2;
71 0 $self->{errorString}='Failed to create the Net::WhitePages object';
72 0 warn('Phone-Info new:2: '.$self->{errorString});
73 0 return $self;
74 }
75  
76 0 return $self;
77 }
78  
79 =head2 find_person
80  
81 For a deeper understanding of values, check the URL below.
82  
83 http://developer.whitepages.com/docs/Methods/find_person
84  
85 =head3 args hash
86  
87 =head4 firstname
88  
89 The first name to search for.
90  
91 =head4 lastname
92  
93 The last name to search for.
94  
95 =head4 name
96  
97 The name to search for.
98  
99 =head4 house
100  
101 The house number.
102  
103 =head4 street
104  
105 The street name to search.
106  
107 =head4 city
108  
109 The city to search.
110  
111 =head4 state
112  
113 The 2 letter state to search.
114  
115 =head4 zip
116  
117 The 5 or 9 digit zip code.
118  
119 =head4 areacode
120  
121 The phone area code to search.
122  
123 =head4 metro
124  
125 A boolean value determining if the search should be expanded to the metro areas.
126  
127 my $res=$pi->find_person(\%args);
128 if($pi->{error}){
129 print "Error!\n";
130 }
131  
132 =cut
133  
134 0 ▶sub find_person{
Subroutine find_person: not called CC=6 SCAR=37.4
Pod documented
135 0 my $self=$_[0];
136 0 my %args;
137 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
138 0 %args= %{$_[1]};
139 }
140  
141 0 $self->errorblank;
142  
143 my $res = $self->{wp}->find_person(
144 firstname=>$args{firstname},
145 lastname=>$args{lastname},
146 house=>$args{house},
147 street=>$args{street},
148 city=>$args{city},
149 state=>$args{state},
150 zip=>$args{zip},
151 areacode=>$args{areacode},
152 metro=>$args{metro},
153 0 );
154  
155 0 ▶ if (!defined($res)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
156 0 $self->{error}=3;
157 0 $self->{errorString}='Net::WhitePages->find_person errored. $res is not defined';
158 0 warn('Phone-Info person:3: '.$self->{errorString});
159 0 return undef;
160 }
161  
162 0 ▶ if (!defined($res->{result})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}) 0 0 0
163 0 $self->{error}=3;
164 0 $self->{errorString}='Net::WhitePages->find_person errored. $res->{result} is not defined';
165 0 warn('Phone-Info person:3: '.$self->{errorString});
166 0 return undef;
167 }
168  
169 0 ▶ if (!defined($res->{result}{type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}{"type"}) 0 0 0
170 0 $self->{error}=3;
171 0 $self->{errorString}='Net::WhitePages->find_person errored. $res->{result}{type} is not defined';
172 0 warn('Phone-Info person:3: '.$self->{errorString});
173 0 return undef;
174 }
175  
176 0 ▶ if ($res->{result}{type} ne 'success') {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"result"}{"type"} ne "success") 0 0 0
177 0 $self->{error}=4;
178 0 $self->{errorString}='Look up errored. $res->{result}{type} is not defined';
179 0 warn('Phone-Info person:4: '.$self->{errorString});
180 0 return undef;
181 }
182  
183 0 return $res;
184 }
185  
186 =head2 resFormat
187  
188 Create a string from the results.
189  
190 =head3 args hash
191  
192 =head4 res
193  
194 This is the returned search data.
195  
196 =head4 format
197  
198 This is the format string for each item. See the format section
199 for more information on this.
200  
201 =head4 header
202  
203 The header that will be attached at the top.
204  
205 If this is not defined, it is created based on the format.
206  
207 For no header, set this to ''.
208  
209 This should also include a new line.
210  
211 =head4 quote
212  
213 If this is set to true, the fields will be quoted.
214  
215 This defaults to true.
216  
217 =head4 quotechar
218  
219 This is the character that should be used for quoting.
220  
221 The default is '"'.
222  
223 my $res=$pi->person(\%args);
224 if($pi->{error}){
225 print "Error!\n";
226 }
227 $pi->resFormat({
228 res=>$res,
229 format=>$format,
230 header=>$header,
231 seperator=>',',
232 quote=>1,
233 quotechar=>'"',
234 });
235 if($pi->{error}){
236 print "Error!\n";
237 }
238  
239 =cut
240  
241 0 ▶sub resFormat{
Subroutine resFormat: not called CC=22 SCAR=62.3
Pod documented
242 0 my $self=$_[0];
243 0 my %args;
244 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
245 0 %args= %{$_[1]};
246 }
247  
248 0 $self->errorblank;
249  
250 0 ▶ if (!defined($args{res})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"res"}) 0 0 0
251 0 $self->{error}=4;
252 0 $self->{errorString}='No search results passed';
253 0 warn('Phone-Info resFormat:4: '.$self->{errorString});
254 0 return undef;
255 }
256  
257 #the format to use for printing it out
258 0 ▶ if (!defined($args{format})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"format"}) 0 0 0
259 0 $args{format}='firstname,middlename,lastname,phone,house,street,city,state,zip';
260 }
261  
262 #if headers should be printed or not
263 0 ▶ if (!defined($args{header})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"header"}) 0 0 0
264 0 $args{header}=$args{format}."\n";
265 0 $args{header}=~s/\,/ \, /g;
266 }
267  
268 #what seperates the various fields
269 0 ▶ if (!defined($args{seperator})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"seperator"}) 0 0 0
270 0 $args{seperator}=" , ";
271 }
272  
273 #the character to use for quotes
274 0 ▶ if (!defined($args{quotechar})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"quotechar"}) 0 0 0
275 0 $args{quotechar}='"';
276 }
277  
278 #default to quoting
279 0 ▶ if (!defined($args{quote})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"quote"}) 0 0 0
280 0 $args{quote}=1;
281 }
282  
283 #the string that will be returned
284 0 my $toreturn=$args{header};
285  
286 0 my @format=split(/,/, $args{format});
287  
288 #put it together
289 0 my $int=0;
290 0 ▶ while (defined( $args{res}->{listings}[$int] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"res"}{"listings"}[$int]) 0 0 0
291 0 my $fint=0;
292  
293 #put the line together
294 0 ▶ while (defined( $format[$fint] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $format[$fint]) 0 0 0
295 0 my $data;
296 0 ▶ if ($format[$fint] eq 'firstname') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "firstname") 0 0 0
297 0 $data=$args{res}->{listings}[$int]{people}[0]{firstname};
298 }
299  
300 0 ▶ if ($format[$fint] eq 'middlename') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "middlename") 0 0 0
301 0 $data=$args{res}->{listings}[$int]{people}[0]{middlename};
302 }
303  
304 0 ▶ if ($format[$fint] eq 'lastname') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "lastname") 0 0 0
305 0 $data=$args{res}->{listings}[$int]{people}[0]{lastname};
306 }
307  
308 0 ▶ if ($format[$fint] eq 'phone') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "phone") 0 0 0
309 0 $data=$args{res}->{listings}[$int]{phonenumbers}[0]{fullphone};
310 }
311  
312 0 ▶ if ($format[$fint] eq 'house') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "house") 0 0 0
313 0 $data=$args{res}->{listings}[$int]{address}{house};
314 }
315  
316 0 ▶ if ($format[$fint] eq 'street') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "street") 0 0 0
317 0 $data=$args{res}->{listings}[$int]{address}{street};
318 }
319  
320 0 ▶ if ($format[$fint] eq 'city') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "city") 0 0 0
321 0 $data=$args{res}->{listings}[$int]{address}{city};
322 }
323  
324 0 ▶ if ($format[$fint] eq 'state') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "state") 0 0 0
325 0 $data=$args{res}->{listings}[$int]{address}{state};
326 }
327  
328 0 ▶ if ($format[$fint] eq 'zip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format[$fint] eq "zip") 0 0 0
329 0 $data=$args{res}->{listings}[$int]{address}{zip};
330 }
331  
332 0 ▶ if (!defined($data)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 0 0
333 0 $data='';
334 }
335  
336 0 ▶ if ($args{quote}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"quote"}) 0 0 0
337 0 $data=$args{quotechar}.$data.$args{quotechar};
338 }
339  
340 #append the data to what is to be returned
341 0 $toreturn=$toreturn.$data;
342  
343 #if it is at the end, don't append the seperator
344 0 ▶ if ($fint ne $#format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fint ne $#format) 0 0 0
345 0 $toreturn=$toreturn.$args{seperator};
346 }
347  
348 0 $fint++;
349 }
350  
351 #stick a new line on before starting another line
352 0 $toreturn=$toreturn."\n";
353  
354 0 $int++;
355 }
356  
357 0 return $toreturn;
358 }
359  
360 =head2 reverse_address
361  
362 This finds related phone number based on their address.
363  
364 See the link below for more information.
365  
366 http://developer.whitepages.com/docs/Methods/reverse_address
367  
368 =head3 args hash
369  
370 =head4 apt
371  
372 The apt to search for.
373  
374 =head4 house
375  
376 The house number searched to search for. This can be
377 number take a range, "100-200".
378  
379 =head4 city
380  
381 The city to search.
382  
383 =head4 state
384  
385 The state to search.
386  
387 =head4 zip
388  
389 The sip code to search.
390  
391 =head4 areacode
392  
393 This is the area code to search.
394  
395 my $res=$pi->reverse_address(\%args);
396 if($pi->{error}){
397 print "Error!\n";
398 }
399  
400 =cut
401  
402 0 ▶sub reverse_address{
Subroutine reverse_address: not called CC=6 SCAR=37.4
Pod documented
403 0 my $self=$_[0];
404 0 my %args;
405 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
406 0 %args= %{$_[1]};
407 }
408  
409 0 $self->errorblank;
410  
411 my $res = $self->{wp}->reverse_address(
412 apt=>$args{apt},
413 house=>$args{house},
414 city=>$args{city},
415 state=>$args{state},
416 zip=>$args{zip},
417 areacode=>$args{areacode},
418 street=>$args{street}
419 0 );
420  
421 0 ▶ if (!defined($res)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
422 0 $self->{error}=3;
423 0 $self->{errorString}='Net::WhitePages->reverse_address errored. $res is not defined';
424 0 warn('Phone-Info reverse_address:3: '.$self->{errorString});
425 0 return undef;
426 }
427  
428 0 ▶ if (!defined($res->{result})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}) 0 0 0
429 0 $self->{error}=3;
430 0 $self->{errorString}='Net::WhitePages->find_address errored. $res->{result} is not defined';
431 0 warn('Phone-Info reverse_address:3: '.$self->{errorString});
432 0 return undef;
433 }
434  
435 0 ▶ if (!defined($res->{result}{type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}{"type"}) 0 0 0
436 0 $self->{error}=3;
437 0 $self->{errorString}='Net::WhitePages->find_address errored. $res->{result}{type} is not defined';
438 0 warn('Phone-Info reverse_address:3: '.$self->{errorString});
439 0 return undef;
440 }
441  
442 0 ▶ if ($res->{result}{type} ne 'success') {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"result"}{"type"} ne "success") 0 0 0
443 0 $self->{error}=4;
444 0 $self->{errorString}='Look up errored. $res->{result}{type} is not defined';
445 0 warn('Phone-Info reverse_address:4: '.$self->{errorString});
446 0 return undef;
447 }
448  
449 0 return $res;
450 }
451  
452 =head2 reverse_phone
453  
454 This finds related addresses based on a phone number.
455  
456 See the link below for more information.
457  
458 http://developer.whitepages.com/docs/Methods/reverse_phone
459  
460 =head3 args hash
461  
462 =head4 phone
463  
464 This is the phone number to look up.
465  
466 my $res=$pi->reverse_phone(\%args);
467 if($pi->{error}){
468 print "Error!\n";
469 }
470  
471 =cut
472  
473 0 ▶sub reverse_phone{
Subroutine reverse_phone: not called CC=7 SCAR=40.3
Pod documented
474 0 my $self=$_[0];
475 0 my %args;
476 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
477 0 %args= %{$_[1]};
478 }
479  
480 0 $self->errorblank;
481  
482 0 ▶ if (!defined($args{phone})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"phone"}) 0 0 0
483 0 $self->{error}=5;
484 0 $self->{errorString}='No phone number specified. Please define $args{phone}';
485 0 warn('Phone-Info reverse_phone:5: '.$self->{errorString});
486 0 return undef;
487 }
488  
489 my $res = $self->{wp}->reverse_phone(
490 phone=>$args{phone},
491 0 );
492
493 0 ▶ if (!defined($res)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
494 0 $self->{error}=3;
495 0 $self->{errorString}='Net::WhitePages->reverse_phone errored. $res is not defined';
496 0 warn('Phone-Info reverse_phone:3: '.$self->{errorString});
497 0 return undef;
498 }
499  
500 0 ▶ if (!defined($res->{result})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}) 0 0 0
501 0 $self->{error}=3;
502 0 $self->{errorString}='Net::WhitePages->reverse_phone errored. $res->{result} is not defined';
503 0 warn('Phone-Info reverse_phone:3: '.$self->{errorString});
504 0 return undef;
505 }
506  
507 0 ▶ if (!defined($res->{result}{type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res->{"result"}{"type"}) 0 0 0
508 0 $self->{error}=3;
509 0 $self->{errorString}='Net::WhitePages->reverse_phone errored. $res->{result}{type} is not defined';
510 0 warn('Phone-Info reverse_phone:3: '.$self->{errorString});
511 0 return undef;
512 }
513  
514 0 ▶ if ($res->{result}{type} ne 'success') {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"result"}{"type"} ne "success") 0 0 0
515 0 $self->{error}=4;
516 0 $self->{errorString}='Look up errored. $res->{result}{type} is not defined';
517 0 warn('Phone-Info reverse_phone:4: '.$self->{errorString});
518 0 return undef;
519 }
520  
521 0 return $res;
522 }
523  
524 =head2 errorblank
525  
526 This blanks the error storage and is only meant for internal usage.
527  
528 It does the following.
529  
530 $self->{error}=undef;
531 $self->{errorString}="";
532  
533 =cut
534  
535 #blanks the error flags
536 0 ▶sub errorblank{
Subroutine errorblank: not called CC=1 SCAR=6.9
Pod documented
537 0 my $self=$_[0];
538  
539 0 $self->{error}=undef;
540 0 $self->{errorString}="";
541  
542 0 return 1;
543 }
544  
545 =head1 ERROR CODES
546  
547 =head2 1
548  
549 $args{token} is not defined and $ENV{WHITEPAGESTOKEN} is also not defined.
550  
551 =head2 2
552  
553 Failed to create the Net::WhitePages object.
554  
555 =head2 3
556  
557 find_person errored.
558  
559 =head2 4
560  
561 No search results passed.
562  
563 =head2 5
564  
565 No phone number specified.
566  
567 =head1 FORMAT STRING
568  
569 This is a comma seperated string comprised of various items listed below.
570  
571 This string sould not include any spaces or etc.
572  
573 =head2 firstname
574  
575 The first name of the first person found listed for the number.
576  
577 =head2 middlename
578  
579 The middle name for the first person found listed for the number.
580  
581 =head2 lastname
582  
583 The last name for the first person found listed for the number.
584  
585 =head2 phone
586  
587 The phone number.
588  
589 =head2 house
590  
591 The house number for the address.
592  
593 =head2 street
594  
595 The street for the address.
596  
597 =head2 city
598  
599 The city the address is in.
600  
601 =head2 state
602  
603 The state the address is in.
604  
605 =head2 zip
606  
607 The zip code for the address.
608  
609 =head1 AUTHOR
610  
611 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
612  
613 =head1 BUGS
614  
615 Please report any bugs or feature requests to C<bug-phone-info at rt.cpan.org>, or through
616 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Phone-Info>. I will be notified, and then you'll
617 automatically be notified of progress on your bug as I make changes.
618  
619  
620  
621  
622 =head1 SUPPORT
623  
624 You can find documentation for this module with the perldoc command.
625  
626 perldoc Phone::Info
627  
628  
629 You can also look for information at:
630  
631 =over 4
632  
633 =item * RT: CPAN's request tracker
634  
635 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Phone-Info>
636  
637 =item * AnnoCPAN: Annotated CPAN documentation
638  
639 L<http://annocpan.org/dist/Phone-Info>
640  
641 =item * CPAN Ratings
642  
643 L<http://cpanratings.perl.org/d/Phone-Info>
644  
645 =item * Search CPAN
646  
647 L<http://search.cpan.org/dist/Phone-Info/>
648  
649 =back
650  
651  
652 =head1 ACKNOWLEDGEMENTS
653  
654  
655 =head1 COPYRIGHT & LICENSE
656  
657 Copyright 2009 Zane C. Bowers, all rights reserved.
658  
659 This program is free software; you can redistribute it and/or modify it
660 under the same terms as Perl itself.
661  
662  
663 =cut
664  
665 2 1; # End of Phone::Info
↑ Summary