[Dancer-users] [RFC] Change in prefix / before functionality
Simon Wistow
simon at thegestalt.org
Mon Mar 28 21:51:11 CEST 2011
I'd really like to be able to do something like this
--- >8 ---
package MyApp;
use MyApp::Secret;
prefix 'undef';
before sub {
# do something
};
package MyApp::Secret;
prefix '/secret';
before sub {
return unless auth && auth->is_admin;
}
1;
--- >8 ---
Rather than having to have the before sub in the main MyApp do all my
auth work (or conditionally load resources or whatever).
However at the moment *all* before subs get run no matter what the route
is - if I put some warns in the before subs for MyApp and MyApp::Secret
I get
[78776] core @0.000241> request: GET / from 127.0.0.1 in
/Library/Perl/5.10.0/Dancer/Handler.pm l. 51
In the before for MyApp::Secret at
lib/MyApp/Secret.pm line 8, <DATA>
line 16.
In the before for MyApp at
lib/MyApp.pm line 9, <DATA> line
16.
[78776] core @0.000302> request: GET /secret from 127.0.0.1 in
/Library/Perl/5.10.0/Dancer/Handler.pm l. 51
In the before for MyApp::Secret at
lib/MyApp/Secret.pm line 8, <DATA>
line 16.
In the before for MyApp at
lib/MyApp.pm line 9, <DATA> line
16.
Perhaps a new method called before_prefix (and before_template_prefix)
or something to maintain backwards compatibility?
More information about the Dancer-users
mailing list