1 package DX::SearchState;
3 use Types::Standard qw(Maybe);
6 has current_hypothesis => (is => 'ro', isa => Hypothesis, required => 1);
8 has resume_step => (is => 'ro', isa => Maybe[Step]);
10 has alternatives => (is => 'ro', isa => AlternativeList, required => 1);
13 my ($class, $hyp) = @_;
15 current_hypothesis => $hyp,
22 my $hyp = $self->current_hypothesis;
23 my $step = $self->resume_step
24 || $hyp->head_proposition->resolve_for($hyp->scope);
25 my @alt = @{$self->alternatives};
28 my ($new_hyp, $alt_step) = $step->apply_to($hyp);
31 current_hypothesis => $new_hyp,
43 ($hyp, $step) = @{shift(@alt)||[]};
50 while ($state and @{$state->current_hypothesis->outstanding_propositions}) {
51 $state = $state->with_one_step;
58 my ($first_alt, @rest_alt) = @{$self->alternatives};
59 return undef unless $first_alt;
60 trace 'search.backtrack' => $first_alt->[0];
61 return ref($self)->new(
62 current_hypothesis => $first_alt->[0],
63 resume_step => $first_alt->[1],
64 alternatives => \@rest_alt
68 sub find_next_solution {
70 return undef unless my $bt = $self->force_backtrack;
71 return $bt->find_solution;