package DX::Step::Backtrack;

use DX::Class;

with 'DX::Role::Step';

sub apply_to {
  my ($self, $ss) = @_;
  trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ];
  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;
