move recheck logic into resolution step
Matt S Trout [Wed, 29 Jun 2016 21:27:33 +0000 (21:27 +0000)]
lib/DX/Hypothesis.pm
lib/DX/Step/ResolveProposition.pm

index 202f4ea..0131688 100644 (file)
@@ -39,55 +39,6 @@ sub with_actions {
   );
 }
 
-sub but_recheck_for {
-  my ($self, @recheck) = @_;
-
-  my $ap = DX::ActionPolicy::LockScope->new(
-    lock_to_depth => $self->scope->depth,
-    next_policy => $self->action_policy,
-  );
-
-  # we should probably be doing something about pruning the scope
-  # but that's completely pointless until we have rules
-
-  my $hyp = ref($self)->new(
-    scope => $self->scope,
-    resolved_propositions => DX::ResolvedPropositionSet->new_empty,
-    actions => [],
-    action_applications => [],
-    action_policy => $ap,
-  );
-
-  my $pseq = DX::PropositionSequence->new(
-    members => \@recheck,
-    external_names => {},
-    internal_names => {},
-  );
-
-  trace 'step.recheck.hyp' => $hyp;
-
-  my $ss = DX::SearchProcess->new_for($hyp, $pseq);
-
-  my $sol_ss = $ss->find_solution;
-
-  unless ($sol_ss) {
-    trace 'step.recheck.fail' => 'argh';
-    return undef;
-  }
-
-  my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
-
-  my $rps = $self->resolved_propositions;
-
-  $rps = $rps->with_updated_dependencies_for(
-    $_, $sol_rps->dependencies_for($_)
-  ) for @recheck;
-
-  trace 'step.recheck.done' => 'yay';
-
-  return $self->but(resolved_propositions => $rps);
-}
-
 sub with_resolution {
   my ($self, $prop, $depends, $actions) = @_;
   (my $hyp, my @recheck) = $self->with_actions(@$actions);
index 231839e..09064c7 100644 (file)
@@ -59,11 +59,58 @@ sub _apply_to_hyp {
   (my $hyp, my @recheck) = $old_hyp->with_resolution(
     $self->resolves, $self->depends_on, $self->actions
   );
-  return undef unless $hyp;
-  if (@recheck) {
-    $hyp = $hyp->but_recheck_for(@recheck);
+  return $self->_recheck_hyp_for($hyp, @recheck);
+}
+
+sub _recheck_hyp_for {
+  my ($self, $old_hyp, @recheck) = @_;
+  return undef unless $old_hyp;
+  return $old_hyp unless @recheck;
+
+  my $ap = DX::ActionPolicy::LockScope->new(
+    lock_to_depth => $old_hyp->scope->depth,
+    next_policy => $old_hyp->action_policy,
+  );
+
+  # we should probably be doing something about pruning the scope
+  # but that's completely pointless until we have rules
+
+  my $hyp = ref($old_hyp)->new(
+    scope => $old_hyp->scope,
+    resolved_propositions => DX::ResolvedPropositionSet->new_empty,
+    actions => [],
+    action_applications => [],
+    action_policy => $ap,
+  );
+
+  my $pseq = DX::PropositionSequence->new(
+    members => \@recheck,
+    external_names => {},
+    internal_names => {},
+  );
+
+  trace 'step.recheck.hyp' => $hyp;
+
+  my $ss = DX::SearchProcess->new_for($hyp, $pseq);
+
+  my $sol_ss = $ss->find_solution;
+
+  unless ($sol_ss) {
+    trace 'step.recheck.fail' => 'argh';
+    return undef;
   }
-  return $hyp;
+
+  my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
+
+  my $rps = $old_hyp->resolved_propositions;
+
+  $rps = $rps->with_updated_dependencies_for(
+    $_, $sol_rps->dependencies_for($_)
+  ) for @recheck;
+
+  trace 'step.recheck.done' => 'yay';
+
+  return $old_hyp->but(resolved_propositions => $rps);
 }
 
 1;