[Dancer-users] [RFC] Change in prefix / before functionality

Simon Wistow simon at thegestalt.org
Mon Mar 28 23:45:50 CEST 2011


On Mon, Mar 28, 2011 at 10:38:56PM +0100, David Precious said:
> That's by design, but the before filter can always inplement whatever
> logic it wants, e.g.:
> 
> before sub {
>     if (request->{path} =~ m{^/secret} && !auth || !auth->is_admin) {
>         redirect '/login';
>     }
> };

That's what I currently do - and it's kind of ugly. I'd much rather that 
I could separate that code out into the different sub modules.

> In fact, you could use a route for this, e.g.:
> 
> prefix '/secret';
> any qr{.*} => sub {
>     redirect '/login' if !auth || !auth->is_admin;
>     pass;  # continue on to the next route which matches
> };
> 
> get '/foo' => sub { "Foo!" };

Hmm, yes - that would work. It still feels a little kludgy though. Also, 
how performant is that versus having a new type of begin? 




More information about the Dancer-users mailing list