have with_actions return the recheck list
[scpubgit/DX.git] / lib / DX / Hypothesis.pm
index db9364f..931cd0c 100644 (file)
@@ -24,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,
@@ -75,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($_)
@@ -87,8 +89,14 @@ sub but_recheck_for {
 }
 
 sub with_resolution {
-  my ($self, $prop, $depends) = @_;
-  $self->but(
+  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(
                                       $prop,