Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

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

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


tuco at pasteur

May 15, 2009, 3:12 AM

Post #1 of 15 (1522 views)
Permalink
How and where to run a method at Catalyst start up?

Hi all,

I am developing a Catalyst App and I'd like to know how to launch a
method at Catalyst start up?
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 as

sub foo: Local {
my($self, $c) = @_;

my $personnal_data = $self->_get_mydata();

...

}


sub get_mydata will reside into MyApp.pm

But how can I access my database within MyApp.pm ?
I tried (in MyApp.pm):


sub _test {

my $self = shift;
@rs = $self->comp('MyApp::DB::Table')->search({ id => { '>' => 2 } });

#If I print each values of @rs
#it prints something like 'MyApp::DB::Table=HASH(....)
#But from each item of my array, if I tried any call to
#column sub (like $_->id()) I get 'Unkown error'
#Also it looks like $_ is a 'DBIx::Class' only


}

Has somebody any clue how could I solve my problem
Thanks in advance

Regards




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

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


rodrigolive at gmail

May 15, 2009, 5:44 AM

Post #2 of 15 (1462 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

On Fri, May 15, 2009 at 12:12 PM, Emmanuel Quevillon <tuco [at] pasteur>wrote:

> Hi all,
>
> I am developing a Catalyst App and I'd like to know how to launch a
> method at Catalyst start up?


In MyApp.pm:

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


>
> 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 } ); }
}

Then call it from any controller:

sub foo : Local {
my $c=pop;
$c->stash->{foome} = $c->model('MyData')->mydata->{foo};
}


>
> But how can I access my database within MyApp.pm ?
> I tried (in MyApp.pm):
>

If don't have $c defined, you can use MyApp->model() most of the time.

--rodrigo


bobtfish at bobtfish

May 15, 2009, 5:57 AM

Post #3 of 15 (1462 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Emmanuel Quevillon wrote:
> #column sub (like $_->id()) I get 'Unkown error'
> #Also it looks like $_ is a 'DBIx::Class' only

That's as you have some form of syntax error at application compile time.

I believe this is fully fixed as of r10169 in trunk. Please test and let
me know if it works for you? (i.e. you get a reasonable error, not
'Unknown error')

Cheers
t0m


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


tuco at pasteur

May 15, 2009, 6:50 AM

Post #4 of 15 (1469 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

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
-------------------------

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


bobtfish at bobtfish

May 15, 2009, 6:58 AM

Post #5 of 15 (1469 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Emmanuel Quevillon wrote:
> 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 :(

You're not doing what Rodrigo suggested, at all.

'model' is a method on Catalyst, therefore you need to call it on an
object which ISA Catalyst (i.e. MyApp, or $c).

I can't really give you much more help unless you give us your _entire_
model code, and the controller code you're trying to call it.

Cheers
t0m


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


tuco at pasteur

May 18, 2009, 2:38 AM

Post #6 of 15 (1424 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Tomas Doran wrote:
> Emmanuel Quevillon wrote:
>> 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 :(
>
> You're not doing what Rodrigo suggested, at all.
>
> 'model' is a method on Catalyst, therefore you need to call it on an
> object which ISA Catalyst (i.e. MyApp, or $c).
>
> I can't really give you much more help unless you give us your _entire_
> model code, and the controller code you're trying to call it.
>

Hi Tom,

I can't even instantiate my new Model 'MyApp::Model::Mapping'
following Rodrigo's code :

package BiblioList::Model::Mapping;

use Moose;
extends 'Catalyst::Model';

has 'mapping_data' => (
is => 'rw',
isa => 'HashRef',
default => sub { { } }
);
no Moose;

sub BUILD {

my($self) = shift;

my $ROrgs = { };
#Get all the remote supported dbname configured
foreach my $db (sort keys
%{BiblioList->config()->{remote_supported_dbs}}){

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

my $mapping = { };

#We handle more than one organism, so loop over results
my $f =
BiblioList->model('BiblioListDB::Organism')->search({isavailable =>
'1'});

while(my $o = $f->next()){
#print STDERR "- ",$o->id_org()," ", $o->shortname(), "\n";

my $oname = $o->fullname();
$oname .= " ".$o->strain() if($o->strain());

foreach my $db (sort keys %{$ROrgs}){

my $remote = $ROrgs->{$db};
my $rname = $remote->fullname();
$rname .= " ".$remote->strain() if($remote->strain());

if($rname eq $oname){
$mapping->{$o->id_org} = $db;
delete $ROrgs->{$db};
last;
}
}
}
$self->mapping_data($mapping);

}

1;


However, the strange is that I can access my config values through
BiblioList->config() whereas I get an error complaining about an
undefined value (here BiblioList->model($model)) : Here is the error:

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.

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.


Any clue?

Cheers


> Cheers
> t0m
>


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

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


rodrigolive at gmail

May 18, 2009, 4:33 AM

Post #7 of 15 (1417 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

>
> #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.

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/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.

-rodrigo


tuco at pasteur

May 18, 2009, 5:11 AM

Post #8 of 15 (1418 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

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
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> 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
-------------------------

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


rodrigolive at gmail

May 18, 2009, 7:57 AM

Post #9 of 15 (1417 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

>
> 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.
>

Strange indeed.
Just try, as a possible workaround, just get rid of the "GenoList" level in
your Model. That would shorten the model call to something like
MyApp->model('bovisR1db::Organism'). See if that works.

-rodrigo


tuco at pasteur

May 19, 2009, 5:01 AM

Post #10 of 15 (1398 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Rodrigo wrote:
>
>
> 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.
>
>
> Strange indeed.
> Just try, as a possible workaround, just get rid of the "GenoList" level
> in your Model. That would shorten the model call to something like
> MyApp->model('bovisR1db::Organism'). See if that works.
>

Hi Rodrigo

I tried what you mentioned but it didn't change anything
unfortunately. Has someone in the list another idea what's is going
wrong?
Help will be much appreciated.

Regards

Emmanuel

> -rodrigo
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> 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
-------------------------

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


bobtfish at bobtfish

May 19, 2009, 11:41 AM

Post #11 of 15 (1392 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

On 19 May 2009, at 13:01, Emmanuel Quevillon wrote:
>
> I tried what you mentioned but it didn't change anything
> unfortunately. Has someone in the list another idea what's is going
> wrong?

No idea as we don't know where it's being called from, or why it's
failing.

Try with perl -MDevel::SimpleTrace and post a stack trace.

I'd also recommend you start a new TestApp, and try to make just the
smallest subset of an application you can to demonstrate / prototype
out the functionality you want.

a) This is gonna be easier to debug for you as there are less moving
parts
b) It's then possible to post your app on github or upload a tarball
somewhere, and an interested party could have a play and see if they
can see your issue, without conjecture/guessing, and also without
having to wade through the rest of your application.

Cheers
t0m


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


tuco at pasteur

May 19, 2009, 12:24 PM

Post #12 of 15 (1384 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Tomas Doran wrote:
>
> On 19 May 2009, at 13:01, Emmanuel Quevillon wrote:
>>
>> I tried what you mentioned but it didn't change anything
>> unfortunately. Has someone in the list another idea what's is going
>> wrong?
>
> No idea as we don't know where it's being called from, or why it's
> failing.
>
> Try with perl -MDevel::SimpleTrace and post a stack trace.
>
Hi Tom,

Thanks to try helping me. Here is the Trace from Devel::SimpleTrace.
Actually, the error is not even when I try
to call my method from my Catalyst::Model but when I start the dev server :

tuco [at] gi bibliolist$ perl -MDevel::SimpleTrace script/bibliolist_server.pl
Couldn't instantiate component "BiblioList::Model::Mapping", "Can't call
method "search" on an undefined value
at
BiblioList::Model::Mapping::_load_BiblioRemote_mapping(/home/tuco/src/perl/projects/Catalyst/BiblioList/dev/bibliolist-0.08/script/../lib/BiblioList/Model/Mapping.pm:37)
at
BiblioList::Model::Mapping::BUILD(/home/tuco/src/perl/projects/Catalyst/BiblioList/dev/bibliolist-0.08/script/../lib/BiblioList/Model/Mapping.pm:20)
at
Class::MOP::Method::execute(/usr/local/lib/perl/5.10.0/Class/MOP/Method.pm:120)
at
Moose::Object::BUILDALL(/usr/local/share/perl/5.10.0/Moose/Object.pm:55)
at Moose::Object::new(/usr/local/share/perl/5.10.0/Moose/Object.pm:28)
at Catalyst::Model::new(generated method (unknown origin):2)
at
Catalyst::Component::COMPONENT(/usr/local/share/perl/5.10.0/Catalyst/Component.pm:85)
at <eval>(/usr/local/share/perl/5.10.0/Catalyst.pm:2202)
at
Catalyst::setup_component(/usr/local/share/perl/5.10.0/Catalyst.pm:2202)
at
Catalyst::setup_components(/usr/local/share/perl/5.10.0/Catalyst.pm:2156)
at Catalyst::setup(/usr/local/share/perl/5.10.0/Catalyst.pm:1071)
at
<eval>(/home/tuco/src/perl/projects/Catalyst/BiblioList/dev/bibliolist-0.08/script/../lib/BiblioList.pm:75)
<== call to BiblioList->setup()
at main::__ANON__(script/bibliolist_server.pl:66)
at main::(script/bibliolist_server.pl:104)" at
script/bibliolist_server.pl line 66
Compilation failed in require at script/bibliolist_server.pl line 66.



> I'd also recommend you start a new TestApp, and try to make just the
> smallest subset of an application you can to demonstrate / prototype
> out the functionality you want.
>
> a) This is gonna be easier to debug for you as there are less moving
> parts
> b) It's then possible to post your app on github or upload a tarball
> somewhere, and an interested party could have a play and see if they
> can see your issue, without conjecture/guessing, and also without
> having to wade through the rest of your application.
>
> Cheers
> t0m
>
I'll do it and post it to the list (github).
Cheers
Emmanuel

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


tuco at pasteur

May 20, 2009, 1:54 AM

Post #13 of 15 (1379 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Emmanuel Quevillon wrote:

>> I'd also recommend you start a new TestApp, and try to make just the
>> smallest subset of an application you can to demonstrate / prototype
>> out the functionality you want.
>>
>> a) This is gonna be easier to debug for you as there are less moving
>> parts
>> b) It's then possible to post your app on github or upload a tarball
>> somewhere, and an interested party could have a play and see if they
>> can see your issue, without conjecture/guessing, and also without
>> having to wade through the rest of your application.

Hi Tom,

I created a small App with Catalyst that does nothing at all but can
reproduce the error encountered with my Application.

This git app has been uploaded to github at :

http://github.com/tuco/startup/tree/master

I hope this will help.
Thanks for any clue/advice

Regards

Emmanuel

>>
>> Cheers
>> t0m
>>

> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> 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
-------------------------

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


bobtfish at bobtfish

May 20, 2009, 4:49 AM

Post #14 of 15 (1374 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Emmanuel Quevillon wrote:
> Thanks to try helping me. Here is the Trace from Devel::SimpleTrace.
> Actually, the error is not even when I try
> to call my method from my Catalyst::Model but when I start the dev server :

Aha, yes - the stack trace makes it fairly clear what's happening!

Catalyst is trying to create your Model::Mapping _before_ it creates
your other model..

And creating an instance of Model::Mapping relies on the other model
having been setup first.

> I'll do it and post it to the list (github).

Ok, and having looked at the code - that isn't the issue that you're
having in that test app..

The result classes for your DBIC models were in the wrong place, so DBIC
wasn't finding them, ergo the call to ->model returning undef..

I have also fiddled with the code to make it not order sensitive, and (I
think) more elegant.

http://github.com/bobtfish/startup/tree/ea22d1ac4af4a9e9f46dbbfd0c9f9963ede3fa5f

Cheers
t0m

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


tuco at pasteur

May 20, 2009, 5:44 AM

Post #15 of 15 (1381 views)
Permalink
Re: How and where to run a method at Catalyst start up? [In reply to]

Tomas Doran wrote:
> Emmanuel Quevillon wrote:
>> Thanks to try helping me. Here is the Trace from Devel::SimpleTrace.
>> Actually, the error is not even when I try
>> to call my method from my Catalyst::Model but when I start the dev
>> server :
>
> Aha, yes - the stack trace makes it fairly clear what's happening!
>
> Catalyst is trying to create your Model::Mapping _before_ it creates
> your other model..
>
> And creating an instance of Model::Mapping relies on the other model
> having been setup first.
>

Ok understood ! :)

>> I'll do it and post it to the list (github).
>
> Ok, and having looked at the code - that isn't the issue that you're
> having in that test app..
>
> The result classes for your DBIC models were in the wrong place, so DBIC
> wasn't finding them, ergo the call to ->model returning undef..
>

Well yes, it is because when I created my classes using
schema_loader, it created a 'Result' dir under Startup(2) direcotry.
But with the application I started earlier (BiblioList), this
directory wasn't present. So I decided to remove it :(
And the diff is that in BiblioList, It uses load_classes instead of
load_namespaces. Why this changes? I don't know, probably an API
change from DBIx::Class I used before.
Anyway, I read DBIx::Class::Schema doc and now see the diff between
the 2 methods. However don't know if one is better than the other one?

> I have also fiddled with the code to make it not order sensitive, and (I
> think) more elegant.

I looks more PROFESSIONAL anyway ;) !

>
> http://github.com/bobtfish/startup/tree/ea22d1ac4af4a9e9f46dbbfd0c9f9963ede3fa5f
>
>
> Cheers
> t0m
Thanks for your time Tom!
Cheers

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

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

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.