[Catalyst] default template
Jonathan Rockway
jon at jrock.us
Fri Dec 29 20:20:50 GMT 2006
Octavian Rasnita wrote:
> Hi,
>
> I often need to make external redirections like in the following case:
>
> sub logout : Local {
> my ($self, $c) = @_;
> $c->logout;
> $c->res->redirect($c->uri_for("/"));
> }
How about $c->detach() after the redirect?
BTW, I notice a common theme in your posts -- being burned by your
poorly-designed custom global end action. Please switch to RenderView
and avoid 90% of your problems :)
Since the code in RenderView is so small, I'm going to paste it here and
tell you why each line there is important. ## comments are my notes
sub execute {
my $self = shift; ## setup
my ($controller, $c ) = @_;
$self->NEXT::execute( @_ ); ## run everything in the actual end
## action first
## dump requested (by setting ?dump_info=1 in the URL)?
## if so, die so we get the debug screen
if ($c->debug && $c->req->params->{dump_info}) {
die "forced debug"
}
## no content type set? use text/html so that the browser doesn't
## choke
if(! $c->response->content_type ) {
$c->response->content_type( 'text/html; charset=utf-8' );
}
## client doesn't want body? don't render it!
return 1 if $c->req->method eq 'HEAD';
## custom body set in an action? send that instead
return 1 if length( $c->response->body );
## errors and no template to show them with? let Catalyst handleit
return 1 if scalar @{ $c->error } && !$c->stash->{template};
## redirect? don't render the template, just redirect!
return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
## get the view
my $view=$c->view()
|| die "Catalyst::Action::RenderView could not find a view to".
" forward to.\n";
## and forward to it
$c->forward( $view );
};
Pretty nice, eh? You can learn a lot by reading the fine source code.
Regards,
Jonathan Rockway
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
More information about the Catalyst
mailing list