have with_actions return the recheck list
[scpubgit/DX.git] / lib / DX / Hypothesis.pm
index 95c05f3..931cd0c 100644 (file)
@@ -11,10 +11,6 @@ has resolved_propositions => (
   is => 'ro', isa => ResolvedPropositionSet, required => 1
 );
 
-has outstanding_propositions => (
-  is => 'ro', isa => ArrayRef[Proposition], required => 1
-);
-
 has actions => (
   is => 'ro', isa => ArrayRef[Action], required => 1
 );
@@ -28,21 +24,23 @@ has action_policy => (is => 'ro', isa => ActionPolicy, required => 1);
 sub with_actions {
   my ($self, @actions) = @_;
   my $hyp = $self;
+  my @events;
   foreach my $act (@actions) {
     return undef unless $self->action_policy->allows($act);
-    ($hyp, my @events) = $act->dry_run($hyp);
-    return undef unless $hyp;
-    $hyp = $hyp->but_recheck_for(@events);
+    ($hyp, my @these_events) = $act->dry_run($hyp);
     return undef unless $hyp;
+    push @events, @these_events;
   }
-  return $hyp;
+  my ($still_resolved, @recheck) = $hyp->resolved_propositions
+                                       ->but_expire_for(@events);
+  return (
+    $hyp->but(resolved_propositions => $still_resolved),
+    @recheck
+  );
 }
 
 sub but_recheck_for {
-  my ($self, @events) = @_;
-  my ($still_resolved, @recheck) = $self->resolved_propositions
-                                        ->but_expire_for(@events);
-  return $self unless @recheck;
+  my ($self, @recheck) = @_;
 
   my $ap = DX::ActionPolicy::LockScope->new(
     lock_to_depth => $self->scope->depth,
@@ -55,7 +53,6 @@ sub but_recheck_for {
   my $hyp = ref($self)->new(
     scope => $self->scope,
     resolved_propositions => DX::ResolvedPropositionSet->new_empty,
-    outstanding_propositions => \@recheck,
     actions => [],
     action_applications => [],
     action_policy => $ap,
@@ -69,7 +66,7 @@ sub but_recheck_for {
 
   trace 'step.recheck.hyp' => $hyp;
 
-  my $ss = DX::SearchState->new_for($hyp, $pseq);
+  my $ss = DX::SearchProcess->new_for($hyp, $pseq);
 
   my $sol_ss = $ss->find_solution;
 
@@ -80,7 +77,7 @@ sub but_recheck_for {
 
   my $sol_rps = $sol_ss->current_hypothesis->resolved_propositions;
 
-  my $rps = $still_resolved;
+  my $rps = $self->resolved_propositions;
 
   $rps = $rps->with_updated_dependencies_for(
     $_, $sol_rps->dependencies_for($_)
@@ -91,16 +88,20 @@ sub but_recheck_for {
   return $self->but(resolved_propositions => $rps);
 }
 
-sub resolve_head_dependent_on {
-  my ($self, $depends) = @_;
-  my ($first, @rest) = @{$self->outstanding_propositions};
-  $self->but(
+sub with_resolution {
+  my ($self, $prop, $depends, $actions) = @_;
+  (my $hyp, my @recheck) = $self->with_actions(@$actions);
+  return undef unless $hyp;
+  if (@recheck) {
+    $hyp = $hyp->but_recheck_for(@recheck);
+    return undef unless $hyp;
+  }
+  $hyp->but(
     resolved_propositions => $self->resolved_propositions
                                   ->with_resolution_for(
-                                      $first,
+                                      $prop,
                                       $depends,
                                     ),
-    outstanding_propositions => \@rest,
   );
 }