| 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
MC/DC0%0/2
ref $type || $type
ref $type
$type
Truth table33%1/3
A || B
A= ref $typeB= $type
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||