File Coverage

blib/lib/WWW/Shorten.pm
Criterion Covered Total %
statement 25 25 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 34 35 97.1


line stmt bran cond sub pod time code
1             #$Id$
2              
3             =head1 NAME
4            
5             WWW::Shorten - Interface to URL shortening sites.
6            
7             =head1 SYNOPSIS
8            
9             use WWW::Shorten 'Linkz';
10             use WWW::Shorten 'MakeAShorterLink';
11             use WWW::Shorten 'Metamark';
12             use WWW::Shorten 'NotLong';
13             use WWW::Shorten 'OneShortLink';
14             use WWW::Shorten 'Shorl';
15             use WWW::Shorten 'TinyClick';
16             use WWW::Shorten 'TinyLink';
17             use WWW::Shorten 'TinyURL';
18            
19             # Individual modules have have their
20             # own syntactic variations.
21            
22             # See the documentation for the particular
23             # module you intend to use for details, trips
24             # and traps.
25            
26             $short_url = makeashorterlink($long_url);
27            
28             $long_url = makealongerlink($short_url);
29            
30             # If you don't like the function names:
31             use WWW::Shorten 'Metamark', ':short';
32             $short_url = short_link( $long_url );
33             $long_url = long_link( $short_url );
34            
35             =head1 ABSTRACT
36            
37             A Perl interface to URL shortening sites. These sites maintain
38             databases of long URLs, each of which has a unique identifier.
39            
40             =head1 DESCRIPTION
41            
42             The function C<makeashorterlink> will call the relevant web site
43             passing it your long URL and will return the shorter version.
44            
45             The function C<makealongerlink> does the reverse. C<makealongerlink>
46             will accept as an argument either the full shortened URL or just the
47             identifier.
48            
49             If anything goes wrong, then either function will return C<undef>.
50            
51             =cut
52              
53             package WWW::Shorten;
54              
55 4     4   172659 use 5.006;
  4         10  
  4         65  
56 4     4   10 use strict;
  4         2  
  4         60  
57 4     4   11 use warnings;
  4         4  
  4         102  
58              
59 4     4   12 use base qw(WWW::Shorten::generic);
  4         4  
  4         423  
60             our @EXPORT = qw(makeashorterlink makealongerlink);
61             our $VERSION = '3.02';
62              
63             our $DEFAULT_SERVICE = 'Metamark';
64              
65 4     4   16 use Carp;
  4         3  
  4         641  
66              
67             my $style;
68              
69             =head1 Subroutines
70            
71             =head2 import
72            
73             Called when the module is C<use>d. Loads the correct sub-module
74            
75             =cut
76              
77             sub import {
78 4     4   32     my $class = shift;
79 4         6     $style = shift;
80 4 100       9     $style = $DEFAULT_SERVICE unless defined $style;
81 4         6     my $package = "${class}::${style}";
82 4         4     eval {
83 4         4 my $file = $package;
84 4         14 $file =~ s/::/\//g;
85 4         477 require "$file.pm";
86                 };
87 4 50       9     croak $@ if $@;
88 4         28     $package->import( @_ );
89             }
90              
91             1;
92              
93             __END__
94            
95             =head2 EXPORT
96            
97             makeashorterlink, makealongerlink
98            
99             Or, if you specify C<:short> on the import line, you instead
100             get C<short_link> and C<long_link>. If you explicitly want the
101             default set, use C<:default>.
102            
103             Actually these functions are exported from the relevant subclass.
104            
105             =head1 COMMAND LINE PROGRAM
106            
107             A very simple program called F<shorten> is supplied in the
108             distribution's F<bin> folder. This program takes a URL and
109             gives you a shortened version of it.
110            
111             =head1 EXAMPLES and PROGRAMS
112            
113             Adam Kessel wrote F<shorlfilter>, a program that uses C<WWW::Shorten>
114             to filter a file, converting long URLs to short ones.
115            
116             http://bostoncoop.net/adam/shorlfilter
117            
118             There is also a F<bin> directory in this distribution which contains a
119             sample program.
120            
121             =head1 NO LONGER SUPPORTED
122            
123             The URL-shortening industry is pretty volatile. Many sites exist for a
124             while and then go away. The most famous of those is probably Make A Shorter
125             Link (the site that originally inspired this suite of modules). MASL has
126             been acquired by TinyURL.com and no longer exists.
127            
128             Here is a list of sites that were once supported by this module and are no
129             longer with us:
130            
131             =over 4
132            
133             =item MakeAShorterLink
134            
135             =item BabyURL
136            
137             =item EkDk
138            
139             =item qURL (although the differently capitalised Qurl.com now uses their old domain)
140            
141             =item ShortLink
142            
143             =item SmLnk
144            
145             =item URLjr
146            
147             =item V3
148            
149             =back
150            
151             See Joshua Schachter's blog entry at
152             L<http://joshua.schachter.org/2009/04/on-url-shorteners.html> for some
153             very interesting discussion on some problems that can be caused by the
154             volatility of this part of the web industry.
155            
156             =head1 RELATED MODULES
157            
158             =head2 Similar Aim
159            
160             L<WWW::MakeAShorterLink> is what this module was originally based upon.
161             That module is obsoleted by L<WWW::Shorten::MakeAShorterLink>, one of
162             the many subclasses of L<WWW::Shorten>. Of course, with the demise of
163             Make A Shorter Link, neither the obsolete module nor it's replacement are
164             of any use.
165            
166             =head2 Same Area, Different Purpose
167            
168             L<CGI::Shorten> provides building blocks for you to create your own URL
169             shortening service. It provides routines to shoretn a URL, lengthen one,
170             and it keeps a store. Nice and easy.
171            
172             =head1 THANKS
173            
174             Dave Cross for L<WWW::MakeAShorterLink>
175            
176             Alex Page for the original LWP hacking on which Dave based his code.
177            
178             Simon Batistoni for giving the C<makealongerlink> idea to Dave.
179            
180             Eric Hammond for writing the NotLong variant.
181            
182             Shashank Tripathi <shank@shank.com> for providing both SnipURL.com and
183             advice on the module.
184            
185             Kevin Gilbertson (Gilby) supplied information on the TinyURL API.
186            
187             Matt Felsen (mattf) wanted shorter function names.
188            
189             Ask Bjoern Hansen for providing both Metamark.net and advice on the
190             module.
191            
192             Martin Thurn for helping me notice a bug and for a suggestion regarding
193             F<MASL.pm>.
194            
195             Jon and William (jon and wjr at smlnk.com respectively) for providing
196             SmLnk.com.
197            
198             P J Goodwin for providing the code for L<WWW::Shorten::OneShortLink>.
199            
200             And especial thanks to all providers of these services.
201            
202             =head1 BUGS, REQUESTS, COMMENTS
203            
204             Support for this module is supplied using the CPAN RT system via the web
205             or email:
206            
207             http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Shorten
208             ( shorter URL: http://xrl.us/rfb )
209            
210             bug-www-shorten@rt.cpan.org
211            
212             This makes it much easier for me to track things and thus means
213             your problem is less likely to be neglected.
214            
215             =head1 LICENCE AND COPYRIGHT
216            
217             WWW::Shorten::NotLong copyright (c) Eric Hammond <ehammond@thinksome.com>.
218            
219             Other modules copyright (c) Magnum Solutions Ltd., 2007. All rights
220             reserved.
221            
222             This library is free software; you can redistribute it and/or modify
223             it under the same terms as Perl itself, either Perl version 5.000 or,
224             at your option, any later version of Perl 5 you may have available.
225            
226             The full text of the licences can be found in the F<Artistic> and
227             F<COPYING> files included with this module, or in L<perlartistic> and
228             L<perlgpl> as supplied with Perl 5.8.1 and later.
229            
230             =head1 AUTHOR
231            
232             Original Iain Truskett <spoon@cpan.org>
233            
234             Based on WWW::MakeAShorterLink by Dave Cross <dave@mag-sol.com>
235            
236             In 2004 Dave Cross took over the maintenance of this distribution
237             following the death of Iain Truskett.
238            
239             =head1 SEE ALSO
240            
241             L<perl>, L<CGI::Shorten>.
242            
243             =cut
244