[Catalyst] Store something in the stash at startup
garrison at zeta.org.au
Wed Aug 18 03:07:19 GMT 2010
On 17/08/10 at 4:24 PM +0100, Tomas Doran
<bobtfish at bobtfish.net> wrote:
>On 17 Aug 2010, at 15:50, Charlie Garrison wrote:
>>I was suggesting the Moose attribute as way of storing the
>>model in $c to be easier to reference from templates.
>I highly recommend taking the model instance and stashing it
>(as is being done already), rather than making an attribute on
>the context object, as this is less flexible...
>I.e. if you are saying [% c.model('Foo').thing %] or [%
>c.foo.thing %] then this is less flexible (as you can't
>override foo for part of your site) than $c->stash(foo =>
>$c->model('Foo')) in your perl code, then [% foo.thing %] in
I'm not sure I understand why it's less flexible. I use
attributes on the context object to store objects that are
needed *everywhere* in the app. I was following the logic of
$c->user which stores the current $user. The objects stored in
the context attributes are still models, and as such can be flexible.
It didn't make sense to me (& in one case had race-condition,
don't recall specifics) to store all those objects in the stash
for each request. So I'm using this as an opportunity to learn...
If the stash or the context attribute are simply storing a model
object, what is the advantage to storing in stash over context
attribute? If it's the model that I would want to
override/extend, why does it matter whether it's accessed via
stash or via context attribute?
And thanks for the input so far, always fun to learn more. :-)
Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the Catalyst