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?


In reply to Problems with setting session variables in Catalyst by LunarCowgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.