line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::RevCanonical; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
26
|
use 5.008_001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use base qw( WWW::Shorten::generic Exporter ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
746
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
use LWP::UserAgent; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _ua { |
14
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
15
|
|
|
|
|
|
|
$ua->env_proxy; |
16
|
|
|
|
|
|
|
$ua; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub makeashorterlink { |
20
|
|
|
|
|
|
|
my $url = shift or croak "URL is required"; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $res = _ua->get($url); |
23
|
|
|
|
|
|
|
my @links = grep /^<.*?>;.*\brev="canonical"/, $res->header('Link'); |
24
|
|
|
|
|
|
|
if (@links) { |
25
|
|
|
|
|
|
|
return ($links[0] =~ /^<(.*?)>/)[0]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub makealongerlink { |
32
|
|
|
|
|
|
|
my $tiny_url = shift or croak "URL is required"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $res = _ua->get($tiny_url); |
35
|
|
|
|
|
|
|
return unless $res->redirects; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $res->request->uri; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
__END__ |