line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::URLchen; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15790
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use base qw( WWW::Shorten::generic Exporter ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
452
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
9
|
|
|
|
|
|
|
our $VERSION = '0.0.3'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Carp; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub makeashorterlink ($) { |
14
|
|
|
|
|
|
|
my $url = shift or croak 'No URL passed to makeashorterlink'; |
15
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
16
|
|
|
|
|
|
|
my $service_url = 'http://urlchen.de/'; |
17
|
|
|
|
|
|
|
my $resp = $ua->post($service_url, [ |
18
|
|
|
|
|
|
|
url => $url, |
19
|
|
|
|
|
|
|
source => "PerlAPI-$VERSION", |
20
|
|
|
|
|
|
|
]); |
21
|
|
|
|
|
|
|
return undef unless $resp->is_redirect; |
22
|
|
|
|
|
|
|
return $resp->header('X-Location'); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub makealongerlink ($) { |
26
|
|
|
|
|
|
|
my $urlchen = shift |
27
|
|
|
|
|
|
|
or croak 'No Urlchen key / URL passed to makealongerlink'; |
28
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$urlchen = "http://urlchen.de/$urlchen" |
31
|
|
|
|
|
|
|
unless $urlchen =~ m!^http://!i; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $resp = $ua->get($urlchen); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return undef unless $resp->is_redirect; |
36
|
|
|
|
|
|
|
my $url = $resp->header('Location'); |
37
|
|
|
|
|
|
|
return $url; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |