skip backtracking rspaces with no alternatives left
[scpubgit/DX.git] / lib / DX / Step / Backtrack.pm
1 package DX::Step::Backtrack;
2
3 use DX::Class;
4
5 with 'DX::Role::Step';
6
7 #has resolution_space => (is => 'ro', isa => ResolutionSpace, required => 1);
8
9 sub apply_to {
10   my ($self, $ss) = @_;
11   trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ];
12   foreach my $adj (@{$ss->decisions_taken}) {
13     my ($rspace_was, $ss_was) = @$adj;
14     next unless @{$rspace_was->remaining_resolution_space->members};
15     trace rspace => [ statement => [
16       [ symbol => 'remaining' ],
17       @{$rspace_was->remaining_resolution_space->for_deparse->[1]}
18     ] ];
19     return $ss_was->but(
20       next_step => $rspace_was->remaining_resolution_space->next_step
21     );
22   }
23   return $ss->but(next_step => $ss->on_exhaustion_step);
24 }
25
26 1;