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

Rodrigo rodrigolive at gmail.com
Mon May 18 11:33:32 GMT 2009


>
>        #Create appropriate model
>        my $model =3D join("::", "GenoList", "$db", "Organism");
>        my $r =3D BiblioList->model($model)->search()->first();
>        $ROrgs->{$db} =3D $r;
>    }
>

Emmanuel, make sure that GenoList::$db::Organism actually resolves to a
correct model name for you application. I have a feeling that it doesn't.

Make sure you understand the way DB models are invoked in Catalyst.
Typically:

$c->model('MyModelName::MyResultClassName');

Where:
- ModelName is a module called lib/MyApp/Model/MyModelName.pm
- ResultClassName (usually points to a db table)  is a module called
lib/MyApp/Schema/Result/ResultClassName.pm

The paths may vary sensibly depending on how you created them and if it's a
DBIC schema or something else, but hopefully you get the idea.

There's good reading material on this here:
http://search.cpan.org/~hkclark/Catalyst-Manual-5.7021/lib/Catalyst/Manual/=
Tutorial/MoreCatalystBasics.pod#Create_Static_DBIx::Class_Schema_Files


> Couldn't instantiate component "BiblioList::Model::Mapping", "Can't
> call method "search" on an undefined value at
>
> /home/tuco/src/perl/projects/Catalyst/BiblioList/dev/bibliolist-0.08/scri=
pt/../lib/BiblioList/Model/Mapping.pm
> line 28." at script/bibliolist_server.pl line 66
> Compilation failed in require at script/bibliolist_server.pl line 66.
>

The method  ->search() is being called "on an undefined value" probably
because Catalyst could not find a model for the parameter you passed to
BiblioList->model('...').


> If I use $self instead of BiblioList the error change:
>
> Couldn't instantiate component "BiblioList::Model::Mapping", "Can't
> locate object method "model" via package
> "BiblioList::Model::Mapping" at
>
> /home/tuco/src/perl/projects/Catalyst/BiblioList/dev/bibliolist-0.08/scri=
pt/../lib/BiblioList/Model/Mapping.pm
> line 28." at script/bibliolist_server.pl line 66
> Compilation failed in require at script/bibliolist_server.pl line 66.
>

Don't use $self. The model method hangs from your application object, which
is $c not $self.

$self points to an instance of you BiblioList::Model::Mapping, which is a
child of Catalyst::Model, which does not give you a ->model() method.

-rodrigo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090518/406e1=
3e7/attachment.htm


More information about the Catalyst mailing list