Catmandu

 view release on metacpan or  search on metacpan

t/Catmandu-IterableOnce.t  view on Meta::CPAN

#!/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;



( run in 0.478 second using v1.01-cache-2.11-cpan-71847e10f99 )