line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Google::PageRank; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# -*- perl -*- |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1437237
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
6
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
87
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
10
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
129
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1895
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
117132
|
|
|
3
|
|
|
|
|
94
|
|
11
|
3
|
|
|
3
|
|
25
|
use URI::Escape; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2477
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.19'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
17
|
0
|
|
|
|
|
0
|
my %par = @_; |
18
|
0
|
|
|
|
|
0
|
my $self; |
19
|
|
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new(agent => $par{agent} || |
20
|
0
|
0
|
0
|
|
|
0
|
'Mozilla/4.0 (compatible; GoogleToolbar 2.0.111-big; Windows XP 5.1)') |
21
|
|
|
|
|
|
|
or return; |
22
|
0
|
0
|
|
|
|
0
|
$self->{ua}->env_proxy if $par{env_proxy}; |
23
|
0
|
0
|
|
|
|
0
|
$self->{ua}->proxy('http', $par{proxy}) if $par{proxy}; |
24
|
0
|
0
|
|
|
|
0
|
$self->{ua}->timeout($par{timeout}) if $par{timeout}; |
25
|
0
|
|
0
|
|
|
0
|
$self->{host} = $par{host} || 'toolbarqueries.google.com'; |
26
|
0
|
|
|
|
|
0
|
bless($self, $class); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
0
|
|
|
0
|
1
|
0
|
my ($self, $url) = @_; |
31
|
0
|
0
|
0
|
|
|
0
|
return unless defined $url and $url =~ m[^https?://]i; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $ch = '6' . _compute_ch_new('info:' . $url); |
34
|
0
|
|
|
|
|
0
|
my $query = 'http://' . $self->{host} . '/tbr?client=navclient-auto&ch=' . $ch . |
35
|
|
|
|
|
|
|
'&ie=UTF-8&oe=UTF-8&features=Rank&q=info:' . uri_escape($url); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my $resp = $self->{ua}->get($query); |
38
|
0
|
0
|
0
|
|
|
0
|
if ($resp->is_success && $resp->content =~ /Rank_\d+:\d+:(\d+)/) { |
39
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
40
|
0
|
|
|
|
|
0
|
return ($1, $resp); |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
0
|
return $1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
46
|
0
|
|
|
|
|
0
|
return (undef, $resp); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
0
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _compute_ch_new { |
54
|
16
|
|
|
16
|
|
295
|
my $url = shift; |
55
|
|
|
|
|
|
|
|
56
|
16
|
|
|
|
|
19
|
my $ch = _compute_ch($url); |
57
|
16
|
|
|
|
|
24
|
$ch = (($ch % 0x0d) & 7) | (($ch / 7) << 2); |
58
|
|
|
|
|
|
|
|
59
|
16
|
|
|
|
|
21
|
return _compute_ch(pack("V20", map {my $t = $ch; _wsub($t, $_*9); $t} 0..19)); |
|
320
|
|
|
|
|
189
|
|
|
320
|
|
|
|
|
265
|
|
|
320
|
|
|
|
|
272
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _compute_ch { |
63
|
32
|
|
|
32
|
|
23
|
my $url = shift; |
64
|
|
|
|
|
|
|
|
65
|
32
|
|
|
|
|
140
|
my @url = unpack("C*", $url); |
66
|
32
|
|
|
|
|
54
|
my ($a, $b, $c, $k) = (0x9e3779b9, 0x9e3779b9, 0xe6359a60, 0); |
67
|
32
|
|
|
|
|
27
|
my $len = scalar @url; |
68
|
|
|
|
|
|
|
|
69
|
32
|
|
|
|
|
47
|
while ($len >= 12) { |
70
|
144
|
|
|
|
|
218
|
_wadd($a, $url[$k+0] | ($url[$k+1] << 8) | ($url[$k+2] << 16) | ($url[$k+3] << 24)); |
71
|
144
|
|
|
|
|
194
|
_wadd($b, $url[$k+4] | ($url[$k+5] << 8) | ($url[$k+6] << 16) | ($url[$k+7] << 24)); |
72
|
144
|
|
|
|
|
191
|
_wadd($c, $url[$k+8] | ($url[$k+9] << 8) | ($url[$k+10] << 16) | ($url[$k+11] << 24)); |
73
|
|
|
|
|
|
|
|
74
|
144
|
|
|
|
|
122
|
_mix($a, $b, $c); |
75
|
|
|
|
|
|
|
|
76
|
144
|
|
|
|
|
109
|
$k += 12; |
77
|
144
|
|
|
|
|
173
|
$len -= 12; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
32
|
|
|
|
|
35
|
_wadd($c, scalar @url); |
81
|
|
|
|
|
|
|
|
82
|
32
|
50
|
|
|
|
38
|
_wadd($c, $url[$k+10] << 24) if $len > 10; |
83
|
32
|
100
|
|
|
|
45
|
_wadd($c, $url[$k+9] << 16) if $len > 9; |
84
|
32
|
100
|
|
|
|
44
|
_wadd($c, $url[$k+8] << 8) if $len > 8; |
85
|
32
|
100
|
|
|
|
49
|
_wadd($b, $url[$k+7] << 24) if $len > 7; |
86
|
32
|
100
|
|
|
|
51
|
_wadd($b, $url[$k+6] << 16) if $len > 6; |
87
|
32
|
100
|
|
|
|
49
|
_wadd($b, $url[$k+5] << 8) if $len > 5; |
88
|
32
|
100
|
|
|
|
50
|
_wadd($b, $url[$k+4]) if $len > 4; |
89
|
32
|
100
|
|
|
|
58
|
_wadd($a, $url[$k+3] << 24) if $len > 3; |
90
|
32
|
100
|
|
|
|
51
|
_wadd($a, $url[$k+2] << 16) if $len > 2; |
91
|
32
|
100
|
|
|
|
52
|
_wadd($a, $url[$k+1] << 8) if $len > 1; |
92
|
32
|
50
|
|
|
|
52
|
_wadd($a, $url[$k]) if $len > 0; |
93
|
|
|
|
|
|
|
|
94
|
32
|
|
|
|
|
27
|
_mix($a, $b, $c); |
95
|
|
|
|
|
|
|
|
96
|
32
|
|
|
|
|
72
|
return $c; # integer is positive always |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _mix { |
100
|
176
|
|
|
176
|
|
126
|
my ($a, $b, $c) = @_; |
101
|
|
|
|
|
|
|
|
102
|
176
|
|
|
|
|
140
|
_wsub($a, $b); _wsub($a, $c); $a ^= $c >> 13; |
|
176
|
|
|
|
|
144
|
|
|
176
|
|
|
|
|
107
|
|
103
|
176
|
|
|
|
|
145
|
_wsub($b, $c); _wsub($b, $a); $b ^= ($a << 8) % 4294967296; |
|
176
|
|
|
|
|
168
|
|
|
176
|
|
|
|
|
114
|
|
104
|
176
|
|
|
|
|
151
|
_wsub($c, $a); _wsub($c, $b); $c ^= $b >>13; |
|
176
|
|
|
|
|
152
|
|
|
176
|
|
|
|
|
121
|
|
105
|
176
|
|
|
|
|
133
|
_wsub($a, $b); _wsub($a, $c); $a ^= $c >> 12; |
|
176
|
|
|
|
|
150
|
|
|
176
|
|
|
|
|
98
|
|
106
|
176
|
|
|
|
|
156
|
_wsub($b, $c); _wsub($b, $a); $b ^= ($a << 16) % 4294967296; |
|
176
|
|
|
|
|
137
|
|
|
176
|
|
|
|
|
119
|
|
107
|
176
|
|
|
|
|
151
|
_wsub($c, $a); _wsub($c, $b); $c ^= $b >> 5; |
|
176
|
|
|
|
|
146
|
|
|
176
|
|
|
|
|
107
|
|
108
|
176
|
|
|
|
|
135
|
_wsub($a, $b); _wsub($a, $c); $a ^= $c >> 3; |
|
176
|
|
|
|
|
146
|
|
|
176
|
|
|
|
|
104
|
|
109
|
176
|
|
|
|
|
150
|
_wsub($b, $c); _wsub($b, $a); $b ^= ($a << 10) % 4294967296; |
|
176
|
|
|
|
|
137
|
|
|
176
|
|
|
|
|
114
|
|
110
|
176
|
|
|
|
|
146
|
_wsub($c, $a); _wsub($c, $b); $c ^= $b >> 15; |
|
176
|
|
|
|
|
159
|
|
|
176
|
|
|
|
|
106
|
|
111
|
|
|
|
|
|
|
|
112
|
176
|
|
|
|
|
278
|
@_[0 .. $#_] = ($a, $b, $c); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
686
|
|
|
686
|
|
547
|
sub _wadd { $_[0] = int(($_[0] + $_[1]) % 4294967296);} |
116
|
3488
|
|
|
3488
|
|
2498
|
sub _wsub { $_[0] = int(($_[0] - $_[1]) % 4294967296);} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |