LunarCowgirl has asked for the wisdom of the Perl Monks concerning the following question:
I'm having trouble with session variables in Catalyst. I'm new to Catalyst, so it's likely I don't fully understand how to use Session::Store. I've found, on all the web, only two examples of how to add items to $c->session:
push @{ $c->session->{items} }, $item_id; $c->session->{cart}{$item_id} += $quantity;
I know $c->session is a hash ref, and I've tried variations on both above. What I'm trying to do is create a hidden token in a form for validation upon POST. This is my GET routine:
sub contact_GET { my ( $self, $c ) = @_; # Using Crypt::Random my $token = makerandom( Size => 128, Strength => 0 ); $c->session->{token} = $token; $c->load_status_msgs; $c->stash( template => 'contact.tt', title => 'Contact Us', token => $token, ); }
I've also tried:
push @{ $c->session->{token} }, $token;The contact page won't load when I use either, and it crashes the server, so I get no error or debugging messages to indicate what's happening. I have to kill the server and restart it. If I comment out the line for $c->session, everything works fine. If I uncomment it though, things crash again.
The odd thing is that it suddenly starting working with the line uncommented. I had the token set at 512 bits from a copy and paste example. Changing the size to 128 made everything start working. Then, all of a sudden, without any changes to the method, it stopped and I have to comment out the line to get the page to load. Setting the token at 12 bits made no change, so I doubt it had anything to do with the variable size. I'm really confused here. What is the proper way to push a variable into a Catalyst session? Or if I'm doing it right, why is the page crashing the server?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems with setting session variables in Catalyst
by thomas895 (Deacon) on Aug 11, 2014 at 22:52 UTC | |
|
Re: Problems with setting session variables in Catalyst
by LunarCowgirl (Sexton) on Aug 12, 2014 at 02:41 UTC | |
by Anonymous Monk on Aug 12, 2014 at 02:55 UTC | |
by LunarCowgirl (Sexton) on Aug 14, 2014 at 03:32 UTC | |
|
Re: Problems with setting session variables in Catalyst
by Anonymous Monk on Aug 11, 2014 at 23:36 UTC |