line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::Flickr; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
21
|
use 5.008_001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
4
|
use base qw( WWW::Shorten::generic Exporter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
952
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
use Encode::Base58; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub makeashorterlink { |
14
|
|
|
|
|
|
|
my $uri = shift or croak 'No URL passed to makeashorterlink'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $photo_id; |
17
|
|
|
|
|
|
|
if ( $uri =~ m!^http://www\.flickr\.com/photos/[\w@-]+/(\d+)!i |
18
|
|
|
|
|
|
|
|| $uri =~ /^(\d+)$/ ) |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
$photo_id = $1; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
|
|
|
|
|
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return sprintf( "http://flic.kr/p/%s", encode_base58($photo_id) ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub makealongerlink { |
30
|
|
|
|
|
|
|
my $uri = shift or croak 'No URL passed to makealongerlink'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
33
|
|
|
|
|
|
|
push @{ $ua->requests_redirectable }, 'GET'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$uri = "http://flic.kr/p/$uri" unless $uri =~ m!^http://!i; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $res = $ua->get($uri); |
38
|
|
|
|
|
|
|
return if $res->redirects() == 0; |
39
|
|
|
|
|
|
|
return $res->request->uri; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
__END__ |