While trying to finish up my thoughts of the followup to "Does Anyone Else Hate the Stash?" one issue that I'm been grappling with is the relationship between using the stash as secondary global namespace and the way I've seen people use the stash as a sort of messaging system to methods called via $c->forward and the like. I guess part of what troubles me here is how doing so seems to bust encapsulation, using the stash as a sort of 'pass by reference' system that reminds more of Perl 4 then where we are at now. I've seen code that forwarded to a method, where the target method expected certain things in the stash but with no interface to really tell you want was expected. That code would forward to other code that expected different things in the stash. And all along all these forwards, stuff gets dropped in and mangled in the stash so by the time it returns from the initial ->forward I really have no idea what is in the stash anymore.
Is this a problem or am I just being too controlling :) Tell me!
So, tell me what you are using forward for, and how you use (or don't use) the stash when doing so. I won't pollute your thoughts on the matter with mine until I've heard from you first :)
And another thing while I'm typing, it seems like all my most popular blog posts contain the word 'Hate" in the title. I may be concerned.
Thanks!
I usually try to use standard method calls instead of using forward and stash. Se also Is using the Catalyst 'forward' method a cargo cult?
Posted by: zby | 11/12/2009 at 10:49 AM
Editorial: I've gotten some offline comments to the effect that some people only use the 'detach' function and only for terminal things like detaching to an error page. Also, comments to the effect that they stay away from using the stash as a messaging system to the detached command.
Posted by: John Napiorkowski | 11/12/2009 at 11:43 AM
[this is good] My initial reaction to the article was, "who cares where arbitrary data is stored", would you agree? Arbitrary being the key word here, tell me, what is the difference between storing this arbitrary data in a session file, database row/column or in a global "stash" object.
Posted by: Al Newkirk | 11/30/2009 at 03:01 PM
I guess if the data is truly arbitrary I would love to see it properly managed, maybe using a metadata system like
MooseX-MetaDescription so that at least its properly tagged. My issue with the stash relates to the fact the data stored in it is usually not arbitrary, but rather extremely important, yet the stash, as a global namespace/messaging system tends to break down with complex websites. Its totally fine when the site is small or small to medium. I guess I'm more playing devils advocate here to see if we can think of other ways to solve these common problems.Regarding sessioning, I guess I tend to see the session more as a cache to avoid roundtripping the database too much. Personally I don't use the session as a tool in my programmer box, since overly relying on session/state is a sure fire way to cause yourself terrible performance issues. Mostly I use it for simple stuff like is a user logged in or not, and that's basically it.
Posted by: John Napiorkowski | 11/30/2009 at 03:11 PM
[this is good] Very appropriate question. The problem I have found as a 'new user' to Catalyst is that there doesn't seem to be a better defined way to pass state type data around between the different action classes.
And I don't mean to say that there isn't, just that at first glance I didn't see anything which demonstrated a 'standard' or 'better' way. The problem I found is that the stash is convenient in that I could change things once and know that other parts of my program would have the info available too. It just 'seems' that Catalyst works best (to a new user anyway) when you don't pass state info directly into subroutines, but assume it will be there in the stash. Again, I'm just very new to Catalyst so these are just first impressions.
I love the way the 'action' to path stuff works, but getting info into 'action' subroutines was a bit of a mystery. I probably am missing some great ideas, so any examples would be great.
Dwight - happy new Catalyst developer
Posted by: Dwight Vietzke | 12/30/2009 at 03:32 PM