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;
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) = @_;