From: Matt S Trout Date: Sat, 14 Apr 2018 16:05:12 +0000 (+0000) Subject: pass rspace to backtrack (as yet unused), tweak DependencyMap API X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=77bc0c6ec624fe585521bff7e9be61b70800d7ea;p=scpubgit%2FDX.git pass rspace to backtrack (as yet unused), tweak DependencyMap API --- diff --git a/lib/DX/DependencyMap.pm b/lib/DX/DependencyMap.pm index d1b8eb2..bd4707d 100644 --- a/lib/DX/DependencyMap.pm +++ b/lib/DX/DependencyMap.pm @@ -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; diff --git a/lib/DX/ResolutionSpace.pm b/lib/DX/ResolutionSpace.pm index 4d6eeb4..51b8490 100644 --- a/lib/DX/ResolutionSpace.pm +++ b/lib/DX/ResolutionSpace.pm @@ -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; diff --git a/lib/DX/ResolvedPropositionSet.pm b/lib/DX/ResolvedPropositionSet.pm index 89a3d5e..3a383b4 100644 --- a/lib/DX/ResolvedPropositionSet.pm +++ b/lib/DX/ResolvedPropositionSet.pm @@ -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,