Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: $c->flash Not Dereferencing Data Objects

by Your Mother (Archbishop)
on Jul 02, 2020 at 20:35 UTC ( [id://11118839]=note: print w/replies, xml ) Need Help??


in reply to $c->flash Not Dereferencing Data Objects

I don’t have time to write test code but I think see the problem. You can only use a flash entry once. It’s gone—removed from the session—after that. The entire point is it cannot persist past a single use. Put it in the stash instead—unless you need it to persist past a redirect or something—and you should be fine. And just to be clear, this is actually a Catalyst question, not a DBIx::Class question. The flash/stash is part of the Catalyst context and its session.

More detail, when you do if $c->flash->{bio}, you just used it so it’s gone by the time you get to the assignment. Also note, you should never put a conditional on an (update: variable declarative) assignment statement. It can behave strangely.

# Unpredictable- my $x = 1 if $y; # Safe- my $x; $x = 1 if $y;

Update in case you do need it as flash, untested–

<%init> my $bio = $c->flash->{'bio'}; </%init> % if ( $bio ) { <p>My name is <% $bio->name |h %><br /> My residence is at <% $bio->address |h %></p> % }

Update, added HTML escape filters. Been ages since I did Mason. :P NEVER trust user input.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found