line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Expand::More; |
2
|
2
|
|
|
2
|
|
33483
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1141
|
use Furl; |
|
2
|
|
|
|
|
56065
|
|
|
2
|
|
|
|
|
1486
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _default_ua { |
10
|
0
|
|
|
0
|
|
|
my $args = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
0
|
|
|
|
Furl->new( |
|
|
|
0
|
|
|
|
|
13
|
|
|
|
|
|
|
timeout => $args->{timeout} || 5, |
14
|
|
|
|
|
|
|
agent => $args->{agent} || __PACKAGE__."/$VERSION", |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our %CACHE = (); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub expand { |
21
|
0
|
|
|
0
|
1
|
|
my ($class, $url, $opt) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
return $CACHE{$url} if exists $CACHE{$url}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my @urls; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$class->_expand($url, \@urls); |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ($opt->{cache}) { |
30
|
0
|
|
|
|
|
|
$CACHE{$url} = $urls[-1]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $urls[-1]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub expand_all { |
37
|
0
|
|
|
0
|
1
|
|
my ($class, $url, $opt) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
return $CACHE{$url} if exists $CACHE{$url}; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my @urls; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$class->_expand($url, \@urls); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($opt->{cache}) { |
46
|
0
|
|
|
|
|
|
$CACHE{$url} = [@urls]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return @urls; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _expand { |
53
|
0
|
|
|
0
|
|
|
my ($class, $url, $urls, $opt) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
0
|
|
|
|
$opt->{ua} ||= _default_ua(); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
push @{$urls}, $url; |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $res = $opt->{ua}->request( |
60
|
|
|
|
|
|
|
method => 'HEAD', |
61
|
|
|
|
|
|
|
url => $url, |
62
|
|
|
|
|
|
|
max_redirects => 0, |
63
|
|
|
|
|
|
|
headers => [ Connection => 'close' ], |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if (my $next_url = $res->headers->header('location')) { |
67
|
0
|
|
|
|
|
|
return $class->_expand($next_url, $urls, $opt); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |