From: Matt S Trout Date: Sun, 14 Jan 2018 21:19:24 +0000 (+0000) Subject: move ResolveProposition step over to rspace system X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=839c00187ec8fa2eaf2349ceabaec43a010be111;p=scpubgit%2FDX.git move ResolveProposition step over to rspace system --- diff --git a/lib/DX/Role/Predicate.pm b/lib/DX/Role/Predicate.pm index e3aa603..e2e76d6 100644 --- a/lib/DX/Role/Predicate.pm +++ b/lib/DX/Role/Predicate.pm @@ -4,30 +4,14 @@ use List::Util qw(reduce); use DX::Utils qw(step CONTENTS_OF); use DX::Role; -sub _possible_resolution_list { - my ($self, @args) = @_; - my $rspace = $self->_resolution_space_for(@args); - my @res; - while (my $next_res = $rspace->next_resolution) { - $rspace = $rspace->remaining_resolution_space; - push @res, step( - actions => $next_res->actions, - depends_on => $next_res->veracity_depends_on, - ); - } - return @res; -} - sub resolution_step_for { my ($self, $prop, @args) = @_; - my ($last, @rest) = reverse $self->_possible_resolution_list(@args); - return undef unless $last; - my $targ = $last->but(resolves => $prop); - $targ = $_->but( - alternative_step => $targ, - resolves => $prop - ) for @rest; - return $targ; + my $rspace = $self->_resolution_space_for(@args); + return undef unless @{$rspace->members}; + return step( + resolves => $prop, + resolution_space => $rspace + ); } 1; diff --git a/lib/DX/Step/ResolveProposition.pm b/lib/DX/Step/ResolveProposition.pm index 1edc2f2..07a0d5c 100644 --- a/lib/DX/Step/ResolveProposition.pm +++ b/lib/DX/Step/ResolveProposition.pm @@ -4,19 +4,48 @@ use DX::Step::EnterRecheck; use DX::Step::Backtrack; use Types::Standard qw(ArrayRef); -use DX::Utils qw(deparse); +use DX::Utils qw(deparse step); use DX::Class; with 'DX::Role::Step'; -has actions => (is => 'ro', isa => ArrayRef[Action], required => 1); - -has depends_on => (is => 'ro', isa => ArrayRef[DependencySpec], required => 1); - has resolves => (is => 'ro', isa => Proposition); -has alternative_step => (is => 'ro', isa => Step); +has resolution_space => (is => 'ro', isa => ResolutionSpace); + +has current_resolution => (is => 'lazy', init_arg => undef, builder => sub { + my ($self) = @_; + $self->resolution_space->next_resolution; +}); + +has actions => (is => 'lazy', init_arg => undef, builder => sub { + my ($self) = @_; + $self->current_resolution->actions; +}); + +has depends_on => (is => 'lazy', init_arg => undef, builder => sub { + my ($self) = @_; + my $_expand_dep = sub { + my ($type, @path) = @{$_[0]}; + my @expanded = map { + ref() ? @{$_->value_path or return ()} : $_ + } @path; + return [ $type, @expanded ]; + }; + [ map $_expand_dep->($_), + @{$self->current_resolution->veracity_depends_on} ]; +}); + +has alternative_step => (is => 'lazy', init_arg => undef, builder => sub { + my ($self) = @_; + my $rspace = $self->resolution_space->remaining_resolution_space; + return undef unless @{$rspace->members}; + return step( + resolves => $self->resolves, + resolution_space => $rspace + ); +}); sub but_first { my ($self, @actions) = @_; diff --git a/lib/DX/Types.pm b/lib/DX/Types.pm index 28b610a..3434bb2 100644 --- a/lib/DX/Types.pm +++ b/lib/DX/Types.pm @@ -7,6 +7,7 @@ use Type::Library (our @CLASSES = qw( Hypothesis Scope ResolvedPropositionSet Proposition DependencyMap PropositionSequence QueryState ShellState ShellSession SearchState + ResolutionSpace ResolutionStrategy Resolution )), (our @ROLES = qw( Step Action ActionPolicy Predicate Value