Skip to content

Commit

Permalink
Make TwitPicThumb a subclass of HTTP since you can't use both.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart A Johnston committed Aug 28, 2011
1 parent 34d557a commit 6147e28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
30 changes: 12 additions & 18 deletions lib/Text/AutoLink/Plugin/TwitPicThumb.pm
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# Copyright (c) 2006 Daisuke Maki <dmaki@cpan.org>
# All rights reserved.

package Text::AutoLink::Plugin::TwitPicThumb;
use strict;
use warnings;
use base qw(Text::AutoLink::Plugin);
use base qw(Text::AutoLink::Plugin::HTTP);

sub process
sub linkfy
{
my $self = shift;
my $ref = shift;

$$ref =~ s/https?:\/\/twitpic.com\/([a-z0-9]+)/
$self->twitpic($1)
/gex;
}

sub twitpic
{
my $self = shift;
my $id = shift;

$self->linkfy(href => "http://twitpic.com/$id", img => "http://twitpic.com/show/thumb/$id");
my %args = @_;

my $url = $args{href};
my ($id) = $url =~ /https?:\/\/twitpic.com\/([a-z0-9]+)/;
if ($id) {
$self->SUPER::linkfy(href => "http://twitpic.com/$id", img => "http://twitpic.com/show/thumb/$id");
}
else {
$self->SUPER::linkfy(href => $1)
}
}

1;
Expand Down
7 changes: 6 additions & 1 deletion t/plugin/twitpic.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use strict;
use Test::More tests => 1;
use Test::More tests => 3;

BEGIN { use_ok("Text::AutoLink") }

Expand All @@ -9,3 +9,8 @@ my $text = $auto->parse_string(<<EOS);
EOS

like($text, qr{<a href="http://twitpic.com/1e10q"><img src="http://twitpic.com/show/thumb/1e10q"});

my $ret = $auto->parse_string(<<'EOS');
http://search.cpan.org/~dmaki/
EOS
is($ret, q{<a href="http://search.cpan.org/~dmaki/">http://search.cpan.org/~dmaki/</a>});

0 comments on commit 6147e28

Please sign in to comment.