6

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?

bliof
  • 2,957
  • 2
  • 23
  • 39

1 Answers1

9

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;
David Precious
  • 6,544
  • 1
  • 24
  • 31