NAME
Catalyst::Plugin::Hooks - Add hooks to Catalyst engine actions
SYNOPSIS
In MyApp.pm:
use Catalyst qw(
-Debug
Hooks
);
In Some model:
sub new {
my $self = shift;
my ( $c ) = @_;
$self->NEXT::new( @_ );
open my $filehandle, "> foo.log";
$c->add_after_finalize_hook( sub {
$filehandle->flush();
}
return $self;
}
DESCRIPTION
Implements hooks on Catalyst's engine actions. See Catalyst::Manual::Internals for when the different actions are called. This is usefull for when you want some code run after all actions for a request are completed. Let's say you want to flush your log after the request is done. You can achieve this by calling $c-
add_after_finalize_hook( sub { warn "Request done, time to cleanup"; $fh->flush } );
METHODS
All of these methods are currently hookable:
handle_request
prepare
prepare_request
prepare_connection
prepare_query_parameters
prepare_headers
prepare_cookies
prepare_path
prepare_body
prepare_body_parameters
prepare_parameters
prepare_uploads
prepare_action
dispatch
finalize
finalize_uploads
finalize_error
finalize_headers
finalize_cookies
finalize_body
To add a before hook, call $c->add_ <method name> _hook( sub { some code } );>
To add an after hook, call $c->add_after_ <method name> _hook( sub { some code } );>
$c->add_before_ <method name> _hook
is an alias to $c->add_ <method name> _hook
.
SEE ALSO
Catalyst, Catalyst::Manual::Internals
AUTHOR
Berik Visschers <berikv@xs4all.nl>