blib/lib/WWW/Shorten/VGd.pm

filter: Statementstmt 66.6% 24 / 36 Branchbran 18.7% 3 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 58.0% 36 / 62 CC 9 SCAR 24.0
CC
9
Cov
52%
makealongerlink
20.0
makeashorterlink
15.1
BEGIN
1.0
CRAP 11.0
↑ Summary
1 package WWW::Shorten::VGd;
2 # ABSTRACT: shorten (or lengthen) URLs with http://v.gd
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = '0.003'; # VERSION
7  
8  
9 2 ▶use base qw( WWW::Shorten::generic Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our @EXPORT = qw( makeashorterlink makealongerlink );
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub makeashorterlink {
16 1 ▶ my $url = shift or croak 'No URL passed to makeashorterlink';
Subroutine makeashorterlink: called CC=6 SCAR=27.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $url = shift() or croak("No URL passed to makeashorterlink") 0 1 1
17 1 my $ua = __PACKAGE__->ua();
18 1 ▶ my $response = $ua->post('http://v.gd/create.php', [
Branch: 1 branch
BranchTrueFalseTotal
defined __PACKAGE__->VERSION ? : 1 0 1
19 url => $url,
20 source => 'PerlAPI-' . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev'),
21 format => 'simple',
22 ]);
23 1 ▶ return unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 1 0 1
24 0 my $shorturl = $response->{_content};
25 0 ▶ return if $shorturl =~ m/Error/;
Branch: 1 branch
BranchTrueFalseTotal
if $shorturl =~ /Error/ 0 0 0
26 0 ▶ if ($response->content =~ m{(\Qhttp://v.gd/\E[\w_]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->content =~ m[(http\:\/\/v\.gd\/[\w_]+)]) 0 0 0
27 0 return $1;
28 }
29 0 return;
30 }
31  
32  
33 sub makealongerlink {
34 0 ▶ my $url = shift or croak 'No v.gd key/URL passed to makealongerlink';
Subroutine makealongerlink: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $url = shift() or croak("No v.gd key/URL passed to makealongerlink") 0 0 0
35 0 my $ua = __PACKAGE__->ua();
36
37 0 $url =~ s{\Qhttp://v.gd/\E}{}i;
38 0 ▶ my $response = $ua->post('http://v.gd/forward.php', [
Branch: 1 branch
BranchTrueFalseTotal
defined __PACKAGE__->VERSION ? : 0 0 0
39 shorturl => $url,
40 source => 'PerlAPI-' . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev'),
41 format => 'simple',
42 ]);
43 # use Data::Dumper;
44 # print STDERR Dumper $response;
45 0 ▶ return unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
46  
47 0 my $longurl = $response->{_content};
48 0 return decode_entities($longurl);
49 }
50  
51 2 1;
52  
53  
54  
55 =pod
56  
57 =encoding utf-8
58  
59 =head1 NAME
60  
61 WWW::Shorten::VGd - shorten (or lengthen) URLs with http://v.gd
62  
63 =head1 VERSION
64  
65 version 0.003
66  
67 =head1 SYNOPSIS
68  
69 use WWW::Shorten::VGd;
70 use WWW::Shorten 'VGd';
71  
72 my $url = q{http://averylong.link/wow?thats=really&really=long};
73 my $short_url = makeashorterlink($url);
74 my $long_url = makealongerlink($short_url); # eq $url
75  
76 =head1 DESCRIPTION
77  
78 A Perl interface to the web site L<http://v.gd>. v.gd simply maintains
79 a database of long URLs, each of which has a unique identifier. By default,
80 this URL shortening service will show you a preview page before redirecting
81 you. This can be turned off by setting a cookie at L<http://v.gd/previews.php>.
82  
83 =head1 FUNCTIONS
84  
85 =head2 makeashorterlink
86  
87 The function C<makeashorterlink> will call the v.gd web site passing
88 it your long URL and will return the shortened link.
89  
90 =head2 makealongerlink
91  
92 The function C<makealongerlink> does the reverse. C<makealongerlink>
93 will accept as an argument either the full TinyURL URL or just the
94 TinyURL identifier.
95  
96 If anything goes wrong, then either function will return C<undef>.
97  
98 =head1 AVAILABILITY
99  
100 The project homepage is L<http://p3rl.org/WWW::Shorten::VGd>.
101  
102 The latest version of this module is available from the Comprehensive Perl
103 Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
104 site near you, or see L<http://search.cpan.org/dist/WWW-Shorten-VGd/>.
105  
106 The development version lives at L<http://github.com/doherty/WWW-Shorten-VGd>
107 and may be cloned from L<git://github.com/doherty/WWW-Shorten-VGd.git>.
108 Instead of sending patches, please fork this project using the standard
109 git and github infrastructure.
110  
111 =head1 SOURCE
112  
113 The development version is on github at L<http://github.com/doherty/WWW-Shorten-VGd>
114 and may be cloned from L<git://github.com/doherty/WWW-Shorten-VGd.git>
115  
116 =head1 BUGS AND LIMITATIONS
117  
118 No bugs have been reported.
119  
120 Please report any bugs or feature requests through the web interface at
121 L<https://github.com/doherty/WWW-Shorten-VGd/issues>.
122  
123 =head1 AUTHOR
124  
125 Mike Doherty <doherty@cpan.org>
126  
127 =head1 COPYRIGHT AND LICENSE
128  
129 This software is copyright (c) 2011 by Mike Doherty.
130  
131 This is free software; you can redistribute it and/or modify it under
132 the same terms as the Perl 5 programming language system itself.
133  
134 =cut
135  
136  
137 __END__
↑ Summary