line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Compete; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30087
|
use 5.008008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
111
|
|
10
|
1
|
|
|
1
|
|
1172
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
57460
|
|
|
1
|
|
|
|
|
32
|
|
11
|
1
|
|
|
1
|
|
1552
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant COMPETE_VERSION => '3'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Preloaded methods go here. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
my $pkg = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $self = {}; |
22
|
|
|
|
|
|
|
bless $self, $pkg; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if (! $self->_init(@_)) { |
25
|
|
|
|
|
|
|
return undef; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _init { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{'_ver'} = $args->{'ver'} || COMPETE_VERSION; |
36
|
|
|
|
|
|
|
$self->{'_debug'} = $args->{'debug'}; |
37
|
|
|
|
|
|
|
$self->{'_key'} = $args->{'api_key'}; |
38
|
|
|
|
|
|
|
$self->{'_return_int'} = $args->{'return_int'} || 0; |
39
|
|
|
|
|
|
|
$self->{'_ua'} = LWP::UserAgent->new(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub api_key { |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
my $key = shift; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ($key) { |
49
|
|
|
|
|
|
|
$self->{'_key'} = $key; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return $self->{'_key'}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub api_ver { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
my $ver = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ($ver) { |
60
|
|
|
|
|
|
|
$self->{'_ver'} = $ver; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return $self->{'_ver'}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub ua { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
my $ua = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
if ($ua) { |
71
|
|
|
|
|
|
|
$self->{'_ua'}->agent($ua); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->{'_ua'}->agent(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub fetch { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
my $domain = shift; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->_reset(); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
carp("No API key!") && return unless $self->api_key(); |
84
|
|
|
|
|
|
|
carp("Nothing to fetch!") && return unless $domain; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->{'_current_domain'} = $domain; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$self->{'_response'} = |
89
|
|
|
|
|
|
|
$self->{'_ua'}->get($self->_build_url($domain)); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->{'_response_data'} = XMLin($self->{'_response'}->content(), |
92
|
|
|
|
|
|
|
NormalizeSpace => 2, |
93
|
|
|
|
|
|
|
SuppressEmpty => "" ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_measurement_yr { |
97
|
|
|
|
|
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return $self->{'_response_data'}->{dmn}->{metrics}->{val}->{yr} || ""; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_measurement_mon { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return $self->{'_response_data'}->{dmn}->{metrics}->{val}->{mth} || ""; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_domain { |
109
|
|
|
|
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return $self->{'_current_domain'} || ""; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_visitors { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $visitors = $self->{'_response_data'}->{dmn}->{metrics}->{val}->{uv}->{count} || ""; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if ($self->{'_return_int'}) { |
120
|
|
|
|
|
|
|
$visitors =~ s/[^\d]//g; |
121
|
|
|
|
|
|
|
return $visitors; |
122
|
|
|
|
|
|
|
} else { |
123
|
|
|
|
|
|
|
return $visitors; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub get_rank { |
129
|
|
|
|
|
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $ranking = $self->{'_response_data'}->{dmn}->{metrics}->{val}->{uv}->{ranking} || ""; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
if ($self->{'_return_int'}) { |
134
|
|
|
|
|
|
|
$ranking =~ s/[^\d]//g; |
135
|
|
|
|
|
|
|
return $ranking; |
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
return $ranking; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub get_trust { |
142
|
|
|
|
|
|
|
my $self = shift; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
return $self->{'_response_data'}->{dmn}->{trust}->{val} || ""; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub get_summary_link { |
148
|
|
|
|
|
|
|
my $self = shift; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$self->{'_response_data'}->{dmn}->{metrics}->{link}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _build_url { |
154
|
|
|
|
|
|
|
my $self = shift; |
155
|
|
|
|
|
|
|
my $domain = shift; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $url = 'http://api.compete.com/fast-cgi/MI?d=' . $domain . |
158
|
|
|
|
|
|
|
'&ver=' . $self->{'_ver'} . |
159
|
|
|
|
|
|
|
'&apikey=' . $self->{'_key'}; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
return $url; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _reset { |
165
|
|
|
|
|
|
|
my $self = shift; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$self->{'_current_domain'} = undef; |
168
|
|
|
|
|
|
|
$self->{'_response'} = undef; |
169
|
|
|
|
|
|
|
$self->{'_response_data'} = undef; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
__END__ |