use strict; use warnings; use Test::More; use HTML::Filter::Callbacks; my $filter = HTML::Filter::Callbacks->new; my @callbacks = ( foo => { start => sub { my $tag = shift; is $tag->name => 'foo', 'tag name is correct'; }, }, foo => { start => sub { my $tag = shift; is $tag->attr('name') => 'bar', 'got an attribute by name'; }, }, foo => { start => sub { my $tag = shift; like $tag->text => qr/comment/, 'got the right text including the comment'; }, }, script => { end => sub { my $tag = shift; like $tag->text => qr/javascript/, 'got the right text including the script'; }, }, ul => { end => sub { my $tag = shift; like $tag->text => qr/list 3/, 'note that this kind of thing may happen...'; }, }, img => { start => sub { my $tag = shift; $tag->add_attr(alt => 'alternative text'); like $tag->as_string => qr/]*alt="alternative text"/, 'added an attribute'; }, }, img => { start => sub { my $tag = shift; $tag->add_attr(src => 'bar'); my $html = $tag->as_string; like $html => qr/]*src="bar"/, 'replaced an attribute'; unlike $html => qr/]*src=[^>]*src=/, 'and not duped'; }, }, a => { start => sub { my $tag = shift; $tag->remove_attr('bad_attr'); my $html = $tag->as_string; unlike $html => qr/bad_attr/, 'removed an attribute by name'; }, }, a => { start => sub { my $tag = shift; $tag->remove_attr(qr/^on_/); my $html = $tag->as_string; unlike $html => qr/on_click/, 'removed an attribute by regexp'; }, }, a => { start => sub { my $tag = shift; $tag->replace_attr(href => 'http://example.com/?foo=bar&hoo=ver'); my $html = $tag->as_string; like $html => qr{\Qhttp://example.com/?foo=bar&hoo=ver}, 'replaced an attribute by name'; }, }, a => { start => sub { my $tag = shift; $tag->replace_attr(qr/^n/ => 'name'); my $html = $tag->as_string; like $html => qr/name="name"/, 'replaced an attribute by regexp'; }, }, div => { start => sub { my $tag = shift; $tag->remove_tag; my $html = $tag->as_string; unlike $html => qr/
qr/
div body

text


HTML