sub force_backtrack {
my ($self) = @_;
my $new_ss = $self->current_search_state->force_backtrack;
- return undef unless $new_ss;
+ # XXX infinite loop without the next line and I'm unsure why we don't
+ # get a loop-ending undef from elsewhere if the backtrack failed
+ return undef unless $new_ss->next_step;
return $self->but(current_search_state => $new_ss);
}
sub force_backtrack {
my ($self) = @_;
- my ($first_alt, @rest_alt) = @{$self->adjustments_made};
- return undef unless $first_alt;
return $self->but(
next_step => DX::Step::Backtrack->new,
)->with_one_step;
sub apply_to {
my ($self, $ss) = @_;
- my ($first_alt, @rest_alt) = @{$ss->adjustments_made};
- return $ss->but(next_step => $ss->on_exhaustion_step) unless $first_alt;
- return $first_alt->[1]->but(next_step => $first_alt->[0]->alternative_step);
+ foreach my $adj (@{$ss->adjustments_made}) {
+ my ($step_was, $ss_was) = @$adj;
+ if (my $alt = $step_was->alternative_step) {
+ return $ss_was->but(next_step => $alt);
+ }
+ }
+ return $ss->but(next_step => $ss->on_exhaustion_step);
}
1;
my $alt_step = $self->alternative_step;
my $ss = $old_ss->but(
next_step => $ns,
- ($alt_step
+ (@{$self->actions}
? (adjustments_made => [
[ $self, $old_ss ],
@{$old_ss->adjustments_made}