Commit | Line | Data |
a3104d41 |
1 | package DX::Step::ResolveProposition; |
9d759b64 |
2 | |
614f3d93 |
3 | use DX::Step::EnterRecheck; |
d6b0c811 |
4 | use DX::Step::CompleteResolution; |
7af7ed1e |
5 | use DX::Step::Backtrack; |
614f3d93 |
6 | |
c99dbb05 |
7 | use DX::Utils qw(expand_deps); |
614f3d93 |
8 | |
9d759b64 |
9 | use DX::Class; |
10 | |
3e465d5d |
11 | with 'DX::Role::Step'; |
9d759b64 |
12 | |
839c0018 |
13 | has resolution_space => (is => 'ro', isa => ResolutionSpace); |
3e465d5d |
14 | |
4aeeab1e |
15 | sub but_first { |
16 | my ($self, @actions) = @_; |
17 | $self->but(actions => [ @actions, @{$self->actions} ]); |
18 | } |
19 | |
0498469a |
20 | sub but_with_dependencies_on { |
21 | my ($self, @deps) = @_; |
22 | $self->but(depends_on => [ @{$self->depends_on}, @deps ]); |
23 | } |
24 | |
9d759b64 |
25 | sub apply_to { |
7af7ed1e |
26 | my ($self, $old_ss) = @_; |
ec22d762 |
27 | my $rspace = $self->resolution_space; |
28 | my $prop = $rspace->proposition; |
29 | my $res = $rspace->next_resolution; |
30 | my $vdeps = $res->veracity_depends_on; |
5b6cab1b |
31 | trace resolve => [ statement => [ |
32 | [ symbol => 'resolve' ], |
33 | [ block => [ |
34 | [ statement => [ |
35 | [ symbol => 'proposition' ], |
ec22d762 |
36 | @{$prop->for_deparse->[1]}, |
5b6cab1b |
37 | ] ], |
ec22d762 |
38 | (@{$res->actions} |
5b6cab1b |
39 | ? [ statement => [ |
40 | [ symbol => 'actions' ], |
ec22d762 |
41 | [ block => $res->actions ], |
5b6cab1b |
42 | ] ] |
43 | : ()), |
93de8fb0 |
44 | [ statement => [ |
45 | [ symbol => 'depends_on' ], |
6162b001 |
46 | [ block => [ |
47 | map [ statement => [ |
48 | [ symbol => (split '::', ${$_->[0]})[-1] ], |
93de8fb0 |
49 | [ value_path => [ @{$_}[1..$#$_] ] ] |
ec22d762 |
50 | ] ], @{$vdeps} |
93de8fb0 |
51 | ] ], |
52 | ] ], |
5b6cab1b |
53 | ] ] |
54 | ] ]; |
2ac94761 |
55 | my $old_hyp = $old_ss->current_hypothesis; |
77065529 |
56 | (my $hyp, my @recheck) = $old_hyp->with_resolution( |
ec22d762 |
57 | $prop, $vdeps, $res->actions |
cdca8723 |
58 | ); |
4e1bf3a6 |
59 | # Failure to have a $hyp here means an action was disallowed by policy |
60 | # or failed - unsure if "failed" should be permitted and unsure if policy |
61 | # checks belong in with_resolution |
b9314f34 |
62 | unless ($hyp) { |
353951dc |
63 | return $old_ss->but( |
b9314f34 |
64 | next_step |
65 | => $rspace->remaining_resolution_space->next_step |
66 | ); |
67 | } |
353951dc |
68 | my $next_step = DX::Step::CompleteResolution->new( |
69 | original_search_state => $old_ss, |
70 | resolution_space => $rspace, |
71 | ); |
72 | unless (@recheck) { |
73 | return $old_ss->but(next_step => $next_step, current_hypothesis => $hyp); |
74 | } |
75 | return $old_ss->but( |
8cf755df |
76 | current_hypothesis => $hyp, |
614f3d93 |
77 | next_step => DX::Step::EnterRecheck->new( |
31753090 |
78 | proposition_list => \@recheck, |
353951dc |
79 | on_completion_step => $next_step, |
54da7534 |
80 | resolution_space => $rspace, |
614f3d93 |
81 | ), |
310662b5 |
82 | ); |
9d759b64 |
83 | } |
84 | |
85 | 1; |