package WWW::Shorten::MakeAShorterLink; 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; # Preloaded methods go here. sub makeashorterlink ($) { my $masl = 'http://www.makeashorterlink.com/index.php'; my $url = shift or croak 'No URL passed to makeashorterlink'; my $ua = __PACKAGE__->ua(); my $resp = $ua->post($masl, [ url => $url ]); return unless $resp->is_success; if ($resp->content =~ m!Your shorter link is: !) { return $1; } elsif ($resp->content =~ m!

URL already short:

!) { return $url; } return; } sub makealongerlink ($) { my $masl_url = shift or croak 'No MASL key / URL passed to makealongerlink'; my $ua = __PACKAGE__->ua(); $masl_url = "http://www.makeashorterlink.com/?$masl_url" unless $masl_url =~ m!^http://!i; my $resp = $ua->get($masl_url); return undef unless $resp->is_success; return undef if $resp->content =~ m!That doesn\'t look like a Make A Shorter Link key.!; if ($resp->content =~ m! will call the MASL web site passing it your long URL and will return the shorter MASL version. The function C does the reverse. C will accept as an argument either the full MASL URL or just the MASL identifier. If the URL to be shortened is already as short, or shorter, than how MASL would make it, then the URL you gave is returned. If anything else goes wrong, then either function will return C. For more information, see L. =head2 EXPORT makeashorterlink, makealongerlink =head1 SUPPORT, LICENCE, THANKS and SUCH See the main L docs. =head1 AUTHOR Dave Cross Subtle modifications by Iain Truskett Original LWP hacking by Alex Page C idea by Simon Batistoni =head1 SEE ALSO L, L, L =cut