File Coverage

blib/lib/WWW/Shorten/URLchen.pm
Criterion Covered Total %
statement 14 27 51.8
branch 0 10 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 21 46 45.6


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