File Coverage

blib/lib/WWW/Shorten/Google.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::Google;
2 1     1   8 use strict;
  1         2  
  1         44  
3 1     1   5 use warnings;
  1         2  
  1         35  
4 1     1   5 use base qw( WWW::Shorten::generic Exporter );
  1         2  
  1         1028  
5             our @EXPORT = qw( makeashorterlink makealongerlink );
6              
7             our $VERSION = '0.01';
8              
9             use Carp;
10              
11             sub makeashorterlink {
12             my $uri = shift or croak 'No URL passed to makeashorterlink';
13             my $ua = __PACKAGE__->ua();
14             my $res = $ua->post(
15             'http://goo.gl/action/shorten',
16             {
17             url => $uri,
18             authed => 1,
19             }
20             );
21              
22             return unless $res->is_redirect;
23             my($tiny_url) = $res->header('location') =~ /url=(.+)/;
24             return $tiny_url;
25             }
26              
27             sub makealongerlink {
28             my $uri = shift or croak 'No URL passed to makealongerlink';
29              
30             my $ua = __PACKAGE__->ua();
31              
32             $uri = "http://goo.gl/$uri" unless $uri =~ m!^http://!i;
33              
34             my $res = $ua->get($uri);
35             return unless $res->is_redirect;
36             return $res->header('Location');
37             }
38              
39             1;
40             __END__