Plugin hooks and prefix
Hi all, If I do this: use Dancer ':syntax'; use Dancer::Plugin::Weborama::Authentication; prefix '/companyname' => sub { post '/bidder' => sub { ... }; }; I would very much like my Authentication plugin to register a 'before' hook which only fires if the /companynameprefix is set. What's the best way of doing this? Cheers, Ovid -- Live and work overseas - http://overseas-exile.blogspot.com/ Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl/
Hi, I would have the authentication plugin get a list of app name from the config, or from an init method. Then the plugin would add a before hook ( so on every route), in which it would get the app name, and return without doing anything if it's not in the list of app name. Does that make sense ? Sadly hooks are not per App. Dancer2 fixes that... On 22 March 2012 17:57, Ovid <curtis_ovid_poe@yahoo.com> wrote:
Hi all,
If I do this:
use Dancer ':syntax'; use Dancer::Plugin::Weborama::Authentication;
prefix '/companyname' => sub { post '/bidder' => sub { ... }; };
I would very much like my Authentication plugin to register a 'before' hook which only fires if the /companyname prefix is set. What's the best way of doing this?
Cheers, Ovid -- Live and work overseas - http://overseas-exile.blogspot.com/ Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl/
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Le 22 mars 2012 17:57, Ovid <curtis_ovid_poe@yahoo.com> a écrit :
Hi all,
If I do this:
use Dancer ':syntax'; use Dancer::Plugin::Weborama::Authentication;
prefix '/companyname' => sub { post '/bidder' => sub { ... }; };
I would very much like my Authentication plugin to register a 'before' hook which only fires if the /companyname prefix is set. What's the best way of doing this?
I'll do it that way: In the plugin: register 'before_hook_for_prefix' => sub { my ($prefix) = @_; hook 'before' => sub { if (request->path =~ /^$prefix/) { .... } }; }; And in the app: use MyPlugin; before_hook_for_prefix '/companies'; See the idea? Of course, that's one way, there must be many others.
----- Original Message -----
From: Alexis Sukrieh <sukria@sukria.net>
I'll do it that way:
In the plugin:
register 'before_hook_for_prefix' => sub { my ($prefix) = @_;
hook 'before' => sub { if (request->path =~ /^$prefix/) { .... } }; };
And in the app:
use MyPlugin;
before_hook_for_prefix '/companies';
See the idea?
Of course, that's one way, there must be many others.
Works like a charm and tests pass with flying colors. Thanks! Cheers, Ovid -- Live and work overseas - http://overseas-exile.blogspot.com/ Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl/
participants (3)
-
Alexis Sukrieh -
damien krotkine -
Ovid