Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
current can be confused with the current route
  • Loading branch information
kraih committed Feb 25, 2015
1 parent 4782364 commit 6aa6b01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Changes
Expand Up @@ -23,8 +23,9 @@
- Removed deprecated render_exception and render_not_found methods from
Mojolicious::Controller.
- Removed deprecated keep_alive_requests setting from Hypnotoad.
- Renamed pattern attribute in Mojolicious::Routes::Route to unparsed.
- Renamed types attribute in Mojolicious::Types to mapping.
- Renamed current attribute in Mojolicious::Routes::Match to position.
- Renamed pattern attribute in Mojolicious::Routes::Route to unparsed.
- Renamed template attribute in Mojo::Template to unparsed.
- Renamed all_contents, contents, following_siblings, next_sibling,
preceding_siblings and previous_sibling methods in Mojo::DOM to
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -20,21 +20,21 @@ sub add_shortcut { $_[0]->shortcuts->{$_[1]} = $_[2] and return $_[0] }
sub continue {
my ($self, $c) = @_;

my $match = $c->match;
my $stack = $match->stack;
my $current = $match->current;
return _render($c) unless my $field = $stack->[$current];
my $match = $c->match;
my $stack = $match->stack;
my $position = $match->position;
return _render($c) unless my $field = $stack->[$position];

# Merge captures into stash
my $stash = $c->stash;
@{$stash->{'mojo.captures'} //= {}}{keys %$field} = values %$field;
@$stash{keys %$field} = values %$field;

my $continue;
my $last = !$stack->[++$current];
my $last = !$stack->[++$position];
if (my $cb = $field->{cb}) { $continue = $self->_callback($c, $cb, $last) }
else { $continue = $self->_controller($c, $field, $last) }
$match->current($current);
$match->position($position);
$self->continue($c) if $last || $continue;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/Mojolicious/Routes/Match.pm
Expand Up @@ -3,8 +3,8 @@ use Mojo::Base -base;

use Mojo::Util;

has current => 0;
has [qw(endpoint root)];
has position => 0;
has stack => sub { [] };

sub match { $_[0]->_match($_[0]->root, $_[1], $_[2]) }
Expand Down Expand Up @@ -130,13 +130,6 @@ structures.
L<Mojolicious::Routes::Match> implements the following attributes.
=head2 current
my $current = $match->current;
$match = $match->current(2);
Current position on the L</"stack">, defaults to C<0>.
=head2 endpoint
my $route = $match->endpoint;
Expand All @@ -145,6 +138,13 @@ Current position on the L</"stack">, defaults to C<0>.
The route endpoint that matched, usually a L<Mojolicious::Routes::Route>
object.
=head2 position
my $position = $match->position;
$match = $match->position(2);
Current position on the L</"stack">, defaults to C<0>.
=head2 root
my $root = $match->root;
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/lib/MojoliciousTest/Foo.pm
Expand Up @@ -64,10 +64,10 @@ sub stage2 { return shift->some_plugin }
sub suspended {
my $self = shift;

$self->res->headers->append('X-Suspended' => $self->match->current);
$self->res->headers->append('X-Suspended' => $self->match->position);
Mojo::IOLoop->next_tick(
sub {
$self->res->headers->append('X-Suspended' => $self->match->current);
$self->res->headers->append('X-Suspended' => $self->match->position);
$self->continue;
}
);
Expand Down

0 comments on commit 6aa6b01

Please sign in to comment.