Good evening,

On 16/08/10 at 11:05 AM +0300, Octavian Rasnita <[email protected]> wrote:

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?

Does it need to be in stash? How about a method in MyApp.pm that supplies the data? Eg.

sub menu_data {
    my $self = shift; # same as $c
    return {
        item1 => 'some data',
    };
}

Or just use some Moose goodness instead:

has "menu_data" => (
    is => "ro",
    isa => "HashRef",
default => sub { shift->config->{menu_data} }, #pull data from config
);

And then later in your template:

[% c.menu_data.item_1 %]


If you really do want the data in the stash, then create the object at app startup and then assign it to stash on each request:

after 'prepare_action' => sub {
    my $c = shift;
    $c->stash( menu_data => $c->menu_data_object );
}



Charlie

--
   Ꮚ Charlie Garrison ♊ <[email protected]>

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠  http://www.ietf.org/rfc/rfc1855.txt

_______________________________________________
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