test more complex stream
[scpubgit/DKit.git] / lib / DX / ResultStream.pm
CommitLineData
94565614 1package DX::ResultStream;
2
3use Moo;
4
5has for_state => (is => 'ro', required => 1);
6
7has _current_state => (is => 'rw');
8
9has is_exhausted => (is => 'rwp');
10
11sub next {
12 my ($self) = @_;
13 return if $self->is_exhausted;
14 my $start_state = do {
15 if (my $cur = $self->_current_state) {
5622b4df 16 $cur->push_backtrack;
94565614 17 } else {
18 $self->for_state
19 }
20 };
21 my $state = $self->_current_state($start_state->run);
5622b4df 22 unless ($state) {
23 $self->_set_is_exhausted(1);
24 return;
25 }
94565614 26 return +{
27 map +($_ => $state->scope_var($_)->bound_value), keys %{$state->scope}
28 };
29}
30
26300a7d 31sub results {
32 my ($self) = @_;
33 my @all;
34 while (my $next = $self->next) {
35 push @all, $next;
36 }
37 return @all;
38}
39
94565614 401;