Plack::Middleware::Cleanup - Run cleanup code after request completion
version 0.002
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
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.