Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created January 18, 2011 13:51
Show Gist options
  • Save xaicron/784452 to your computer and use it in GitHub Desktop.
Save xaicron/784452 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Test::More;
use HTML::Filter::Callbacks;
my $SKIP_TAGS = { map { $_ => 1 } qw(title textarea) };
my $code = sub {
my ($tag, $c) = @_;
my $text = $tag->text;
# note explain $tag;
return unless $text;
return if $SKIP_TAGS->{lc $tag->name};
$tag->text("yappo");
return 1;
};
my $html = do { local $/; <DATA> };
my $filter = HTML::Filter::Callbacks->new;
$filter->add_callbacks(
'*' => +{
start => $code,
# end => $code, ## not running
end => sub { $code->(@_) },
},
);
my $new_html = $filter->process($html);
note $new_html;
ok 1;
done_testing;
__END__
<html>
<head>
<title>hoge</title>
</head>
<body>
foo
<input name="foo" value="bar" />
<textarea>
baz
</textarea>
hoge
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment