blib/lib/WWW/WhoCallsMe.pm

filter: Statementstmt 23.2% 10 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 25.8% 15 / 58 CC 6 SCAR 32.5
CC
6
Cov
20%
fetch
42.0
new
2.0
BEGIN
1.0
CRAP 25.7
↑ Summary
1 package WWW::WhoCallsMe;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.02';
8  
9 =head1 NAME
10  
11 WWW::WhoCallsMe - Query WhoCallsMe.com for details about a caller's phone number
12  
13 =head1 SYNOPSIS
14  
15 use WWW::WhoCallsMe;
16 my $who = WWW::WhoCallsMe->new;
17  
18 my $number = '6305053008';
19 my $calledme = $who->fetch($number);
20 if ($calledme->{listed})
21 {
22 my $name = $calledme->{name};
23 print "The number $number is listed. ";
24 print "It seems that $name was calling." if $name;
25 print "I don't know who was calling, though." unless $name;
26 print "\n";
27 }
28 else
29 {
30 print "This number is not listed.\n";
31 }
32  
33 =head1 DESCRIPTION
34  
35 WhoCallsMe.com is a website that compiles reports from users about
36 companies that call people. These callers might be telemarketers,
37 bill collectors, legit companies, or otherwise. These reports are
38 filed by the person that received the call. In some cases, the
39 report includes the name of the company that called. This module
40 attempts to grab this information and report it back to your program.
41  
42 You supply the phone number and it tells you if the number is listed,
43 what names have been reported for this number, and a guess at the
44 company name of the caller.
45  
46 =head2 new
47  
48 my $who = WWW::WhoCallsMe->new;
49  
50 Accepts no parameters.
51  
52 Returns a new WWW::WhoCallsMe object for your enjoyment.
53  
54 =cut
55  
56 sub new
57 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
58 0 my $class = shift;
59 0 my $self = shift;
60  
61 0 $self->{ua} = LWP::UserAgent->new;
62 0 $self->{ua}->agent("WWW::WhoCallsMe/$VERSION");
63  
64 0 return bless($self, $class);
65 }
66  
67 =head2 fetch
68  
69 my $hashref = $who->fetch($number);
70  
71 Accepts one I<required> argument: the phone number.
72  
73 Returns a hashref containing this information:
74  
75 =over
76  
77 =item *
78  
79 number - scalar: the number that was queried
80  
81 =item *
82  
83 success - scalar: whether or not the HTTP query succeeded
84  
85 =item *
86  
87 listed - scalar: determines if the number is listed
88  
89 =item *
90  
91 name - scalar: the guessed name of the caller (based on frequency of occurrences in the callername array)
92  
93 =item *
94  
95 callername - array: list of reported caller names (the "Caller:" field)
96  
97 =item *
98  
99 callerid - array: list of reported caller id values (the "Caller ID:" field)
100  
101 =back
102  
103 =cut
104  
105 sub fetch
106 0 ▶{
Subroutine fetch: not called CC=6 SCAR=37.4
Pod documented
107 0 my $self = shift;
108 0 my $number = shift;
109 0 $number =~ s/[^0-9]//g;
110  
111 0 my $req = HTTP::Request->new(GET => 'http://whocallsme.com/Phone-Number.aspx/'.$number);
112 0 my $res = $self->{ua}->request($req);
113  
114 0 my $return = {
115 number => $number,
116 };
117  
118 0 my $content = $res->content;
119 0 ▶ $return->{success} = ($res->is_success ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$res->is_success ? : 0 0 0
120 0 ▶ $return->{listed} = (($content =~ m#\s+phone\s+number\s+comments:</h4>#i) ? 1 : 0); # no comments means no listing
Branch: 1 branch
BranchTrueFalseTotal
$content =~ m[\s+phone\s+number\s+comments:</h4>]i ? : 0 0 0
121 0 @{$return->{callername}} = $content =~ m#<div>Caller:\s*(.*?)\s*</div>#ig;
122 0 @{$return->{callerid}} = $content =~ m#<div>Caller\s+ID:\s*(.*?)\s*</div>#ig;
123  
124 0 my $callernames = {};
125 0 my $maxcallercount = 0;
126 0 my $maxcallername = 'unknown';
127 0 foreach my $callername (@{$return->{callername}})
128 {
129 0 $callername =~ s/[\?\'\s]+/ /g;
130 0 $callername =~ s/^\s+//;
131 0 $callername =~ s/\s+$//;
132 0 ▶ next unless $callername;
Branch: 1 branch
BranchTrueFalseTotal
unless $callername 0 0 0
133  
134 0 $callernames->{uc($callername)}++;
135 0 ▶ if ($callernames->{uc($callername)} > $maxcallercount)
Branch: 1 branch
BranchTrueFalseTotal
if ($$callernames{uc $callername} > $maxcallercount) 0 0 0
136 {
137 0 $maxcallercount = $callernames->{uc($callername)};
138 0 $maxcallername = uc($callername);
139 }
140 }
141  
142 0 $return->{name} = $maxcallername;
143  
144 0 return $return;
145 }
146  
147 =head1 DEPENDENCIES
148  
149 L<LWP>
150  
151 =head1 SEE ALSO
152  
153 L<http://www.whocallsme.com/>
154  
155 =head1 TODO
156  
157 I have no plans to expand this module, but I welcome any wishlist
158 requests. If you can think of something reasonable to add to this
159 module, I'll consider doing it. I also accept patches from others.
160  
161 =head1 BUGS
162  
163 Report all bugs through CPAN's bug reporting tool. Feel free to
164 file wishlist requests there as well.
165  
166 =head1 COPYRIGHT / LICENSE
167  
168 All data that is provided by this module is provided by
169 WhoCallsMe.com. They probably own the copyright to all of the data.
170 Their site doesn't appear to specify any kind of copyright or licensing
171 information. Be reasonable with it. I'll leave it up to you to
172 interpret what they think is okay for you to do with their data.
173  
174 The (short amount of) code in this module is (C) Dusty Wilson, but
175 no real rights are reserved. Feel free to use it as you see fit,
176 as long as it doesn't get me in trouble. ;-)
177  
178 =cut
↑ Summary