| 1 | package WWW::Alexa::TrafficRank; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | $VERSION = '1.11'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | sub new | ||||||||||||||||||||
| 11 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||
| 12 | 1 | my $class = shift; | |||||||||||||||||||
| 13 | 1 | my %par = @_; | |||||||||||||||||||
| 14 | 1 | my $self; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | $self->{ua} = LWP::UserAgent->new(agent => $par{agent} || 'Opera 11.1') or return; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$par{'agent'} || 'Opera 11.1'
MC/DC0%0/1
$par{'agent'} || 'Opera 11.1'
$par{'agent'}
Truth table50%1/2
A
A= $par{'agent'}
| |||||||||||||||||||||
| 17 | 1 | ▶ | $self->{ua}->proxy('http', $par{proxy}) if $par{proxy}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 1 | ▶ | $self->{ua}->timeout($par{timeout}) if $par{timeout}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | bless ($self, $class); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub get | ||||||||||||||||||||
| 24 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||
| 25 | 1 | my ($self, $domain) = @_; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | ▶ | return unless defined $domain; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | my $res = $self->{ua}->get("http://xml.alexa.com/data?cli=10&dat=nsa&url=$domain"); | |||||||||||||||||||
| 30 | 1 | ▶ | return $res->status_line if !$res->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | my ($rank) = $res->content =~ /<POPULARITY URL=".+" TEXT="(\d+)"/i; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | return $rank; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 2 | 1; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | __END__ | ||||||||||||||||||||