$self->$code;
}
+sub apply_if {
+ my ($self, $predicate, $code) = @_;
+ if($predicate) {
+ local $_ = $self;
+ $self->$code;
+ }
+ else {
+ $self;
+ }
+}
+
sub to_html {
my $self = shift;
$self->zconfig->producer->html_from_stream($self->to_stream);
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use Test::More 'no_plan';
+
+use HTML::Zoom;
+
+my $template = <<HTML;
+<html>
+ <body></body>
+</html>
+HTML
+
+my $expect = <<HTML;
+<html>
+ <body>Hello</body>
+</html>
+HTML
+
+my $output = HTML::Zoom
+ ->from_html($template)
+ ->apply_if(1, sub { $_->select('body')->replace_content('Hello') })
+ ->to_html;
+
+is( $output => $expect, 'apply_if with a true predicate' );
+
+$output = HTML::Zoom
+ ->from_html($template)
+ ->apply_if(0, sub { $_->select('body')->replace_content('Hello') })
+ ->to_html;
+
+is( $output => $template, 'apply_if with a false predicate' );