1 package DX::Step::ResolveProposition;
3 use DX::Step::EnterRecheck;
4 use DX::Step::Backtrack;
6 use Types::Standard qw(ArrayRef);
7 use DX::Utils qw(deparse step);
11 with 'DX::Role::Step';
13 has resolves => (is => 'ro', isa => Proposition);
15 has resolution_space => (is => 'ro', isa => ResolutionSpace);
17 has current_resolution => (is => 'lazy', init_arg => undef, builder => sub {
19 $self->resolution_space->next_resolution;
22 has actions => (is => 'lazy', init_arg => undef, builder => sub {
24 $self->current_resolution->actions;
27 has depends_on => (is => 'lazy', init_arg => undef, builder => sub {
29 my $_expand_dep = sub {
30 my ($type, @path) = @{$_[0]};
32 ref() ? @{$_->value_path or return ()} : $_
34 return [ $type, @expanded ];
36 [ map $_expand_dep->($_),
37 @{$self->current_resolution->veracity_depends_on} ];
40 has alternative_step => (is => 'lazy', init_arg => undef, builder => sub {
42 my $rspace = $self->resolution_space->remaining_resolution_space;
43 return undef unless @{$rspace->members};
45 resolves => $self->resolves,
46 resolution_space => $rspace
51 my ($self, @actions) = @_;
52 $self->but(actions => [ @actions, @{$self->actions} ]);
55 sub but_with_dependencies_on {
56 my ($self, @deps) = @_;
57 $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
61 my ($self, $old_ss) = @_;
63 if (my $prop = $old_ss->next_proposition) {
64 DX::Step::ConsiderProposition->new(
68 $old_ss->on_solution_step
71 my $ss = $old_ss->but(
74 ? (adjustments_made => [
76 @{$old_ss->adjustments_made}
81 my $new_ss = $self->_apply_to_ss($ss);
82 return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_ss;
87 my ($self, $old_ss) = @_;
88 my $old_hyp = $old_ss->current_hypothesis;
89 (my $hyp, my @recheck) = $old_hyp->with_resolution(
90 $self->resolves, $self->depends_on, $self->actions
92 return undef unless $hyp;
93 return $self->_recheck_for(
94 $old_ss->but(current_hypothesis => $hyp),
100 my ($self, $old_ss, @recheck) = @_;
102 return $old_ss unless @recheck;
104 my $ss = $old_ss->but(
105 next_step => DX::Step::EnterRecheck->new(
106 proposition_list => \@recheck,
107 on_completion_step => $old_ss->next_step,
108 on_failure_step => DX::Step::Backtrack->new,