File Coverage

blib/lib/WWW/Alexa/TrafficRank.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 10 50.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package WWW::Alexa::TrafficRank;
2            
3 2     2   7647 use strict;
  2         2  
  2         44  
4 2     2   6 use warnings;
  2         2  
  2         55  
5 2     2   5 use vars qw($VERSION);
  2         5  
  2         59  
6 2     2   1106 use LWP::UserAgent;
  2         66787  
  2         295  
7            
8             $VERSION = '1.11';
9            
10             sub new
11             {
12 1     1 1 9 my $class = shift;
13 1         2 my %par = @_;
14 1         2 my $self;
15            
16 1 50 50     10 $self->{ua} = LWP::UserAgent->new(agent => $par{agent} || 'Opera 11.1') or return;
17 1 50       1894 $self->{ua}->proxy('http', $par{proxy}) if $par{proxy};
18 1 50       2 $self->{ua}->timeout($par{timeout}) if $par{timeout};
19            
20 1         4 bless ($self, $class);
21             }
22            
23             sub get
24             {
25 1     1 1 4 my ($self, $domain) = @_;
26            
27 1 50       3 return unless defined $domain;
28            
29 1         11 my $res = $self->{ua}->get("http://xml.alexa.com/data?cli=10&dat=nsa&url=$domain");
30 1 50       265999 return $res->status_line if !$res->is_success;
31            
32 1         17 my ($rank) = $res->content =~ /
33            
34 1         31 return $rank;
35             }
36            
37             1;
38            
39             __END__