3 use Return::MultiLevel qw(with_return);
7 has next_op => (is => 'ro', required => 1);
9 has return_stack => (is => 'ro', required => 1);
11 has by_id => (is => 'ro', required => 1);
13 has scope => (is => 'ro', required => 1);
15 has last_choice => (is => 'ro', required => 1);
18 my ($self, $name) = @_;
19 $self->by_id->{$self->scope->{$name}};
22 sub bind_stream_then {
23 my ($self, $var, $stream, $then) = @_;
24 warn "Binding ".$var->id." to $stream";
25 my $bound = $var->with_stream($stream);
27 by_id => { %{$self->by_id}, $var->id => $bound },
29 )->mark_choice($bound);
33 my ($self, $var) = @_;
35 last_choice => [ $self, $var ]
41 my ($state, $var) = ($self);
42 while (($state, $var) = @{$state->last_choice}) {
43 $var->bound_value; $var->clear_bound_value;
44 return $state->mark_choice($var) unless $var->bound_stream->is_exhausted;
46 if (our $No_Options_Handler) {
47 $No_Options_Handler->(undef);
53 my ($self, $then) = @_;
54 $self->new(%$self, next_op => $then);
61 local our $No_Options_Handler = $return;
62 while (my $op = $state->next_op) {
63 $state = $op->run($state);
70 $_[0]->then(DX::Op::FromCode->new(code => sub { $_[1]->backtrack }));