From: Matt S Trout Date: Sat, 26 Mar 2016 21:51:35 +0000 (+0000) Subject: re-arranging resolution - thread proposition through predicate invocation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ccf0d4fe8a87335c80e88325b2a2e00c679182f7;p=scpubgit%2FDX.git re-arranging resolution - thread proposition through predicate invocation --- diff --git a/lib/DX/Proposition.pm b/lib/DX/Proposition.pm index aa6f060..b682392 100644 --- a/lib/DX/Proposition.pm +++ b/lib/DX/Proposition.pm @@ -18,7 +18,7 @@ sub resolve_for { #if (my $step = $scope->known_facts->resolution_step_for($predicate, @args)) { # return $step; #} - return $predicate->resolution_step_for(@args); + return $predicate->resolution_step_for($self, @args); } 1; diff --git a/lib/DX/Role/Predicate.pm b/lib/DX/Role/Predicate.pm index 2a94ade..832150b 100644 --- a/lib/DX/Role/Predicate.pm +++ b/lib/DX/Role/Predicate.pm @@ -5,11 +5,14 @@ use DX::Utils qw(step CONTENTS_OF); use DX::Role; sub resolution_step_for { - my ($self, @args) = @_; + my ($self, $prop, @args) = @_; my ($last, @rest) = reverse $self->_possible_resolution_list(@args); return undef unless $last; - my $targ = $last; - $targ = $_->but_with_alternative_step($targ) for @rest; + my $targ = $last->but(resolves => $prop); + $targ = $_->but( + alternative_step => $targ, + resolves => $prop + ) for @rest; return $targ; } diff --git a/lib/DX/SearchState.pm b/lib/DX/SearchState.pm index 1053f48..38271b3 100644 --- a/lib/DX/SearchState.pm +++ b/lib/DX/SearchState.pm @@ -10,12 +10,16 @@ has next_step => (is => 'ro', isa => Maybe[Step]); has alternatives => (is => 'ro', isa => AlternativeList, required => 1); +sub next_proposition { $_[0]->current_hypothesis->head_proposition } + sub new_for { my ($class, $hyp) = @_; $class->new( current_hypothesis => $hyp, alternatives => [], - next_step => DX::Step::InvokeNextPredicate->new, + next_step => DX::Step::InvokeNextPredicate->new( + proposition => $hyp->head_proposition, + ), ); } @@ -34,7 +38,9 @@ sub with_one_step { : ()), @alt ], - next_step => DX::Step::InvokeNextPredicate->new, + next_step => DX::Step::InvokeNextPredicate->new( + proposition => $self->next_proposition, + ), ); } if ($alt_step) { diff --git a/lib/DX/Step/InvokeNextPredicate.pm b/lib/DX/Step/InvokeNextPredicate.pm index f4a68dd..510d013 100644 --- a/lib/DX/Step/InvokeNextPredicate.pm +++ b/lib/DX/Step/InvokeNextPredicate.pm @@ -4,9 +4,11 @@ use DX::Class; with 'DX::Role::Step'; +has proposition => (is => 'ro', required => 1); + sub apply_to { my ($self, $hyp) = @_; - return (undef, $hyp->head_proposition->resolve_for($hyp->scope)); + return (undef, $self->proposition->resolve_for($hyp->scope)); } 1; diff --git a/lib/DX/Step/Normal.pm b/lib/DX/Step/Normal.pm index b8ac7ed..9488e74 100644 --- a/lib/DX/Step/Normal.pm +++ b/lib/DX/Step/Normal.pm @@ -10,6 +10,8 @@ has actions => (is => 'ro', isa => ArrayRef[Action], required => 1); has depends_on => (is => 'ro', isa => DependencyGroupList, required => 1); +has resolves => (is => 'ro', isa => Proposition); + has alternative_step => (is => 'ro', isa => Step); sub but_first { @@ -22,11 +24,6 @@ sub but_with_dependencies_on { $self->but(depends_on => [ @{$self->depends_on}, @deps ]); } -sub but_with_alternative_step { - my ($self, $step) = @_; - bless { %$self, alternative_step => $step }, ref($self); -} - sub apply_to { my ($self, $old_hyp) = @_; trace 'step.apply.old_hyp '.$self => $old_hyp;