From: Matt S Trout Date: Thu, 18 Feb 2010 01:51:33 +0000 (+0000) Subject: pre-filter for collect/repeat/replace X-Git-Tag: release_0.009004~76 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=dae33531219f600d126f485532fd20e5ad1b4be1 pre-filter for collect/repeat/replace --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index e9c67d8..0659cca 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -84,7 +84,8 @@ sub remove_attribute { sub collect { my ($self, $options) = @_; - my ($into, $passthrough, $content) = @{$options}{qw(into passthrough content)}; + my ($into, $passthrough, $content, $filter) = + @{$options}{qw(into passthrough content filter)}; sub { my ($evt, $stream) = @_; # We wipe the contents of @$into here so that other actions depending @@ -101,6 +102,7 @@ sub collect { my $name = $evt->{name}; my $depth = 1; my $_next = $content ? 'peek' : 'next'; + $stream = $filter->($stream) if $filter; my $collector = $self->_stream_from_code(sub { return unless $stream; while (my ($evt) = $stream->$_next) { diff --git a/t/actions.t b/t/actions.t index d9b883a..790962f 100644 --- a/t/actions.t +++ b/t/actions.t @@ -262,4 +262,43 @@ is( 'repeat_content ok' ); +is( + run_for { + my @between; + $_->repeat_content( + [ + sub { + HTML::Zoom::CodeStream->from_array( + (filter + filter($_ => '.name' => $r_content->('mst')) + => '.career' => $r_content->('Chainsaw Wielder')), + HTML::Zoom::CodeStream->from_array(@between) + )->flatten + }, + sub { + filter + filter($_ => '.name' => $r_content->('mdk')) + => '.career' => $r_content->('Adminion') + }, + ], + { filter => sub { + filter $_[0] => 'hr' => sub { $_->collect({ into => \@between }) } + } + } + ) + }, + q{ +
+ mst + Chainsaw Wielder +
+ mdk + Adminion + +
+ +}, + 'repeat_content with filter ok' +); + done_testing;