Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've just started taking a decent in-depth look at Catalyst with a view to using it in the next major project coming up at work. I like a lot of it, but one thing that really bugs me is the stash.


It's basically a global variable, even though it's being passed round in the Catalyst::Context object. I don't have a problem with that, globals can be useful sometimes. But what concerns me is the way it's used to communicate between functions. eg.
sub foo : Local { my ($self, $c) = @_; $c->stash->{foo} = 'store some stuff'; $self->forward('bar'); } sub bar : Private { my ($self, $c) = @_; # ... do something with data put in stash by foo() }
Of course, you don't *have* to do it that way, especially since forward() now supports passing of arguments. But a lot of the Catalyst::* modules do things like (from Catalyst::View::HTML::Template for use with HTML::Template):
$template->param( base => $c->req->base, name => $c->config->{name}, %{ $c->stash } );
It seems most of the other view modules take this sort of a approach as well.

So you're just expected to put some things into the stash, forward to the view, and automagically your template gets populated with everything currently in the stash (whether you need or want it).

Again, you don't *have* to do it that way, you can easily create your own HTML::Template view module that passes parameters to the process() function, but it seems like the 'default' way of doing things is encouraging the use of stash.

What happens if another module decides to overwrite a whole lot of stash variables that you were using? True, there has to be sloppy coding along the line somewhere, but why make it easier for this sort of problem when you could just as easily protect against this sort of thing by passing parameters around?

I'm looking forward to using Catalyst in future applications, but these issues are making me slightly uneasy. I'd like someone to put my mind at rest :)

In reply to Catalyst and the stash by Mutant

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found