[Catalyst] Store something in the stash at startup
Octavian Rasnita
octavian.rasnita at ssifbroker.ro
Tue Aug 17 05:27:59 GMT 2010
From: "J. Shirley" <jshirley at gmail.com>
> 2010/8/16 Octavian Rasnita <orasnita at gmail.com>:
>> Hi,
>> I have a module that creates an object (a menu) and I want to store it in
>> the stash when the application starts.
>> Where is the recommended place to create this object and store it in the
>> stash if I want that object created just once at app startup?
>> Should I override a certain method in MyApp.pm and create the object
>> there?
>> Thanks.
>>
>
>
> That sounds exactly like a model class.
I have already created a model:
package BRK::Model::Menu;
use strict;
use warnings;
use base 'Catalyst::Model::Adaptor';
1;
In the configuration file I have:
'Model::Menu' => {
class => 'HTML::Menu::MoreLevels',
args => do('/web/S/menu.pl'),
},
And the module HTML::Menu::MoreLevels create the menu object.
I load and store this object in the stash on each request in the Root::auto
: Private method with:
$c->stash(menu => $c->model('Menu'));
But this would re-create the menu object on each request, and this takes
time.
The data structure of the menu is loaded only at startup by the do() in the
configuration file, but then it is used on each request to re-create the
menu object.
Thanks.
Octavian
__________ Information from ESET NOD32 Antivirus, version of virus signature database 5371 (20100816) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
More information about the Catalyst
mailing list