Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Dancer after hook

Tags:

perl

hook

dancer

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?

like image 460
bliof Avatar asked Sep 29 '11 09:09

bliof


1 Answers

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;
like image 158
Michał Wojciechowski Avatar answered Sep 21 '22 16:09

Michał Wojciechowski