From ced8c05434bdb32484eb862e356333dd163d4c86 Mon Sep 17 00:00:00 2001 From: David Precious Date: Wed, 15 Feb 2012 18:37:38 +0000 Subject: [PATCH 1/2] Provide the route handler to before hooks. When calling a before hook, pass a reference to the route handler about to be executed as a parameter. --- lib/Dancer/Renderer.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dancer/Renderer.pm b/lib/Dancer/Renderer.pm index c72c7fbe8..f881d2b3f 100644 --- a/lib/Dancer/Renderer.pm +++ b/lib/Dancer/Renderer.pm @@ -98,7 +98,7 @@ sub get_action_response { my $app = ($handler && $handler->app) ? $handler->app : Dancer::App->current(); # run the before filters, before "running" the route handler - Dancer::Factory::Hook->instance->execute_hooks('before'); + Dancer::Factory::Hook->instance->execute_hooks('before', $handler); # recurse if something has changed my $MAX_RECURSIVE_LOOP = 10; From 03665072c2660ea79b0eb2d58dd57ba398b149ef Mon Sep 17 00:00:00 2001 From: David Precious Date: Wed, 15 Feb 2012 18:39:10 +0000 Subject: [PATCH 2/2] Document that before hooks receive a route handler --- lib/Dancer.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Dancer.pm b/lib/Dancer.pm index bb2472465..920d6521a 100644 --- a/lib/Dancer.pm +++ b/lib/Dancer.pm @@ -638,7 +638,8 @@ Defines a before filter: }; The anonymous function given to C will be executed before executing a -route handler to handle the request. +route handler to handle the request. It will receive a reference to the route +handler about to be executed as its parameter. If the function modifies the request's C or C, a new search for a matching route is performed and the filter is re-executed.