phildeman has asked for the wisdom of the Perl Monks concerning the following question:

I have been building catalyst apps of a number of years now. This is the first time I am getting an error trying to open a view. When I call the view (there is only one view), I get the following error:

Can't call method "model" on an undefined value at....

The following snippet of code is used in Root.pm,. This is what is generating the error. Again, this is not the first time I am using this catalyst method to call a model.

my $model = $c->mode( 'mypackage' );
my $result = $model->get_my_results();

Has any one ever encounter this before? If yes, can you tell me how you resolved it?

Thanks

Replies are listed 'Best First'.
Re: Can't call method "model" on an undefined value at
by LanX (Saint) on Jan 08, 2015 at 21:32 UTC
    Perl tries telling you that $c is not defined

    Try to find out why.

    update

    please provide correct informations if you want us to help you:

    ->mode is not ->model !

    Cheers Rolf

    PS: Je suis Charlie!

      That was a typo. It should have read, $c->model. However, it is typed correctly in the app.

      Below is a snippet of code from Root.pm
      sub myform :Local {
         my ($self, $c) = @_;
         my $model = $c->model( 'mypackage' );
         my $results = $model->get_my_results();
         .
         .
         .
      }

        Obviously myform was not called passing a correct $c

        So please show us the call ....

        I could imagine someone forgot calling it as a ->method hence messing up $self.

        update

        Using Carp::Always might help...

        Cheers Rolf

        PS: Je suis Charlie!