[Catalyst-dev] Proposal for new module: Catalyst::Plugin::Memory

Simon Bertrang janus at errornet.de
Wed Oct 8 17:11:21 BST 2008


On Wed, Oct 08, 2008 at 03:56:08PM +0100, Matt S Trout wrote:
> On Wed, Oct 08, 2008 at 02:28:02PM +0200, Simon Bertrang wrote:
> > Hi,
> > i need a way to save various kinds of information between different
> > points in the request chain.
> > Initially i abused the stash for this, but polluting the template with
> > data not needed there or even worse, preventing things to work as
> > expected, did not work out.
> 
> Catalyst::Component::InstancePerContext sticks stuff in the stash as well,
> it just picks fairly careful key names and I've never had a clash.
> 
> Basically, this is what the stash is -for-, and introducing a second thing
> that means the same thing only under a different name would be wrong.
> 

Well, that is in contrast what Andy Grundman wrote on perlmonks [0] and
in fact i share his view that the place where data for the view is put
shouldn't be used for application internal data.


> I think what you maybe want is to override template_args or whatever relevant
> method in your view so that it uses %{$c->stash->{template_info}} instead of
> just %{$c->stash} ?
> 

That could be an option but would require even more changes i think.


> Alternatively, Template Toolkit refuses to expose keys starting with an _
> for just this purpose, so if you do
> 
> $c->stash->{_internal}{foo} = ...
> 
> then you're absolutely safe from the template accessing it.
> 

Yep, but we switched to XSLT where everything except template and xml
are taken as parameters, so that's no directly applicable.


> The other thing you could do, of course, is if the data is per-controller
> then use Catalyst::Component::InstancePerContext in your controllers and
> then do
> 
> $self->foo($foo);
> 
> and further down $c->controller('Whatever')->foo
> 

Wow, that is more heavy than i want it to be but interesting anyways.


> Thoughts on these different approaches?
> 

I honestly think they are more like workarounds as they don't provide
the clear separation of duties i want to have.
I'm happy with ash's proposal and will go with that and see if it's
working in the long term without overhead.
For now at least my proposed plugin won't be uploaded as it's really not
as useful as i thought.

Thanks for your suggestions though, they're valuable contributions to
the discussion and provide more insight in a new context.


Regards,
Simon

[0] http://www.perlmonks.org/index.pl?node_id=476246



More information about the Catalyst-dev mailing list