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) = @_;
62 trace resolve => [ statement => [
63 [ symbol => 'resolve' ],
66 [ symbol => 'proposition' ],
67 @{$self->resolves->for_deparse->[1]},
71 [ symbol => 'actions' ],
72 [ block => [ @{$self->actions} ] ],
76 [ symbol => 'depends_on' ],
79 (split '::', ${$_->[0]})[-1],
80 [ value_path => [ @{$_}[1..$#$_] ] ]
81 ], @{$self->depends_on}
87 if (my $prop = $old_ss->next_proposition) {
88 DX::Step::ConsiderProposition->new(
92 $old_ss->on_solution_step
95 my $ss = $old_ss->but(
98 ? (adjustments_made => [
100 @{$old_ss->adjustments_made}
105 my $new_ss = $self->_apply_to_ss($ss);
106 return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_ss;
111 my ($self, $old_ss) = @_;
112 my $old_hyp = $old_ss->current_hypothesis;
113 (my $hyp, my @recheck) = $old_hyp->with_resolution(
114 $self->resolves, $self->depends_on, $self->actions
116 return undef unless $hyp;
117 return $self->_recheck_for(
118 $old_ss->but(current_hypothesis => $hyp),
124 my ($self, $old_ss, @recheck) = @_;
126 return $old_ss unless @recheck;
128 my $ss = $old_ss->but(
129 next_step => DX::Step::EnterRecheck->new(
130 proposition_list => \@recheck,
131 on_completion_step => $old_ss->next_step,
132 on_failure_step => DX::Step::Backtrack->new,