switch recheck to using an on_completion_step
[scpubgit/DX.git] / lib / DX / Step / EnterRecheck.pm
1 package DX::Step::EnterRecheck;
2
3 use DX::Step::CompleteRecheck;
4
5 use DX::Class;
6
7 with 'DX::Role::Step';
8
9 has proposition_list => (is => 'ro', required => 1);
10
11 has on_completion_step => (is => 'ro', required => 1);
12
13 sub apply_to {
14   my ($self, $old_ss) = @_;
15
16   my ($prop, @rest) = @{$self->proposition_list};
17
18   die "NOT YET DAMNIT" if @rest;
19
20   my $old_hyp = $old_ss->current_hypothesis;
21
22   # we should probably be doing something about pruning the scope
23   # but that's completely pointless until we have rules (and also,
24   # the lock_to_depth arg needs to come from the proposition somehow)
25
26   my $ap = DX::ActionPolicy::LockScope->new(
27     lock_to_depth => $old_hyp->scope->depth,
28     next_policy => $old_hyp->action_policy,
29   );
30
31   my $hyp = ref($old_hyp)->new(
32     scope => $old_hyp->scope,
33     resolved_propositions => DX::ResolvedPropositionSet->new_empty,
34     actions => [],
35     action_applications => [],
36     action_policy => $ap,
37   );
38
39   my $pseq = DX::PropositionSequence->new(
40     members => [ $prop ],
41     external_names => {},
42     internal_names => {},
43   );
44
45   trace 'step.recheck.hyp' => $hyp;
46
47   my $ss = DX::SearchState->new(
48     current_hypothesis => $hyp,
49     alternatives => [],
50     propositions => $pseq,
51     next_step => DX::Step::ConsiderProposition->new(
52                    proposition => $prop,
53                  ),
54     is_solution_state => 0,
55     on_exhaustion_step => undef,
56     on_solution_step => DX::Step::CompleteRecheck->new(
57       resume_search_state => $old_ss->but(
58         next_step => $self->on_completion_step
59       ),
60       was_recheck_for => $prop,
61     ),
62   );
63
64   return $ss;
65 }
66
67 1;