[Catalyst] Has $c->response->redirect behaviour changed?

Alan Humphrey alan.humphrey at comcast.net
Mon Jan 23 20:25:25 CET 2006


I'm using Mason as well and I'm also doing redirects.  I haven't had any
problems.  The only difference I see is that my redirects tend to look like:

$c->response->redirect( $c->request->base . 'birds/list' );

In other words, I'm not using relative paths.  Don't know how that would
make a difference....

-----Original Message-----
From: catalyst-bounces at lists.rawmode.org
[mailto:catalyst-bounces at lists.rawmode.org] On Behalf Of Alex Kavanagh
Sent: Monday, January 23, 2006 11:07 AM
To: The elegant MVC web framework
Subject: Re: [Catalyst] Has $c->response->redirect behaviour changed?

Okay, my own follow-up:

At Mon, 23 Jan 2006 14:24:31 +0000,
Alex Kavanagh wrote:
> 
> Hi
> 
> I just upgraded from 5.61 to 5.63 and I got a strange error with one
> of my HTML::Mason templates that complained about a variable not being
> defined.
> 
> The difference between the two seems to be that in 5.61 the view was
> NOT processed when a redirect was issued, but now with 5.62 the view
> IS processed and therefore it tripped up my view.
> 
> In my case the very simple change from:
> 
>     $c->response->redirect('/manage/users/' . $obj->username );
> 
> to:
> 
>     $c->stash->{form} = { field => $field };
>     $c->response->redirect('/manage/users/' . $obj->username );
> 
> allowed the Mason view to process (i.e. needed the form in the stash).
> 
> The reason I question this is that the processed view will never be
> displayed due to the redirect.
> 
> Is this any of the following:
> 
> a) a buggy install?
> b) a change in behaviour?
> c) a bug that has been introduced?
> d) Have I been relying on a 'feature' that I shouldn't have?

I've fixed it by over-riding 'process' in the Mason View as follows:

=head2 process

Overload process to not do the template if we are doing a redirect.

=cut

sub process {
  my $self = shift;
  my $c    = shift;
  
  my $status = $c->response->status;
  if (($status =~ /^(\d)\d\d$/) &&
      ($1 == 3)) {
    # Don't bother processing if we are doing a redirect
    return 1;
  }
  return $self->SUPER::process($c, @_);
}


It works, but is the right way to do it?  Should I be doing something
else?

Many thanks
Alex.

_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst




More information about the Catalyst mailing list