};
}
+sub transform_content {
+ my ( $self, $code ) = @_;
+
+ my $replace = $self->replace_content(
+ sub {
+ $self->_stream_from_proto($code->($_));
+ }
+ );
+ sub {
+ my ( $evt, $stream ) = @_;
+
+ my $item_ref = $stream->next;
+ if ( $item_ref->{type} eq 'TEXT' ) {
+ local $_ = $item_ref->{raw};
+ return $replace->($evt, $stream);
+ }
+ else {
+ return $self->_stream_concat($evt, $stream);
+ }
+ };
+}
+
sub collect {
my ($self, $options) = @_;
my ($into, $passthrough, $content, $filter, $flush_before) =
->select('title, #greeting')
->replace_content('Hello world!');
+=head2 transform_content
+
+Given a "select" in HTML::Zoom result, transform the content with a code
+reference. This allows you for example to localize your template text
+elements or doing anything else with the node's text content.
+
+ $html_zoom
+ ->select('a')
+ ->transform_content(
+ sub {
+ "please click on: $_"
+ },
+ );
+
=head2 repeat
For a given selection, repeat over transformations, typically for the purposes
'transform_attribute on nonexistent att does not add it if code returns undef',
);
+($expect = $tmpl) =~ s{(</span>)}{ What ever$1}g;
+
+is(
+ ( run_for {
+ $_->transform_content( sub { "$_ What ever" } ),
+ } 'span'
+ ),
+ $expect,
+ 'transform_content works for multiple selected elements',
+ );
+
+($expect = $tmpl) =~ s{(<span class="career">Builder)}{$1 What ever};
+
+is(
+ ( run_for {
+ $_->transform_content( sub { "$_ What ever" } ),
+ } 'span.career'
+ ),
+ $expect,
+ 'transform_content works for one specific selected element',
+ );
($expect = $tmpl) =~ s/(?=<div)/O HAI/;