+sub insert_path {
+ my $self = shift;
+ my $ref = $self->path;
+ my $i = $self->{'path_i'} || 0;
+ if ($i + 1 > $#$ref) {
+ push @$ref, @_;
+ } else {
+ splice(@$ref, $i + 1, 0, @_); # insert a path at the current location
+ }
+}
+
+sub jump {
+ my $self = shift;
+ my $i = @_ == 1 ? shift : 1;
+ my $path = $self->path;
+ my $path_i = $self->{'path_i'};
+ croak "Can't jump if nav_loop not started" if ! defined $path_i;
+
+ if ($i =~ /^\w+$/) {
+ if ( $i eq 'FIRST' ) { $i = - $path_i - 1 }
+ elsif ($i eq 'LAST' ) { $i = $#$path - $path_i }
+ elsif ($i eq 'NEXT' ) { $i = 1 }
+ elsif ($i eq 'CURRENT' ) { $i = 0 }
+ elsif ($i eq 'PREVIOUS') { $i = -1 }
+ else { # look for a step by that name
+ for (my $j = $#$path; $j >= 0; $j --) {
+ if ($path->[$j] eq $i) {
+ $i = $j - $path_i;
+ last;
+ }
+ }
+ }
+ }
+ croak "Invalid jump index ($i)" if $i !~ /^-?\d+$/;
+
+ ### manipulate the path to contain the new jump location
+ my $cut_i = $path_i + $i;
+ my @replace = ($cut_i > $#$path) ? $self->default_step
+ : ($cut_i < 0) ? @$path
+ : @$path[$cut_i .. $#$path];
+ $self->replace_path(@replace);
+
+ $self->{'jumps'} = ($self->{'jumps'} || 0) + 1;
+
+ $self->{'path_i'}++; # move along now that the path is updated
+ $self->nav_loop; # recurse on the path
+ $self->exit_nav_loop;
+}
+
+sub js_uri_path {
+ my $self = shift;
+ my $script = $self->script_name;
+ my $js_step = $self->js_step;
+ return ($self->can('path') == \&CGI::Ex::App::path)
+ ? $script .'/'. $js_step # try to use a cache friendly URI (if path is our own)
+ : $script . '?'.$self->step_key.'='.$js_step.'&js='; # use one that works with more paths
+}
+
+
+sub morph {
+ my $self = shift;
+ my $step = shift || return;
+ my $allow = $self->run_hook('allow_morph', $step) || return;
+ my $lin = $self->{'_morph_lineage'} ||= [];
+ my $cur = ref $self; # what are we currently
+ push @$lin, $cur; # store so subsequent unmorph calls can do the right thing
+
+ my $hist = {step => $step, meth => 'morph', found => 'morph', time => time, elapsed => 0, response => 0};
+ push @{ $self->history }, $hist if ! $self->{'no_history'};
+
+ if (ref($allow) && ! $allow->{$step}) { # hash - but no step - record for unbless
+ $hist->{'found'} .= " (not allowed to morph to that step)";
+ return 0;
+ }
+
+ ### make sure we haven't already been reblessed