Catalyst::Plugin::RedirectAndDetach - Redirect and detach at the same time
# load the plugin use Catalyst qw( RedirectAndDetach ); # in your controller ... sub admin { my $self = shift; my $c = shift; $c->redirect_and_detach('/') unless $c->stash()->{user}->is_admin(); ... }
I generally find that if I want to issue a redirect in my web app, I want to stop processing right there. This plugin adds a ridiculously simply method to your Catalyst objects to do just that.
The reason to use detach() instead of simply returning from the current sub is that detach() throws an exception that effectively aborts all execution, rather than simply exiting the current method.
detach()
This class provides one method:
The $uri parameter is required, and $status is optional. Internally, this just calls redirect() on the Response object, followed by detach().
$uri
$status
redirect()
Dave Rolsky, <autarch@urth.org>
<autarch@urth.org>
Please report any bugs or feature requests to bug-catalyst-plugin-redirectanddetach@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-catalyst-plugin-redirectanddetach@rt.cpan.org
Copyright 2008 Dave Rolsky, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::Plugin::RedirectAndDetach, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::RedirectAndDetach
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::RedirectAndDetach
For more information on module installation, please visit the detailed CPAN module installation guide.