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(expand_deps);
11 with 'DX::Role::Step';
13 has resolves => (is => 'lazy', init_arg => undef, builder => sub {
15 $self->resolution_space->proposition;
18 has resolution_space => (is => 'ro', isa => ResolutionSpace);
20 has current_resolution => (is => 'lazy', init_arg => undef, builder => sub {
22 $self->resolution_space->next_resolution;
25 has actions => (is => 'lazy', init_arg => undef, builder => sub {
27 $self->current_resolution->actions;
30 has depends_on => (is => 'lazy', init_arg => undef, builder => sub {
32 expand_deps($self->current_resolution->veracity_depends_on);
35 has alternative_step => (is => 'lazy', init_arg => undef, builder => sub {
37 my $rspace = $self->resolution_space->remaining_resolution_space;
38 return undef unless @{$rspace->members};
39 return $rspace->next_step;
43 my ($self, @actions) = @_;
44 $self->but(actions => [ @actions, @{$self->actions} ]);
47 sub but_with_dependencies_on {
48 my ($self, @deps) = @_;
49 $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
53 my ($self, $old_ss) = @_;
54 trace resolve => [ statement => [
55 [ symbol => 'resolve' ],
58 [ symbol => 'proposition' ],
59 @{$self->resolves->for_deparse->[1]},
63 [ symbol => 'actions' ],
64 [ block => $self->actions ],
68 [ symbol => 'depends_on' ],
71 (split '::', ${$_->[0]})[-1],
72 [ value_path => [ @{$_}[1..$#$_] ] ]
73 ], @{$self->depends_on}
79 if (my $prop = $old_ss->next_proposition) {
80 DX::Step::ConsiderProposition->new(
84 $old_ss->on_solution_step
87 my $ss = $old_ss->but(
90 [ $self->resolution_space, $old_ss ],
91 @{$old_ss->decisions_taken}
94 my $new_ss = $self->_apply_to_ss($ss);
95 return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_ss;
100 my ($self, $old_ss) = @_;
101 my $old_hyp = $old_ss->current_hypothesis;
102 (my $hyp, my @recheck) = $old_hyp->with_resolution(
103 $self->resolves, $self->depends_on, $self->actions
105 return undef unless $hyp;
106 return $self->_recheck_for(
107 $old_ss->but(current_hypothesis => $hyp),
113 my ($self, $old_ss, @recheck) = @_;
115 return $old_ss unless @recheck;
117 my $ss = $old_ss->but(
118 next_step => DX::Step::EnterRecheck->new(
119 proposition_list => \@recheck,
120 on_completion_step => $old_ss->next_step,
121 on_failure_step => DX::Step::Backtrack->new,