From: Matt S Trout Date: Wed, 17 Feb 2010 21:37:52 +0000 (+0000) Subject: switch replace to collect then emit, document that it isn't strictly required to... X-Git-Tag: release_0.009004~84 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=451b3b302656dab4035e430b0035f027d737a6a2 switch replace to collect then emit, document that it isn't strictly required to do it that way --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index dc03958..823ebf6 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -168,11 +168,17 @@ sub replace { my ($evt, $stream) = @_; my $emit = $self->_stream_from_array(@$events); my $coll = $self->collect($options)->(@_); + # For a straightforward replace operation we can, in fact, do the emit + # -before- the collect, and my first cut did so. However in order to + # use the captured content in generating the new content, we need + # the collect stage to happen first - and it seems highly unlikely + # that in normal operation the collect phase will take long enough + # for the difference to be noticeable return ($coll ? (ref $coll eq 'ARRAY' - ? [ $coll->[0], $self->_stream_concat($emit, $coll->[1]) ] - : $self->_stream_concat($emit, $coll) + ? [ $coll->[0], $self->_stream_concat($coll->[1], $emit) ] + : $self->_stream_concat($coll, $emit) ) : $emit );