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,
41 trace 'search.backtrack.alt' => $alt_step;
44 ($hyp, $step) = @{shift(@alt)||[]};
45 trace 'search.backtrack.rewind_to' => $step;
52 while ($state and @{$state->current_hypothesis->outstanding_propositions}) {
53 $state = $state->with_one_step;
55 trace 'search.solution.hyp' => $state->current_hypothesis if $state;
61 my ($first_alt, @rest_alt) = @{$self->alternatives};
62 return undef unless $first_alt;
63 trace 'search.backtrack.forced' => $first_alt->[0];
64 return ref($self)->new(
65 current_hypothesis => $first_alt->[0],
66 resume_step => $first_alt->[1],
67 alternatives => \@rest_alt
71 sub find_next_solution {
73 return undef unless my $bt = $self->force_backtrack;
74 return $bt->find_solution;