-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Return::MultiLevel so forward & redirect can immediately return from current hook/route code. #485
Conversation
Move the code for calling before hooks and the route handler to its own (private) method. This will get wrapped by Return::MultiLevel to clean up forward/redirect DSL methods.
As suggested in PerlDancer#432, use Return::MultiLevel to wrap route dispatch. Cache the multilevel return coderef in the context for forward/redirect to use. Add Return::MultiLevel to prereqs and Scope::Upper to recommends.
Use the with_return handler to return immediatly to the dispatcher after the redirect details have been added to the response. Resolves PerlDancer#432.
…r forward. This is the implementation of "... after a forward is executed, any remaining code (route and hooks) from the current dispatch will never be run." from PerlDancer#432.
Include the description of forward and update that forward immediately returns form the current route/hook. Update redirect docs to reflect the immediate return from route/hook.
Looks very nice. Thanks for the PR. Any other core dev willing to upvote? 👍 |
I like this. 👍 @veryrusty! One note is that it optionally uses Scope::Upper, so we need to indicate that for speed, one should have that installed too, but not to require it (and make sure it's not required), because it's XS and that would break one of our assumptions: Dancer 2 is fatpackable by default. |
@xsawyerx - Should the documentation of all the recommended XS modules "for speed" be raised a a separate issue? Currently only Dancer2::Core::Request notes the two XS modules it uses (from a quick grep of the source), but there are several others listed as Prereqs/Recommends in dist.ini. (There is also no mention of fatpacking either.. I'll stop before I volunteer myself ;) ) Note that @shadowcat-mst commented in #432:
I've verified the test suite passes without Scope::Upper installed; though I'd take mst's experience over my quick check any day! |
On 10/05/2013 10:19 AM, Russell Jenkins wrote:
This should definitely be documented, both the XS recommends and the fact that Dancer2 must be fatpackable. Regards Perl and Dancer Development Visit our Open Source conference on E-commerce: |
+1 to what @racke said. |
Once PerlDancer#485 is merged, use the with_return handler to immediately stop processing a before hook or route handler. Includes tests for use in a reoute handler and a before hook. Resolves PerlDancer#472.
Thanks a lot @veryrusty, patch merged. That's good stuff ;) |
Once PerlDancer#485 is merged, use the with_return handler to immediately stop processing a before hook or route handler. Includes tests for use in a reoute handler and a before hook. Resolves PerlDancer#472.
Implements the "specification" for
forward
from #432; calling forward ceases execution of the current dispatch and returns the response from dispatching a modified request.redirect
uses the same mechanism to immediately return from hook/route code to avoid halting the response, resolving #432.Adds tests for
after
hook being called (once and once only) from a route, forward and redirect.@ambs - apologies again for the largish pull request!