Wishlist: Filters/hooks (path, stage) => code( req, \%returned_data)
dallaylaen opened this issue · 2 comments
dallaylaen commented
For reference: http://www.sinatrarb.com/intro.html#Filters
Make a way to add hooks: (path, method, stage) => CODE( $request, %return_value_if_applicable).
If URI foo/bar/baz was called, applied are hooks for /foo, then /foo/bar, then /foo/bar/baz (if any).
TODO
- What are the appropriate stages?
- Adding another hook for the same location = replace? enqueue? die?
- on_stage_name( path => CODE ) or add_hook( stage => ..., path => ..., code => ...)?
Dev notes
- see where server_stat is inserted - probably a good place for hooks. BTW replacing server_stat with hooks seems ok and then multiple hooks must be enqueued.
- add Request->on_cleanup to be executed in DESTROY after postpone() queue is processed (postponed queue may grow!)
- applicable hooks should be cached in location's profile, calculated on first call (or else unnecessary work with CGI)
akzhan commented
Any added hook should be OK enqueued. No more manipulation, because author of routes have full control over 'em.
dallaylaen commented
Implemented in 0.14. Multiple hooks are possible.
P.S. Thanks for discussion in PM, Akzhan!