move backtracking into a 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) {
16 $cur->backtrack;
17 } else {
18 $self->for_state
19 }
20 };
21 my $state = $self->_current_state($start_state->run);
22 return +{
23 map +($_ => $state->scope_var($_)->bound_value), keys %{$state->scope}
24 };
25}
26
271;