Plack and CGI : where to put initialization code ?
Hello developers, I need to execute code at the beginning of every request. For now it's in a BEGIN block. It works well in CGI mode, but not at all with plack (it's only executed once). I tried moving the BEGIN block into a sub init(), calling this sub in the BEGIN block and in the PSGI file (in CGI::new wrapper). It works but it doesn't feel "right". Is there a common place to put this kind of code ? Should I use the L1 cache (which is flushed at every request) to store some state (initialized or no) and call init() in every method of the module or something like that ? -- Julian Maurice <julian.maurice@biblibre.com> BibLibre
On 10. april 2017 10:39, Julian Maurice wrote:
I need to execute code at the beginning of every request. For now it's in a BEGIN block. It works well in CGI mode, but not at all with plack (it's only executed once). I tried moving the BEGIN block into a sub init(), calling this sub in the BEGIN block and in the PSGI file (in CGI::new wrapper). It works but it doesn't feel "right".
probably the best way in plack is to "enable" it in the build chain, like it is happening with Koha::Middleware::SetEnv in plack.psgi HTH F
Le 10/04/2017 à 10:42, Francesco Rivetti a écrit :
On 10. april 2017 10:39, Julian Maurice wrote:
I need to execute code at the beginning of every request. For now it's in a BEGIN block. It works well in CGI mode, but not at all with plack (it's only executed once). I tried moving the BEGIN block into a sub init(), calling this sub in the BEGIN block and in the PSGI file (in CGI::new wrapper). It works but it doesn't feel "right".
probably the best way in plack is to "enable" it in the build chain, like it is happening with Koha::Middleware::SetEnv in plack.psgi
HTH
F
I haven't thought of that. I'll give it a try. Thanks! -- Julian Maurice <julian.maurice@biblibre.com> BibLibre
participants (2)
-
Francesco Rivetti -
Julian Maurice