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

Simon Bertrang janus at errornet.de
Wed Oct 8 16:58:10 BST 2008


On Wed, Oct 08, 2008 at 02:37:39PM +0100, Ash Berlin wrote:
>
> On 8 Oct 2008, at 13:28, 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.
>> The session would have been another solution but the same arguments
>> apply there as for the templates.
>>
>> What was left:
>> a) accessing $c manually to hand over the data
>> b) implement a controller providing a common method
>> c) writing a plugin
>>
>> I decided for the plugin as i need access to this data from many points
>> in our applications (the controllers as well as the models use
>> this information).
>> So what i'm now proposing is the module Catalyst::Plugin::Memory which
>> is mostly identical with the stash, except that it isn't the stash.
>> It allows me to capture arguments out of the chains, use them at later
>> points in the chain and access them from forwarded methods.
>>
>> I've attached the code i've written so far but it's not done yet.  A few
>> tests are to be written as also as documentation.
>>
>> But what do you think?  Is it conceptually ok, do you disagree with the
>> name (suggestions welcome) or are there any other comments i should take
>> into account before i finish and upload this?
>>
>> Kind regards,
>> Simon
>
> General idea of not polluting the stash/session is good imo.
>
> However I'm not sure what you want needs to be anything more than a 
> wiki/cookbook example
>
> in MyApp.pm
>
> use Catalyst;
> use base 'Class::Data::Accessor'; # So you can have defaults/override or 
> local on a per request basis
>
> __PACKAGE__->mk_classaccessors(qw/memory/)
>
> in a controller:
>
> sub foo : Local
> {
> 	my ($self, $c) = @_;
>
> 	$c->memory->{foo} = 1;
> }
>
> Unless i've missed something thats basically what your plugin would end up 
> doing. (Tho my personal preference is to add many such accessors rather 
> than just one hash, but thats not much different)
>

That is actually a good idea and gives me exactly what i want even
without the overhead of a plugin, thanks.  That makes my suggestion
useless of course; i have obviously not looked in the wiki/cookbook for
a while.

Regards,
Simon



More information about the Catalyst-dev mailing list