use strict; use warnings FATAL => 'all'; use HTML::Zoom; use Test::More; ok my $zoom = HTML::Zoom->new( { zconfig => { parser => 'HTML::Zoom::Parser::HTML::Parser' } } )->from_html(< Hi!

Test

Some Stuff

More Stuff

Even More Stuff

  1. First
  2. Stuff A
  3. Stuff B
  4. Stuff C
  5. Last

Even More stuff

Some Stuff

Sub Item

HTML ## Stub for testing the fill method to be ok my $title = sub { my ($z, $content) = @_; $z = $z->select('title')->replace_content($content); return $z; }; { ok my $z = HTML::Zoom->new( { zconfig => { parser => 'HTML::Zoom::Parser::HTML::Parser' } } ) ->from_html(q[]) ->select('ul') ->repeat_content( [ sub { $_->select('li')->replace_content('Real Life1') }, sub { $_->select('li')->replace_content('Real Life2') }, sub { $_->select('li')->replace_content('Real Life3') }, ], ) ->to_html; is $z, '', 'Got correct from repeat_content'; } { ok my $z = HTML::Zoom->new( { zconfig => { parser => 'HTML::Zoom::Parser::HTML::Parser' } } ) ->from_html(q[]) ->select('ul') ->repeat_content([ map { my $i = $_; +sub {$_->select('li')->replace_content("Real Life$i")} } (1,2,3) ]) ->to_html; is $z, '', 'Got correct from repeat_content'; } use HTML::Zoom::CodeStream; sub code_stream (&) { my $code = shift; return sub { HTML::Zoom::CodeStream->new({ code => $code, }); } } { my @list = qw(foo bar baz); ok my $z = HTML::Zoom->new( { zconfig => { parser => 'HTML::Zoom::Parser::HTML::Parser' } } ) ->from_html(q[]) ->select('ul') ->repeat_content(code_stream { if (my $name = shift @list) { return sub { $_->select('li')->replace_content($name) }; } else { return } }) ->to_html; is $z, '', 'Got correct from repeat_content'; } { my @list = qw(foo bar baz); ok my $z = HTML::Zoom->new( { zconfig => { parser => 'HTML::Zoom::Parser::HTML::Parser' } } ) ->from_html(q[]) ->select('ul') ->repeat_content(sub { HTML::Zoom::CodeStream->new({ code => sub { if (my $name = shift @list) { return sub { $_->select('li')->replace_content($name) }; } else { return } } }); }) ->to_html; is $z, '', 'Got correct from repeat_content'; } done_testing;