follow alternative rspace entries without backtracking, explicitly resolve
[scpubgit/DX.git] / lib / DX / Step / CompleteResolution.pm
diff --git a/lib/DX/Step/CompleteResolution.pm b/lib/DX/Step/CompleteResolution.pm
new file mode 100644 (file)
index 0000000..ef5a6f4
--- /dev/null
@@ -0,0 +1,34 @@
+package DX::Step::CompleteResolution;
+
+use DX::Class;
+
+with 'DX::Role::Step';
+
+has original_search_state => (
+  is => 'ro', isa => SearchState, required => 1
+);
+
+has resolution_space => (
+  is => 'ro', isa => ResolutionSpace, required => 1
+);
+
+sub apply_to {
+  my ($self, $old_ss) = @_;
+  my $orig_ss = $self->original_search_state;
+  my $ns = do {
+    if (my $prop = $orig_ss->next_proposition) {
+      $prop->consider_step
+    } else {
+      $old_ss->on_solution_step
+    }
+  };
+  return $old_ss->but(
+    next_step => $ns,
+    decisions_taken => [
+      [ $self->resolution_space, $orig_ss ],
+      @{$old_ss->decisions_taken}
+    ],
+  );
+}
+
+1;