[Catalyst] How and where to run a method at Catalyst start up?
Emmanuel Quevillon
tuco at pasteur.fr
Mon May 18 12:11:48 GMT 2009
Rodrigo wrote:
>
>
> #Create appropriate model
> my $model = join("::", "GenoList", "$db", "Organism");
> my $r = BiblioList->model($model)->search()->first();
> $ROrgs->{$db} = $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.
>
Hi Rodrigo,
Thanks for your quick reply.
Actually yes, GenoList::$db::Organism resolves to a correct model.
I use that sort of call into some of my controller sub using the
same syntax $c->model("GenoList::$db::<Table>").
in BUILD body :
<snip> ...
foreach my $db (sort keys
%{BiblioList->config()->{remote_supported_dbs}}){
#Create appropriate model
my $model = join("::", "GenoList", "$db", "Organism");
print STDERR "Model: $model\n";
my $r = BiblioList->model($model)->search()->first();
$ROrgs->{$db} = $r;
}
<snip>
the output is :
Model: GenoList::bovisR1db::Organism
Just before the error message
> 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
>
I created my module using the schema loader from DBIC package.
>
> 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/script/../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/script/../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.
>
The strange thing is that if I copy the body of BUILD to
BiblioList.pm (just after __PACKAGE__->setup())
The function works just fine and I don't get any error.
So my question is, would it be a problem with my BiblioList/Model
directory stucture which is:
$ ls -l lib/BiblioList/Model/*
lib/BiblioList/Model/BiblioListDB.pm*
lib/BiblioList/Model/File.pm
lib/BiblioList/Model/Mapping.pm
lib/BiblioList/Model/GenoList:
total 40
-rw-r--r-- 1 tuco tuco 723 Apr 6 09:57 aureusdb2.pm
-rw-r--r-- 1 tuco tuco 728 Apr 6 09:57 bordetelladb2.pm
-rw-r--r-- 1 tuco tuco 723 Apr 6 09:57 bovisR1db.pm
-rw-r--r-- 1 tuco tuco 722 Apr 6 09:57 colibridb2.pm
-rw-r--r-- 1 tuco tuco 720 Apr 6 09:57 lepraedb2.pm
-rw-r--r-- 1 tuco tuco 722 Apr 6 09:57 spneumodb2.pm
-rw-r--r-- 1 tuco tuco 732 Apr 6 09:57 tsmegmatisR2db.pm
-rw-r--r-- 1 tuco tuco 734 Apr 6 09:57 ttuberculisR8db.pm
-rw-r--r-- 1 tuco tuco 733 Apr 6 09:57 tuberculisR8db.pm
-rw-r--r-- 1 tuco tuco 729 Apr 6 09:57 ulceransR1db.pm
And each of these model are configured as :
__PACKAGE__->config(
'schema_class' => 'GenoList',
'connect_info' => [...]
);
NOTE: I don't have a module called lib/BiblioList/Model/GenoList.pm
But I don't think this causes the problems? Isn't it?
and where my DBIC class build with the loader are located under
lib/GenoList :
$ ls -l lib/GenoList
total 28
-rwxr-xr-x 1 tuco tuco 1514 Apr 6 09:57 Author.pm*
-rwxr-xr-x 1 tuco tuco 1955 Apr 6 09:57 Bibliography.pm*
-rwxr-xr-x 1 tuco tuco 974 Apr 6 09:57 BufBiblAuth.pm*
-rwxr-xr-x 1 tuco tuco 1127 Apr 6 09:57 BufBiblGene.pm*
-rwxr-xr-x 1 tuco tuco 5409 Apr 6 09:57 Genes.pm*
-rwxr-xr-x 1 tuco tuco 899 May 15 14:25 Organism.pm*
I must confess I am a bit lost :(
Thanks for any advice/help
Best regards
Emmanuel
> -rodrigo
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
--
-------------------------
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