};
}
my $repeater = sub {
- my $s = $self->_stream_from_proto($repeat_for);
+ my $s = ref($repeat_for) eq 'CODE'
+ ? $self->_stream_from_code($repeat_for) # $repeat_for is iterator
+ : $self->_stream_from_proto($repeat_for);
# We have to test $repeat_between not @between here because
# at the point we're constructing our return stream @between
# hasn't been populated yet - but we can test @between in the
use warnings FATAL => 'all';
use HTML::Zoom;
-use HTML::Zoom::CodeStream;
-
use Test::More;
-
-# turns iterator into stream
-sub code_stream (&) {
- my $code = shift;
- return sub {
- HTML::Zoom::CodeStream->new({
- code => $code,
- });
- }
-}
-
my $tmpl = <<'TMPL';
<body>
<div class="item">
foreach my $flush (0..1) {
# from HTML::Zoom manpage, slightly modified
- my $z2 = $zoom->select('.item')->repeat(code_stream {
+ my $z2 = $zoom->select('.item')->repeat(sub {
if (my $name = shift @list) {
return sub { $_->select('.item-name')->replace_content($name) }
} else {
--- /dev/null
+use strict;
+use HTML::Zoom;
+use Test::More;
+
+my $z = HTML::Zoom->from_html(<<'HTML');
+<html>
+<body>
+<div id="foo"><p></p></div>
+</body>
+</html>
+HTML
+
+my @list = qw(foo bar baz);
+my $iter = sub { shift @list };
+
+my $actual = $z->select("#foo")->repeat(sub {
+ my $e = $iter->() or return;
+ return sub {
+ $_->select("#foo")->set_attribute({name => 'id', value => $e})
+ ->select("p")->replace_content($e);
+ };
+})->to_html;
+my $expected = <<'HTML';
+<html>
+<body>
+<div id="foo"><p>foo</p></div><div id="bar"><p>bar</p></div><div id="baz"><p>baz</p></div>
+</body>
+</html>
+HTML
+
+is($actual, $expected, 'repeat with iterator works');
+
+@list = qw(foo bar baz);
+$actual = $z->select("#foo")->repeat([
+ map {
+ my $e = $_;
+ sub {
+ $_->select("#foo")->set_attribute({name => 'id', value => $e})
+ ->select("p")->replace_content($e);
+ }
+ } @list
+])->to_html;
+
+is($actual, $expected, 'repeat with array of transforms works');
+
+done_testing;
+++ /dev/null
-use strict;
-use HTML::Zoom;
-use Test::More skip_all => "Totally doesn't work yet";
-
-my $z = HTML::Zoom->from_html(<<HTML);
-<html>
-<body>
-<div id="foo"><p/></div>
-</body>
-</html>
-HTML
-
-my @list = qw(foo bar baz);
-my $iter = sub { shift @list };
-
-$z->select("#foo")->repeat(sub {
- my $e = $iter->() or return;
- return sub { $_->select("p")->replace_content($e) };
-})->to_html;
-
-ok 1;
-
-done_testing;