line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::5gp; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
78881
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
7
|
use Carp qw(); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
29
|
|
7
|
2
|
|
|
2
|
|
940
|
use JSON::MaybeXS qw(decode_json); |
|
2
|
|
|
|
|
12258
|
|
|
2
|
|
|
|
|
122
|
|
8
|
2
|
|
|
2
|
|
720
|
use URI (); |
|
2
|
|
|
|
|
5000
|
|
|
2
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
9
|
use base qw( WWW::Shorten::generic Exporter ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
901
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
12
|
|
|
|
|
|
|
our $VERSION = '1.030'; |
13
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $service = 'http://5.gp/api/'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub makeashorterlink { |
18
|
0
|
0
|
|
0
|
1
|
|
my $url = shift or Carp::croak('No URL passed to makeashorterlink'); |
19
|
0
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
20
|
0
|
|
|
|
|
|
my $uri = URI->new('http://5.gp/api/short'); |
21
|
0
|
|
|
|
|
|
$uri->query_form(longurl => $url); |
22
|
0
|
|
|
|
|
|
my $res = $ua->get($uri); |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
0
|
|
|
|
return undef unless $res && $res->is_success; |
25
|
0
|
|
|
|
|
|
my $content = decode_json($res->decoded_content); |
26
|
0
|
0
|
0
|
|
|
|
return undef unless $content && $content->{url}; |
27
|
0
|
|
|
|
|
|
return $content->{url}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub makealongerlink { |
31
|
0
|
0
|
|
0
|
1
|
|
my $url = shift or Carp::croak('No 5.gp key / URL passed to makealongerlink'); |
32
|
0
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
$url = "http://5.gp/$url" unless $url =~ m!^http://!i; |
35
|
0
|
|
|
|
|
|
my $uri = URI->new('http://5.gp/api/long'); |
36
|
0
|
|
|
|
|
|
$uri->query_form(shorturl => $url); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $res = $ua->get($uri); |
39
|
0
|
0
|
0
|
|
|
|
return undef unless $res && $res->is_success; |
40
|
0
|
|
|
|
|
|
my $content = decode_json($res->decoded_content); |
41
|
0
|
0
|
0
|
|
|
|
return undef unless $content && $content->{$url}->{target_url}; |
42
|
0
|
|
|
|
|
|
return $content->{$url}->{target_url}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |