[Dancer-users] Plugin hooks and prefix
Alexis Sukrieh
sukria at sukria.net
Fri Mar 23 16:19:53 CET 2012
Le 22 mars 2012 17:57, Ovid <curtis_ovid_poe at 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.
More information about the Dancer-users
mailing list