[Catalyst] How and where to run a method at Catalyst start up?

Emmanuel Quevillon tuco at pasteur.fr
Fri May 15 13:50:56 GMT 2009


Rodrigo wrote:
Hi Rodrigo,

Thanks for your reply.

> In MyApp.pm:
> 
> # Start the application
> __PACKAGE__->setup();
> mymethod();
> sub mymethod {
>     ...
> }
> But that's probably not what you're looking for...
>  
> 

Well, that's what I was thinking of actually.
However, your following code looks interesting :)

> 
>     The idea is to check and create some kind of a data structure that
>     will be loaded into memory (__PACKAGE__->{mydata} = { ... }) of my
>     application and will be then accessible at anytime from anywhere in
>     any controller
> 
> 
> Create a model for it.
> $ script/myapp_create.pl model MyData
> 
> Then create the data structure in Model/MyData.pm:
> 
> package MyApp::Model::MyData;
> use Moose;
> extends 'Catalyst::Model';
> has 'mydata' => ( is=>'rw', isa=>'HashRef', default=>sub{{}} );
> no Moose;
> sub BUILD {
>    my $self=shift;
>    my $data = MyApp->model('DB::Table')->search(...)->first; # I rather
> avoid storing dbic resultsets in memory for a long time.
>     $self->mydata({  foo=> $data } ); }
> }
> 

I tried to follow your advices, but unfortunately, I looks like
MyApp->model().. does not work :

Couldn't instantiate component "MyApp::Model::Mapping", "Can't
locate object method "model" via package "MyApp::Model::Mapping"
....

I also tried with $self without success :(


Cheers

Emmanuel

-- 
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------



More information about the Catalyst mailing list