Plack::Middleware::Cleanup - Run cleanup code after request completion
version 0.003
Don't use this module. It has some serious flaws. See this proposal instead:
https://github.com/miyagawa/psgi-specs/wiki/Proposal%3A-PSGI-environment-cleanup-handlers
my $app = sub { my $env = shift; $env->{'cleanup.register'}->(sub { # do some long running task # careful not to reference $env! ... }); ... }; builder { enable 'Cleanup'; $app; };
This middleware makes it possible to run code after the request cycle is complete and the client has received the response.
Your application will see a callback in $env->{'cleanup.register'}. Call this callback with any number of coderefs that you want to be invoked after the request is complete.
$env->{'cleanup.register'}
Make sure your coderefs do not accidentally refer to $env, or you will have a circular reference and leak memory (also, your coderefs will never run).
$env
This will only work properly on handlers that happen to let $env fall out of scope at the right time, e.g. FCGI. It will not work correctly, for example, on CGI or mod_perl.
Catalyst::Plugin::RunAfterRequest
Hans Dieter Pearcey <hdp@pobox.com>
This software is copyright (c) 2011 by Hans Dieter Pearcey.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::Cleanup, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Cleanup
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Cleanup
For more information on module installation, please visit the detailed CPAN module installation guide.