[dancer-users] Before Hook hit multiple times.

Alexis Sukrieh sukria at sukria.net
Thu Jan 3 15:05:29 GMT 2013


And then, I raise the Dancer 2 flag:


2013/1/3 David Golden <xdg at xdg.me>

>
> Dancer doesn't (to my knowledge) have a way to have per-route hooks,
> or hooks for routes matching some criteria.
>
>     before qr{^/private} => sub { ... };
>
> (This is the sort of thing that I think Catalyst does with 'begin'
> actions in controllers.)
>
>
If you mean Dancer 1, you're right, if you mean Dancer 2, you're wrong.

In Dancer 2, everything is scoped to the "app" it's defined, so doing that
is preatty easy with D2:

  package SomeApp;

  hook 'before' => sub {
  };

  # some routes

In this case, only the routes defined in SomeApp will have the filters
defined. Only them. For more details about that feature, I suggest reading
that article: http://advent.perldancer.org/2012/7

Wouldn't that be a perfect opportunity to try a switch to Dancer 2?

PS: you could actually do it in Dancer 1 with a test in the before filter
like so:

  hook before => sub {
    return pass if request->path !~ //;
    ...
  };
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130103/dc9d8136/attachment.htm>


More information about the dancer-users mailing list