| 1 |
NAME |
| 2 |
|
| 3 |
WWW::Shorten::Simple - Factory wrapper around WWW::Shorten to avoid |
| 4 |
imports |
| 5 |
|
| 6 |
SYNOPSIS |
| 7 |
|
| 8 |
use WWW::Shorten::Simple; |
| 9 |
|
| 10 |
my $svc = WWW::Shorten::Simple->new('TinyURL'); |
| 11 |
my $short_url = $svc->shorten($long_url); |
| 12 |
my $canon_url = $svc->unshorten($short_url); |
| 13 |
|
| 14 |
DESCRIPTION |
| 15 |
|
| 16 |
WWW::Shorten::Simple is a wrapper (factory) around WWW::Shorten so that |
| 17 |
you can create an object representing each URL shortening service, |
| 18 |
instead of importing makeashorterlink function into your namespace. |
| 19 |
|
| 20 |
This allows you to call multiple URL shortening services in one |
| 21 |
package, for instance to call WWW::Shorten::RevCanonical to extract |
| 22 |
rev="canonical", fallback to bit.ly if username and API key are |
| 23 |
present, and then finally to TinyURL. |
| 24 |
|
| 25 |
use WWW::Shorten::Simple; |
| 26 |
|
| 27 |
my @shorteners = ( |
| 28 |
WWW::Shorten::Simple->new('RevCanonical'), |
| 29 |
WWW::Shorten::Simple->new('Bitly', $bitly_username, $bitly_api_key), |
| 30 |
WWW::Shorten::Simple->new('TinyURL'), |
| 31 |
); |
| 32 |
|
| 33 |
my $short_url; |
| 34 |
for my $shortener (@shorteners) { |
| 35 |
$short_url = eval { $shortener->shorten($long_url) } # eval to ignore errors |
| 36 |
and last; |
| 37 |
} |
| 38 |
|
| 39 |
This wrapper works with most WWW::Shorten implementation that |
| 40 |
implements the default makeashorterlink and makealongerlink functions. |
| 41 |
The options should be able to be passed as an optional parameters to |
| 42 |
makeashorterlink function. |
| 43 |
|
| 44 |
METHODS |
| 45 |
|
| 46 |
new |
| 47 |
|
| 48 |
$svc = WWW::Shorten::Simple->new('TinyURL'); |
| 49 |
$svc = WWW::Shorten::Simple->new('Bitly', $bitly_username, $bitly_api_key); |
| 50 |
|
| 51 |
Creates a new WWW::Shoten::Simple object. Takes a subclass name and |
| 52 |
optional parameters to makeashorterlink call. |
| 53 |
|
| 54 |
shorten |
| 55 |
|
| 56 |
my $short_url = $svc->shorten($url); |
| 57 |
|
| 58 |
Shortens the given URL. Aliases: makeashorterlink, short_link |
| 59 |
|
| 60 |
unshorten |
| 61 |
|
| 62 |
my $long_url = $svc->unshorten($short_url); |
| 63 |
|
| 64 |
Unshortens the given URL. Aliases: makealongerlink, long_link |
| 65 |
|
| 66 |
AUTHOR |
| 67 |
|
| 68 |
Tatsuhiko Miyagawa <[email protected]> |
| 69 |
|
| 70 |
LICENSE |
| 71 |
|
| 72 |
This library is free software; you can redistribute it and/or modify it |
| 73 |
under the same terms as Perl itself. |
| 74 |
|
| 75 |
SEE ALSO |
| 76 |
|
| 77 |
WWW::Shorten, WWW::Shorten::RevCanonical |
| 78 |
|