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
|
|
123876
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
30
|
|
11
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
12
|
1
|
|
|
1
|
|
496
|
use LWP::Protocol::https; |
|
1
|
|
|
|
|
99556
|
|
|
1
|
|
|
|
|
58
|
|
13
|
1
|
|
|
1
|
|
9
|
use URI::Escape qw/uri_escape_utf8/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
14
|
1
|
|
|
1
|
|
711
|
use JSON; |
|
1
|
|
|
|
|
10614
|
|
|
1
|
|
|
|
|
8
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.8'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ABSTRACT: Perl interface to sck.pm |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
190
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
7
|
use parent qw( WWW::Shorten::generic Exporter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
22
|
1
|
|
|
1
|
|
76
|
use vars qw(@EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
74
|
|
23
|
|
|
|
|
|
|
@EXPORT_OK = qw( makeashorterlink makealongerlink ); |
24
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [@EXPORT_OK] ); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
290
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub makeashorterlink { |
29
|
2
|
50
|
|
2
|
1
|
152
|
my $url = shift or croak 'No URL passed to makeashorterlink'; |
30
|
2
|
|
|
|
|
28
|
my $ua = __PACKAGE__->ua(); |
31
|
2
|
|
|
|
|
21881
|
my $sck_url = 'https://api.sck.pm'; |
32
|
2
|
|
|
|
|
15
|
my $resp = $ua->get( $sck_url . '/shorten?' . $url, ); |
33
|
2
|
50
|
|
|
|
586893
|
return unless $resp->is_success; |
34
|
2
|
|
|
|
|
43
|
my $content = decode_json( $resp->content ); |
35
|
2
|
50
|
33
|
|
|
441
|
if ( ref $content && $content->{status} eq 'OK' ) { |
36
|
2
|
|
|
|
|
77
|
return $content->{short_url}; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
0
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub makealongerlink { |
42
|
2
|
50
|
|
2
|
1
|
10
|
my $sck_url = shift |
43
|
|
|
|
|
|
|
or croak 'No SCK key / URL passed to makealongerlink'; |
44
|
2
|
|
|
|
|
28
|
my $ua = __PACKAGE__->ua(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#call api to get long url from the short |
47
|
2
|
50
|
|
|
|
31
|
if ( $sck_url =~ /^https?:\/\/sck.pm\/(.*)$/x ) { |
48
|
2
|
|
|
|
|
8
|
$sck_url = $1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
14
|
my $resp = $ua->get( "https://api.sck.pm/expand?" . $sck_url ); |
52
|
2
|
50
|
|
|
|
296478
|
return unless $resp->is_success; |
53
|
2
|
|
|
|
|
38
|
my $content = decode_json( $resp->content ); |
54
|
2
|
50
|
33
|
|
|
75
|
if ( ref $content && $content->{status} eq 'OK' ) { |
55
|
2
|
|
|
|
|
47
|
return $content->{url}; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |