File Coverage

blib/lib/WWW/Shorten/IsGd.pm
Criterion Covered Total %
statement 15 30 50.0
branch 0 14 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 53 41.5


line stmt bran cond sub pod time code
1             package WWW::Shorten::IsGd;
2 2     2   65444 use strict;
  2         3  
  2         55  
3 2     2   7 use warnings;
  2         3  
  2         64  
4              
5 2     2   7 use base qw( WWW::Shorten::generic Exporter );
  2         3  
  2         787  
6             our @EXPORT = qw( makeashorterlink makealongerlink );
7 2     2   42505 use Carp ();
  2         2  
  2         45  
8 2     2   891 use HTML::Entities qw(decode_entities);
  2         7443  
  2         487  
9              
10             our $VERSION = '0.004';
11             $VERSION = eval $VERSION;
12              
13             sub makeashorterlink {
14 0 0   0 1   my $url = shift or Carp::croak('No URL passed to makeashorterlink');
15 0           my $ua = __PACKAGE__->ua();
16 0           my $response = $ua->post('https://is.gd/create.php', {
17             url => $url,
18             format => 'simple',
19             });
20              
21 0 0         return undef unless $response->is_success;
22 0           my $shorturl = $response->decoded_content;
23 0 0         return undef if $shorturl =~ m/Error/;
24 0           return $shorturl;
25             }
26              
27             sub makealongerlink {
28 0 0   0 1   my $url = shift or Carp::croak('No is.gd key/URL passed to makealongerlink');
29 0           my $ua = __PACKAGE__->ua();
30              
31 0 0         $url = "https://is.gd/$url" unless $url =~ m{^https?://}i;
32 0           my $response = $ua->post('https://is.gd/forward.php', {
33             shorturl => $url,
34             format => 'simple',
35             });
36              
37 0 0         return undef unless $response->is_success;
38 0           my $longurl = $response->decoded_content;
39 0 0         return undef if $longurl =~ m/Error/;
40 0           return decode_entities($longurl);
41             }
42              
43             1;
44              
45             __END__