X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDX%2FState.pm;h=4815ab2360c5a5a74ef427d0bf418da57f110b14;hb=5622b4df271135b1574c6346e50f3812f55a7c68;hp=0ee431cbc8d9f9c144d8279d5d2cd93aeac92012;hpb=94565614cc7abfa71ad664816ba845bc6ea14741;p=scpubgit%2FDKit.git diff --git a/lib/DX/State.pm b/lib/DX/State.pm index 0ee431c..4815ab2 100644 --- a/lib/DX/State.pm +++ b/lib/DX/State.pm @@ -1,5 +1,7 @@ package DX::State; +use Return::MultiLevel qw(with_return); +use DX::Op::FromCode; use Moo; has next_op => (is => 'ro', required => 1); @@ -41,6 +43,9 @@ sub backtrack { $var->bound_value; $var->clear_bound_value; return $state->mark_choice($var) unless $var->bound_stream->is_exhausted; } + if (our $No_Options_Handler) { + $No_Options_Handler->(undef); + } die "Out of options"; } @@ -51,10 +56,18 @@ sub then { sub run { my ($state) = @_; - while (my $op = $state->next_op) { - $state = $op->run($state); + with_return { + my ($return) = @_; + local our $No_Options_Handler = $return; + while (my $op = $state->next_op) { + $state = $op->run($state); + } + return $state; } - return $state; +} + +sub push_backtrack { + $_[0]->then(DX::Op::FromCode->new(code => sub { $_[1]->backtrack })); } 1;