pass rspace to backtrack (as yet unused), tweak DependencyMap API
Matt S Trout [Sat, 14 Apr 2018 16:05:12 +0000 (16:05 +0000)]
lib/DX/DependencyMap.pm
lib/DX/ResolutionSpace.pm
lib/DX/ResolvedPropositionSet.pm

index d1b8eb2..bd4707d 100644 (file)
@@ -16,11 +16,12 @@ sub new_empty {
   $class->new(deps => {}, revdeps => {});
 }
 
-sub with_entry_for {
+sub with_dependencies_for {
   my ($self, $for_id, $deps_for) = @_;
+  my $old_revdeps = $self->revdeps;
   my $new_revdeps = {
-    %{$self->revdeps},
-    $for_id => $deps_for,
+    %{$old_revdeps},
+    $for_id => [ @{$old_revdeps->{$for_id}||[]}, @$deps_for ],
   };
   my $new_deps = $self->_merge_deps_for(
     $self->deps, $for_id, @$deps_for
@@ -77,7 +78,7 @@ sub _mangle_deps {
   return $root->[0];
 }
 
-sub _dependents_of {
+sub dependents_of {
   my ($self, $event) = @_;
   my ($type, @path) = @$event;
   my $root = [ $self->deps ];
@@ -114,7 +115,7 @@ sub _dependents_of {
 sub but_expire_dependents_of {
   my ($self, @events) = @_;
   my @expired = keys %{{
-    map +($_ => 1), map $self->_dependents_of($_), @events
+    map +($_ => 1), map $self->dependents_of($_), @events
   }};
   # Didn't expire anything? Don't clone self
   return $self unless @expired;
index 4d6eeb4..51b8490 100644 (file)
@@ -54,8 +54,8 @@ sub remaining_resolution_space {
 
 sub next_step {
   my ($self) = @_;
-  return DX::Step::Backtrack->new unless @{$self->members};
-  return DX::Step::ResolveProposition->new(resolution_space => $self);
+  my $step_type = (@{$self->members} ? 'ResolveProposition' : 'Backtrack');
+  return "DX::Step::${step_type}"->new(resolution_space => $self);
 }
 
 1;
index 89a3d5e..3a383b4 100644 (file)
@@ -25,7 +25,7 @@ sub with_resolution_for {
   my ($self, $prop, $deps) = @_;
   my $id = my @already = @{$self->propositions};
   my $new_depmap = $self->dependency_map
-                        ->with_entry_for($id, $deps);
+                        ->with_dependencies_for($id, $deps);
   ref($self)->new(
     dependency_map => $new_depmap,
     propositions => [ @already, $prop ],
@@ -40,7 +40,7 @@ sub with_updated_dependencies_for {
   # 0 is valid, undef means the grep failed
   die "Unable to find $prop in proplist" unless defined $id;
   my $new_depmap = $self->dependency_map
-                        ->with_entry_for($id, $deps);
+                        ->with_dependencies_for($id, $deps);
   ref($self)->new(
     dependency_map => $new_depmap,
     propositions => \@props,