From: "J. Shirley" <[email protected]>
2010/8/16 Octavian Rasnita <[email protected]>:
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




_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to