Catalyst::Plugin::RunAfterRequest - run code after the response has been sent.


    #### In
    use Catalyst qw(RunAfterRequest);

    #### In your controller
    sub my_action : Local {
        my ( $self, $c ) = @_;

        # do your normal processing...

        # add code that runs after response has been sent to client
        $c->run_after_request(    #
            sub { $self->do_something_slow(); },
            sub { $self->do_something_else_as_well(); }

        # continue handling the request

    #### Or in your Model:

    package MyApp::Model::Foo;

    use Moose;
    extends 'Catalyst::Model';
    with 'Catalyst::Model::Role::RunAfterRequest';

    sub some_method {
        my $self = shift;

            sub { $self->do_something_slow(); },
            sub { $self->do_something_else_as_well(); }


Sometimes you want to run something after you've sent the reponse back to the client. For example you might want to send a tweet to Twitter, or do some logging, or something that will take a long time and would delay the response.

This module provides a conveniant way to do that by simply calling run_after_request and adding a closure to it.



    $c->run_after_request(            # '_run_after_request' in model
        sub {
            # create preview of uploaded file and store to remote server
            # etc, etc
        sub {
            # another closure...

Takes one or more anonymous subs and adds them to a list to be run after the response has been sent back to the client.

The method name has an underscore at the start in the model to indicate that it is a private method. Really you should only be calling this method from within the model and not from other code.


  • Matt S Trout <>

  • Edmund von der Burg <>

  • Florian Ragwitz <>

  • Pedro Melo <>


This software is copyright (c) 2010 by Matt S Trout.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.