From: Matt S Trout Date: Sat, 6 Feb 2010 20:23:44 +0000 (+0000) Subject: test replace inside X-Git-Tag: release_0.009004~87 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=11cc25dd4b8378ed73eb43b140d97460abde0c62 test replace inside --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index e06d570..bccc856 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -128,18 +128,25 @@ sub append_inside { } sub replace { - my ($self, $events) = @_; + my ($self, $events, $options) = @_; sub { my ($evt, $stream) = @_; my $emit = $self->_stream_from_array(@$events); - my $coll = $self->collect->(@_); - return $coll ? $self->_stream_concat($emit, $coll) : $emit; + my $coll = $self->collect($options)->(@_); + return + ($coll + ? (ref $coll eq 'ARRAY' + ? [ $coll->[0], $self->_stream_concat($emit, $coll->[1]) ] + : $self->_stream_concat($emit, $coll) + ) + : $emit + ); }; } sub collect { - my ($self, $attrs) = @_; - my ($into, $passthrough, $inside) = @{$attrs}{qw(into passthrough inside)}; + my ($self, $options) = @_; + my ($into, $passthrough, $inside) = @{$options}{qw(into passthrough inside)}; sub { my ($evt, $stream) = @_; push(@$into, $evt) if $into && !$inside; diff --git a/t/actions.t b/t/actions.t index 625c48e..f369b13 100644 --- a/t/actions.t +++ b/t/actions.t @@ -179,4 +179,13 @@ is( 'collect w/inside collects correctly' ); +is( + run_for { $_->replace($ohai, { inside => 1 }) }, + ' +
O HAI
+ +', + 'replace w/inside' +); + done_testing;