Is there a way in Dancer to execute a code after every request?
I tried with an after hook but it seems that it doesn't execute after a file request... There is a hook called 'after_file_render' which is executed a decent number of times after each request but I am not sure what is its purpose. Is it always called after every request?
The after_file_render
hook is run after each successful request for a static file (e.g., a CSS file or an image), while the after
hook runs after an action is performed by a route handler.
If you want to run the same code for both after
and after_file_render
, you can put it in a subroutine and assign it to the two hooks using a reference, e.g.:
sub foo {
...
}
hook after_file_render => \&foo;
hook after => \&foo;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With