hayajo/Mojolicious-Plugin-AccessControl — pull request #6 by oliverguenther (2014-04-11 10:16:04+00:00)
Title: Fix shift from arguments on cached routes.

The current plugin version does not execute a on_deny callback after the first execution.
This is due to the $args ref that is being shifted within. Further (cached) route calls are then missing the on_deny hash key and the route silently fails, leading to a 404 error.

The code below provides a minimal example on how to reproduce this bug.
On first execution, the 'Forbidden' text is rendered correctly, however upon reload with route caches, the request fails with a 404 instead, and Mojolicious reports that no route for '/' has been found.

The attached pull requests fixes this issue with no other side effects.

package Test;
use Mojo::Base 'Mojolicious';

sub startup {
my $self = shift;

$self->plugin('Mojolicious::Plugin::AccessControl');

my $r = $self->routes;
$r->get('/')->name('home')->to(cb => sub {
shift->render(text => 'Allowed');
})->over( 'access' => [
{ on_deny => sub {
my $self = shift;
$self->res->code(403);
$self->render( text => 'Forbidden');
}
},
# Remove comment to get 200 / Allowed output
# allow => '127.0.0.1',
deny => 'all',
]);
}
1;