package WWW::Shorten::NotLong; use 5.006; use strict; use warnings; use base qw( WWW::Shorten::generic Exporter ); our @EXPORT = qw(makeashorterlink makealongerlink); our $VERSION = "1.81"; use Carp; sub makeashorterlink ($;%) { my $url = shift or croak 'No URL passed to makeashorterlink'; my $ua = __PACKAGE__->ua(); my %args = @_; my $nickname = delete $args{'nickname'} || ''; my $notlong = 'http://notlong.com/'; my $resp = $ua->post($notlong, [ url => $url, (length $nickname) ? (nickname => $nickname) : (), ]); return unless $resp->is_success; if ($resp->content =~ m! notlong \s+ URL: .*? (http://[^.]+\.notlong\.com) .*? Password: \s+ (\w+) !xs) { return wantarray ? ($1, $2) : $1; } return; } sub makealongerlink ($) { my $notlong_url = shift or croak 'No notlong nickname/URL passed to makealongerlink'; my $ua = __PACKAGE__->ua(); $notlong_url = "http://$notlong_url.notlong.com/" unless $notlong_url =~ m!^http://!i; my $resp = $ua->get($notlong_url); return undef unless $resp->is_redirect; my $url = $resp->header('Location'); return $url; } 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME WWW::Shorten::NotLong - Perl interface to notlong.com =head1 SYNOPSIS use WWW::Shorten 'NotLong'; $short_url = makeashorterlink($long_url); $short_url = makeashorterlink($long_url, nickname => $nickname); ($short_url,$password) = makeashorterlink($long_url); ($short_url,$password) = makeashorterlink($long_url, nickname => $nickname); $long_url = makealongerlink($short_url); $long_url = makealongerlink($nickname); =head1 DESCRIPTION A Perl interface to the web site notlong.com. Notlong.com simply maintains a database of long URLs, each of which has a unique identifier. The function C will call the notlong.com web site passing it your long URL and will return the shorter (notlong) version. If used in a list context, then it will return both the notlong URL and the password. If you pass a nickname, the notlong service will use your provided (alpha-numeric) string as the unique identifier, provided that it has not already been assigned previously. The function C does the reverse. C will accept as an argument either the full notlong URL or just the notlong identifier/nickname. If anything goes wrong, then either function will return C. Note that notlong.com, unlike TinyURL and MakeAShorterLink, returns a unique code for every submission. =head2 EXPORT makeashorterlink, makealongerlink =head1 SUPPORT, LICENCE, THANKS and SUCH See the main L docs. =head1 AUTHOR Eric Hammond Based almost entirely on WWW::Shorten::Shorl by Iain Truskett which was based on WWW::MakeAShorterLink by Dave Cross =head1 SEE ALSO L, L, L =cut