File Coverage

blib/lib/WWW/Shorten/URLchen.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


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