factor action execution out into solver method
Matt S Trout [Sun, 9 Feb 2014 19:20:55 +0000 (19:20 +0000)]
lib/DX/Solver.pm
t/dot_ssh.t

index e94e050..2042a10 100644 (file)
@@ -36,4 +36,12 @@ sub query {
   );
 }
 
+sub run_action {
+  my ($self, $action) = @_;
+  my @invalidate = $action->run;
+  while (my ($type, $value) = splice @invalidate, 0, 2) {
+    $self->facts->{$type}->remove_value($value);
+  }
+}
+
 1;
index 1c752a7..2e37b31 100644 (file)
@@ -262,9 +262,7 @@ is(
   scalar(my ($action) = $res[0]->actions), 1
 );
 
-my ($type, $value) = $action->run;
-
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($action);
 
 ok(!$path_status{'.ssh'}, 'Empty retracted');
 
@@ -343,9 +341,7 @@ is(scalar(my @act = $res[0]->actions), 2, 'Two actions');
 
 is(scalar(my ($poss) = grep !@{$_->dependencies}, @act), 1, 'One possible');
 
-($type, $value) = $poss->run;
-
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($poss);
 
 @res = keys_file()->results;
 
@@ -356,9 +352,7 @@ is(
   'One possible'
 );
 
-($type, $value) = $poss->run;
-
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($poss);
 
 @res = keys_file()->results;