blib/lib/Telephone/Lookup/Americom.pm

filter: Statementstmt 85.7% 24 / 28 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 72.0% 31 / 43 CC 4 SCAR 8.3
CC
4
Cov
77%
lookup
3.3
new
2.1
BEGIN
1.0
CRAP 2.3
↑ Summary
1 package Telephone::Lookup::Americom;
2 1 our $VERSION = 0.01;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
10 1 my $type = shift;
11 1 ▶ my $class = ref($type) || $type;
Condition33%1/3
ref $type || $type
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table33%1/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
12 1 my $self = {};
13 1 bless $self, $class;
14 1 return $self;
15 }
16  
17 1 ▶sub lookup {
Subroutine lookup: called CC=3 SCAR=11.9
Pod undocumented
18 1 my ($self, $query) = @_;
19 1 my $url = "http://decoder.americom.com/decoderscript?Search=$query&handle=101";
20  
21 ## Using LWP::Simple to get the html content
22 1 my $content = get($url);
23  
24 ## Format the content, naively, making it easier to parse
25 1 $content =~ s/[\r\n]+//g; ## get rid of newlines
26 {
27 1 local $/; ## clear default newline separator
28 1 $content =~ s/<[^>]*>//gs; ## strip html comments. not a very good method, but works for us
29 }
30  
31 1 my (@results);
32  
33 ## AREA_CODE Record match
34 1 ▶ if ($content =~ /Found Area Code Match(.?\d+-\d{3}) .{10}(.*?)Created on (.*?\d{4}).*?((Area)|( Country)|( Found))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /Found Area Code Match(.?\d+-\d{3}) .{10}(.*?)Created on (.*?\d{4}).*?((Area)|( Country)|( Found))/) 0 1 1
35 0 my $record = { _type => 'AREA_CODE',
36 area_code => $1,
37 location => $2,
38 created_on => $3
39 };
40 0 push(@results, $record);
41 }
42  
43 ## EXCHANGE_CODE Record match
44 1 ▶ if ($content =~ /Exchange Location:..(.*?)Exchange Type:..(.*?)Owner:..(.*?)Created On:..(.*?\d{4})/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /Exchange Location:..(.*?)Exchange Type:..(.*?)Owner:..(.*?)Created On:..(.*?\d{4})/) 0 1 1
45 0 my $record = { _type => 'EXCHANGE_CODE',
46 exchange_location => $1,
47 exchange_type => $2,
48 exchange_owner => $3,
49 created_on => $4
50 };
51 0 push(@results, $record);
52 }
53
54 1 return @results;
55 }
56  
57 1 1;
58 __END__
↑ Summary