my ($evt, $stream) = @_;
my $emit = $self->_stream_from_proto($replace_with);
my $coll = &$coll_proto;
+ # if we're replacing the contents of an in place close
+ # then we need to handle that here
+ if ($options->{content}
+ && ref($coll) eq 'HASH'
+ && delete $coll->{is_in_place_close}
+ ) {
+ delete $coll->{raw};
+ my $close = $stream->next;
+ delete @{$close}{qw(is_in_place_close raw)};
+ $emit = $self->_stream_concat(
+ $emit,
+ $self->_stream_from_array($close),
+ );
+ }
# 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
# for the difference to be noticeable
return
($coll
- ? (ref $coll eq 'ARRAY'
+ ? (ref $coll eq 'ARRAY' # [ event, stream ]
? [ $coll->[0], $self->_stream_concat($coll->[1], $emit) ]
- : $self->_stream_concat($coll, $emit)
+ : (ref $coll eq 'HASH' # event or stream?
+ ? [ $coll, $emit ]
+ : $self->_stream_concat($coll, $emit))
)
: $emit
);
});
}
+sub then {
+ my ($self) = @_;
+ # see notes in HTML/Zoom.pm for why this needs to be fixed
+ $self->select($self->transform->selector);
+}
+
sub apply {
my ($self, $code) = @_;
local $_ = $self;
use strict;
use warnings FATAL => 'all';
use base qw(HTML::Zoom::SubObject);
+use HTML::Zoom::TransformedStream;
sub new {
my ($class, $args) = @_;
sub apply_to_stream {
my ($self, $stream) = @_;
- HTML::Zoom::FilterStream->new({
+ HTML::Zoom::TransformedStream->new({
stream => $stream,
- match => $self->match,
- filters => $self->filters,
+ transform => $self,
zconfig => $self->_zconfig,
});
}
use strict;
use warnings FATAL => 'all';
use base qw(HTML::Zoom::SubObject);
+use HTML::Zoom::Transform;
sub new {
my ($class, $args) = @_;
--- /dev/null
+package HTML::Zoom::TransformedStream;
+
+use strict;
+use warnings FATAL => 'all';
+use base qw(HTML::Zoom::FilterStream);
+
+sub new {
+ my ($class, $args) = @_;
+ $args->{selector} = $args->{transform}->selector;
+ $args->{match} = $args->{transform}->match;
+ $args->{filters} = $args->{transform}->filters;
+ my $new = $class->SUPER::new($args);
+ $new->{transform} = $args->{transform};
+ $new
+}
+
+sub transform { shift->{transform} }
+
+1;
} } @fields
])->to_html;
+warn $h;
+
ok 1;
done_testing;
my $zoom = HTML::Zoom->from_html('<p>Hello my name is <span id="name" /></p>');
my $html = $zoom->select('#name')->replace_content('Foo foo')->to_html;
-is($html, '<p>Hello my name is <span id="#name">Foo foo</span></p>');
+is($html, '<p>Hello my name is <span id="name">Foo foo</span></p>');