NAME

Plack::Middleware::Cleanup - Run cleanup code after request completion

VERSION

version 0.002

SYNOPSIS

my $app = sub {
    my $env = shift;
    $env->{'cleanup.register'}->(sub {
        # do some long running task
        # careful not to reference $env!
        ...
    });
    ...
};

builder {
    enable 'Cleanup';
    $app;
};

DESCRIPTION

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.

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).

AUTHOR

Hans Dieter Pearcey <hdp@pobox.com>

COPYRIGHT AND LICENSE

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.