GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Catalyst::Plugin::RunAfterRequest(3) User Contributed Perl Documentation Catalyst::Plugin::RunAfterRequest(3)

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

    #### In MyApp.pm
    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;

        $self->_run_after_request(
            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 <mst@shadowcat.co.uk>
  • Edmund von der Burg <evdb@ecclestoad.co.uk>
  • Florian Ragwitz <rafl@debian.org>
  • Pedro Melo <melo@simplicidade.org>

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.

2010-08-26 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.