1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
my $pkg;
BEGIN {
$pkg = 'Catmandu::IterableOnce';
use_ok $pkg;
}
require_ok $pkg;
{
package T::IterableOnce;
use Catmandu::Sane;
use Moo;
with 'Catmandu::Iterable';
with $pkg;
sub generator {
my ($self) = @_;
my $data = [1 .. 3];
my $n = 0;
sub {
return $data->[$n++] if $n < @$data;
return;
};
}
}
my $iter = T::IterableOnce->new;
is_deeply $iter->to_array, [1, 2, 3], 'first iteration gives results';
is_deeply $iter->to_array, [], 'repeated iterations give no results';
done_testing;
|