line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of WWW-Shorten-SCK |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2013 by celogeek . |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
package WWW::Shorten::SCK; |
10
|
1
|
|
|
1
|
|
155170
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
12
|
1
|
|
|
1
|
|
6
|
use URI::Escape qw/uri_escape_utf8/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
98
|
|
13
|
1
|
|
|
1
|
|
1145
|
use JSON; |
|
1
|
|
|
|
|
15336
|
|
|
1
|
|
|
|
|
6
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.5'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: Perl interface to sck.pm |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
222
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
53
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
1172
|
use parent qw( WWW::Shorten::generic Exporter ); |
|
1
|
|
|
|
|
307
|
|
|
1
|
|
|
|
|
6
|
|
21
|
1
|
|
|
1
|
|
73
|
use vars qw(@EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
22
|
|
|
|
|
|
|
@EXPORT_OK = qw( makeashorterlink makealongerlink ); |
23
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [@EXPORT_OK] ); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
338
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub makeashorterlink { |
28
|
2
|
50
|
|
2
|
1
|
43
|
my $url = shift or croak 'No URL passed to makeashorterlink'; |
29
|
2
|
|
|
|
|
28
|
my $ua = __PACKAGE__->ua(); |
30
|
2
|
|
|
|
|
662406
|
my $sck_url = 'http://api.sck.pm'; |
31
|
2
|
|
|
|
|
16
|
my $resp = $ua->get( $sck_url . '?url=' . uri_escape_utf8($url), ); |
32
|
2
|
50
|
|
|
|
323312
|
return unless $resp->is_success; |
33
|
2
|
|
|
|
|
37
|
my $content = decode_json( $resp->content ); |
34
|
2
|
50
|
33
|
|
|
66
|
if ( ref $content && $content->{status} eq 'OK' ) { |
35
|
2
|
|
|
|
|
52
|
return 'http://sck.pm/' . $content->{short}; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
0
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub makealongerlink { |
41
|
2
|
50
|
|
2
|
1
|
13
|
my $sck_url = shift |
42
|
|
|
|
|
|
|
or croak 'No SCK key / URL passed to makealongerlink'; |
43
|
2
|
|
|
|
|
24
|
my $ua = __PACKAGE__->ua(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#call api to get long url from the short |
46
|
2
|
50
|
|
|
|
22
|
$sck_url = substr( $sck_url, 14 ) |
47
|
|
|
|
|
|
|
if substr( $sck_url, 0, 14 ) eq 'http://sck.pm/'; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
15
|
my $resp = $ua->get("http://api.sck.pm?surl=$sck_url"); |
50
|
2
|
50
|
|
|
|
68475
|
return unless $resp->is_success; |
51
|
2
|
|
|
|
|
42
|
my $content = decode_json( $resp->content ); |
52
|
2
|
50
|
33
|
|
|
68
|
if ( ref $content && $content->{status} eq 'OK' ) { |
53
|
0
|
|
|
|
|
0
|
return $content->{url}; |
54
|
|
|
|
|
|
|
} |
55
|
2
|
|
|
|
|
41
|
return; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |