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

Emmanuel Quevillon tuco at pasteur.fr
Mon May 18 09:38:15 GMT 2009


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



More information about the Catalyst mailing list