WWW::Shorten::Smallr - Perl interface to Smallr.com


WWW-Shorten-Smallr documentation Contained in the WWW-Shorten-Smallr distribution.

Index


Code Index:

NAME

Top

WWW::Shorten::Smallr - Perl interface to Smallr.com

SYNOPSIS

Top

  use WWW::Shorten::Smallr;

  use WWW::Shorten 'Smallr';

  my $short_url = makeashorterlink($long_url);

DESCRIPTION

Top

A Perl interface to the web site Smallr.com. Smallr maintains a database of long URLs, each of which has a unique identifier.

Functions

Top

EXPORT

makeashorterlink

SUPPORT, LICENCE, THANKS and SUCH

Top

See the main WWW::Shorten docs.

AUTHOR

Top

Dean Wilson <dean.wilson@gmail.com>

SEE ALSO

Top

WWW::Shorten, perl, http://smallr.com/


WWW-Shorten-Smallr documentation Contained in the WWW-Shorten-Smallr distribution.
package WWW::Shorten::Smallr;
use strict;
use warnings;
use Carp;

use base qw( WWW::Shorten::generic Exporter );

our @EXPORT = qw(makeashorterlink);
our $VERSION = '0.01';

sub makeashorterlink ($)
{
  my $smallr = 'http://smallr.com/url/make';
  my $base_url = 'http://smallr.com/';
  my $url = shift or croak 'No URL passed to makeashorterlink';
  my $ua = __PACKAGE__->ua();

  my $resp = $ua->post($smallr,
                       [ url => $url, submit => 'submit' ]);

  return unless $resp->is_success;

  if ($resp->content =~ m!<h2 id="shortUrl"><a href="/(.*?)"!) {
  #if ($resp->content =~ m!Your shorter link is: <a href="(.*?)">!) {
      return "$base_url$1";
  }
  return;
}

1;

__END__