Created
January 18, 2011 13:51
-
-
Save xaicron/784452 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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