[dancer-users] Scope of 'hook before'

Rick Westerman westerman at purdue.edu
Tue Mar 1 21:35:58 GMT 2016


Hello.  New Dancer2 user here.  I am having problems with the scope of a 
'hook before' while using 'prefix'.  I am not sure if I am doing 
something dumb or if this is simply not possible or something else is 
going on.

Using the prefix example from the Cookbook I have two modules

package myapp;
use Dancer2;
use myapp::admin;

prefix undef;
get '/' => sub { return 'main ' . dancer_version };
1;

And

package myapp::admin;
use Dancer2 appname => 'myapp';

prefix '/admin';

hook 'before' => sub {
     if (dancer_app->environment ne 'rick') {
         return halt;
     }
};

get '/' => sub { return 'admin' };
1;

As expected when running with environment 'rick' then the following 
output is produced:

/        ==> main 0.166001
/admin/  ==> admin

But, unexpectedly to me, using the default 'development' environment has 
the app just halting as it, I presume, hits the 'hook before'.    I 
would have expected '/' to return with 'main 0.166001' while '/admin/' 
to halt.   In other words I would expect that the 'hook before' is kept 
within the scope of the prefix '/admin' and not bleed over to the undef 
prefix.

Any ideas on what is happening?

Thanks,

-- 
Rick Westerman
westerman at purdue.edu

Bioinformatics specialist at the Genomics Facility.
Phone: (765) 494-0505           FAX: (765) 496-7255
Department of Horticulture and Landscape Architecture
625 Agriculture Mall Drive
West Lafayette, IN 47907-2010
Physically located in room S049, WSLR building

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20160301/d3585c5c/attachment.html>


More information about the dancer-users mailing list