line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::5gp; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15549
|
use 5.008001; |
|
2
|
|
|
|
|
37
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
124
|
|
8
|
2
|
|
|
2
|
|
694
|
use JSON::PP; |
|
2
|
|
|
|
|
14429
|
|
|
2
|
|
|
|
|
157
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
13
|
use base qw( WWW::Shorten::generic Exporter ); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
992
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
12
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $service = 'http://5.gp/api/'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub makeashorterlink ($) { |
17
|
|
|
|
|
|
|
my $url = shift or croak 'No URL passed to makeashorterlink'; |
18
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
19
|
|
|
|
|
|
|
my $resp = $ua->get($service .'short?longurl=' . $url); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if (!$resp->is_success) { |
22
|
|
|
|
|
|
|
carp $resp->status_line; |
23
|
|
|
|
|
|
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
my $result = decode_json $resp->content; |
26
|
|
|
|
|
|
|
return $result->{url}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub makealongerlink ($) { |
30
|
|
|
|
|
|
|
my $url = shift or croak 'No 5.gp key / URL passed to makealongerlink'; |
31
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$url = "http://5.gp/$url" unless $url =~ m!^http://!i; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $resp = $ua->get($service . 'long?shorturl=' . $url); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if (!$resp->is_success) { |
38
|
|
|
|
|
|
|
carp $resp->status_line; |
39
|
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
my $result = decode_json $resp->content; |
42
|
|
|
|
|
|
|
return $result->{$url}->{target_url}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |