goo.glのショートURLを作れるWWW::Shorten::Googleを使ってみた(use WWW::Shorten::Google)

Google短縮URLサービスgoo.glAPIを叩くモジュール「WWW::Shorten::Google」を使って、TwitterにPostするスクリプトを書いた。

#!/usr/bin/perl
# file: twitGoogleShorter.pl
# usage: twitGoogleShorter.pl ["Twit Message"]

use strict;
use warnings;
use utf8;
use Net::Twitter::Lite;
use WWW::Shorten::Google;
use WWW::Shorten 'Google';

my $twit = shift;
my $twitter = Net::Twitter::Lite->new(
    username => 'Your Username',
    password => 'Your Password',
);

if ($twit =~ m{https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+\$,%#]+}) {
    $twit = "$`" . makeashorterlink($&) . "$'";
    $twitter->update($twit);
    print "Twit Message!!: $twit\n";
} else {
    $twitter->update($twit);
    print "Twit Message!!: $twit\n";
}

__END__

こんな感じです。

$ ./twitGoogleShorter.pl "goo.glを使ってPost http://apiwiki.twitter.com/ 短くなった?"
Twit Message!!: goo.glを使ってPost http://goo.gl/XgUB 短くなった?


Google URL Shortener
GitHub - yappo/p5-WWW-Shorten-Google
YappoLogs: goo.gl の API を叩いて goo.gl のショートURLを作る WWW::Shorten::Google ってモジュールかいた