line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
WWW::Shorten::Qurl - Perl interface to qurl.com |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use WWW::Shorten::Qurl; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# or |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use WWW::Shorten 'Qurl'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$short_url = makeashorterlink($long_url); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$long_url = makealongerlink($short_url); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
A Perl interface to the web site Qurl.com. Qurl simply maintains |
22
|
|
|
|
|
|
|
a database of long URLs, each of which has a unique identifier. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package WWW::Shorten::Qurl; |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
151893
|
use 5.006; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
175
|
|
29
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
173
|
|
30
|
3
|
|
|
3
|
|
25
|
use warnings; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
235
|
|
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
3
|
|
19
|
use base qw( WWW::Shorten::generic Exporter ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
4962
|
|
33
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
34
|
|
|
|
|
|
|
our $VERSION = '2.01'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use Carp; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 Functions |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 makeashorterlink |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The function C will call the Qurl web site passing |
43
|
|
|
|
|
|
|
it your long URL and will return the shorter Qurl version. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub makeashorterlink ($) |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
my $url = shift or croak 'No URL passed to makeashorterlink'; |
50
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
51
|
|
|
|
|
|
|
my $qurl = 'http://qurl.com/automate.php'; |
52
|
|
|
|
|
|
|
my $resp = $ua->post($qurl, [ |
53
|
|
|
|
|
|
|
url => $url, |
54
|
|
|
|
|
|
|
]); |
55
|
|
|
|
|
|
|
return undef unless $resp->is_success; |
56
|
|
|
|
|
|
|
my $content = $resp->content; |
57
|
|
|
|
|
|
|
return if $content eq $url; |
58
|
|
|
|
|
|
|
return $content; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 makealongerlink |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The function C does the reverse. C |
64
|
|
|
|
|
|
|
will accept as an argument either the full Qurl URL or just the |
65
|
|
|
|
|
|
|
Qurl identifier. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
If anything goes wrong, then either function will return C. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub makealongerlink ($) |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
my $qurl = shift |
74
|
|
|
|
|
|
|
or croak 'No Qurl key / URL passed to makealongerlink'; |
75
|
|
|
|
|
|
|
my $ua = __PACKAGE__->ua(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$qurl = "http://qurl.com/$qurl" |
78
|
|
|
|
|
|
|
unless $qurl =~ m!^http://!i; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
if ($qurl =~ m|^http://www\.|) { |
81
|
|
|
|
|
|
|
$qurl =~ s/www\.//; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $resp = $ua->get($qurl); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return unless $resp->is_redirect; |
87
|
|
|
|
|
|
|
my $url = $resp->header('Location'); |
88
|
|
|
|
|
|
|
return $url; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |