[Catalyst] The stash and go()

Alexander Tamm alex at frantic.com
Mon Feb 16 08:18:36 GMT 2009


Hi!

I'm experiencing a little bit of weirdness with the stash when using 
go(). I'd like to make sure I'm not making false assumptions. Is the 
called action supposed to see the same context and/or stash as the the 
calling action?

I'm noticing that my Root's auto-sub is getting called after calling 
go() and I'm ok with that, but I need to retain the original values in 
the stash. This is where the weirness kicks in... If I pass a stashed 
value to warn() in Root::auto(), the called action will see the same 
stash. Otherwise, the stash is empty, except for values stashed by 
Root::auto().

Here's my code. Notice, that if I comment out the else-branch in auto(), 
the template will have an empty stash, even though the called action 
does its thing.

in Root.pm:
sub auto :Path :Args(0) {
     my ( $self, $c ) = @_;
     warn "Root::auto()";
     if( ! $c->stash->{lang} ) {
         warn "Setting the default lingo";
         $c->stash->{lang} = $c->config->{default_language};
     }
     else {
         warn "lingo is " . $c->stash->{lang};
     }
}

in (En|Sv|Fi).pm:

sub default :Private {
     my ( $self, $c ) = @_;
     my $path = $c->req->path;
     my $lang = $self->_lang();
     $c->stash->{lang} = $lang;
     $path =~ s{\A $lang }{}msx;
     $c->go( $path, [] );
}

Any info?
Alex



More information about the Catalyst mailing list