[dancer-users] Re : Before Hook hit multiple times.

Damien Krotkine dkrotkine at gmail.com
Thu Jan 3 17:58:07 GMT 2013



Le jeudi 3 janvier 2013 à 16:05, Alexis Sukrieh a écrit :

> And then, I raise the Dancer 2 flag:
>  
>  
> 2013/1/3 David Golden <xdg at xdg.me (mailto: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

Hi,

After reading some emails of people about this scoping, I think we have a hidden issue here:

Scoping hooks in a package is great and is a must have feature. However, as some people have pointed out it makes it very difficult to quickly add a hook on all routes if they are in multiple packages.  

We should accept that developers have the right to separate features by packages, and not oblige them to group routes and hooks per package.  

Celogeek mentioned that this can be worked around by using roles but not everybody ate fluent with them.  

So, I propose that one could specify the scope of a hook.  

By default a hook would be package-scoped. But we should make it possible to scope it to the whole application ( if that's possible), and also be able to scope it to a selection of routes, as David Golden mentioned.  

Maybe it's not the right solution, but at least you'll agree that there is an issue in the current state ( I think English speaking people say "red herring" :)   
  
>  
> 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 !~ //;
>     ...
>   };
>   
>  
>  
>  
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>  
>  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130103/0cf5402f/attachment.htm>


More information about the dancer-users mailing list