# Perl で短縮URLを展開する {{tag: perl, cpan}} ぱっと調べた感じだと {{cpan: WWW::Expand}} というモジュールがあったのだけど、{{cpan: LWP::UserAgent}} を HTTP クライアントに使っていて、{{cpan: Furl}} 欲しさを感じたので {{cpan: WWW::Expand::More}} というモジュールを書いた。 ## WWW::Expand::More 短縮URL を渡すと、展開する。 use WWW::Expand::More; my $expanded_url = WWW::Expand::More->expand('http://t.co/mxuRqUuDmX'); print $expanded_url; # http://bayashi.net/diary/2015/0606 timeout できる。 print WWW::Expand::More->expand('http://t.co/mxuRqUuDmX' => { timeout => 1, }); 展開結果をキャッシュして2度目は HTTPリクエストしない。 print WWW::Expand::More->expand('http://t.co/mxuRqUuDmX' => { cache => 1, # cache on memory }); ## expand_url {{cpan: expand_url}} という CLI コマンドが同梱されてるのでターミナルで展開とかできる。 $ expand_url http://bit.ly/1BPj30x https://www.google.com/search?q=Perl 短縮URLのリダイレクトが複数ある場合に全部出すとかできる。 $ expand_url http://bit.ly/1BPj30x --all http://bit.ly/1BPj30x https://goo.gl/dXwzqw https://www.google.com/search?q=Perl 詳細は {{cpan: WWW::Expand::More}} をどうぞ。 うぇーい