From 6aa6b0159ed49df061356c9d5060ae3a3e08fe6e Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Wed, 25 Feb 2015 05:55:36 +0100 Subject: [PATCH] current can be confused with the current route --- Changes | 3 ++- lib/Mojolicious/Routes.pm | 12 ++++++------ lib/Mojolicious/Routes/Match.pm | 16 ++++++++-------- t/mojolicious/lib/MojoliciousTest/Foo.pm | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index eb66f3d22c..cbbe4654ac 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/Mojolicious/Routes.pm b/lib/Mojolicious/Routes.pm index 70b474a800..02ff748f8d 100644 --- a/lib/Mojolicious/Routes.pm +++ b/lib/Mojolicious/Routes.pm @@ -20,10 +20,10 @@ 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; @@ -31,10 +31,10 @@ sub continue { @$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; } diff --git a/lib/Mojolicious/Routes/Match.pm b/lib/Mojolicious/Routes/Match.pm index a0e80af34e..76d9f798b2 100644 --- a/lib/Mojolicious/Routes/Match.pm +++ b/lib/Mojolicious/Routes/Match.pm @@ -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]) } @@ -130,13 +130,6 @@ structures. L implements the following attributes. -=head2 current - - my $current = $match->current; - $match = $match->current(2); - -Current position on the L, defaults to C<0>. - =head2 endpoint my $route = $match->endpoint; @@ -145,6 +138,13 @@ Current position on the L, defaults to C<0>. The route endpoint that matched, usually a L object. +=head2 position + + my $position = $match->position; + $match = $match->position(2); + +Current position on the L, defaults to C<0>. + =head2 root my $root = $match->root; diff --git a/t/mojolicious/lib/MojoliciousTest/Foo.pm b/t/mojolicious/lib/MojoliciousTest/Foo.pm index 3237fa90dc..ae5ac66929 100644 --- a/t/mojolicious/lib/MojoliciousTest/Foo.pm +++ b/t/mojolicious/lib/MojoliciousTest/Foo.pm @@ -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; } );