WWW::Shorten::URLchen - Perl interface to URLchen.de


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

Index


Code Index:

NAME

Top

WWW::Shorten::URLchen - Perl interface to URLchen.de

SYNOPSIS

Top

  use WWW::Shorten 'URLchen';

  $short_url = makeashorterlink($long_url);
  $long_url  = makealongerlink($short_url);

DESCRIPTION

Top

A Perl interface to the web site urlchen.de. URLchen 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

Danijel Tasov <data@cpan.org>

SEE ALSO

Top

WWW::Shorten, perl, http://urlchen.de/


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

package WWW::Shorten::URLchen;
use strict;
use warnings;

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

use Carp;

sub makeashorterlink ($) {
    my $url = shift or croak 'No URL passed to makeashorterlink';
    my $ua = __PACKAGE__->ua();
    my $service_url = 'http://urlchen.de/';
    my $resp = $ua->post($service_url, [
	url => $url,
	source => "PerlAPI-$VERSION",
    ]);
    return undef unless $resp->is_redirect;
    return $resp->header('X-Location');
}

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

    $urlchen = "http://urlchen.de/$urlchen"
    unless $urlchen =~ m!^http://!i;

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

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

1;

__END__