WWW::Shorten::Qurl - Perl interface to qurl.com


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

Index


Code Index:

NAME

Top

WWW::Shorten::Qurl - Perl interface to qurl.com

SYNOPSIS

Top

  use WWW::Shorten::Qurl;

  # or

  use WWW::Shorten 'Qurl';

  $short_url = makeashorterlink($long_url);

  $long_url  = makealongerlink($short_url);

DESCRIPTION

Top

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

Functions

Top

EXPORT

makeashorterlink, makealongerlink

SUPPORT, LICENCE, THANKS and SUCH

Top

See the main WWW::Shorten docs.

AUTHOR

Top

Dave Cross <dave@mag-sol.com>

SEE ALSO

Top

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


WWW-Shorten-Qurl documentation Contained in the WWW-Shorten-Qurl distribution.
# $Id$

package WWW::Shorten::Qurl;

use 5.006;
use strict;
use warnings;

use base qw( WWW::Shorten::generic Exporter );
our @EXPORT = qw( makeashorterlink makealongerlink );
our $VERSION = '2.01';

use Carp;

sub makeashorterlink ($)
{
    my $url = shift or croak 'No URL passed to makeashorterlink';
    my $ua = __PACKAGE__->ua();
    my $qurl = 'http://qurl.com/automate.php';
    my $resp = $ua->post($qurl, [
	url => $url,
	]);
    return undef unless $resp->is_success;
    my $content = $resp->content;
    return if $content eq $url;
    return $content;
}

sub makealongerlink ($)
{
    my $qurl = shift 
	or croak 'No Qurl key / URL passed to makealongerlink';
    my $ua = __PACKAGE__->ua();

    $qurl = "http://qurl.com/$qurl"
    unless $qurl =~ m!^http://!i;

    if ($qurl =~ m|^http://www\.|) {
      $qurl =~ s/www\.//;
    }

    my $resp = $ua->get($qurl);

    return unless $resp->is_redirect;
    my $url = $resp->header('Location');
    return $url;
}

1;

__END__