FAQ
Hi,

Running prove over my t directoty is giving me errors:

Error: Can't locate object method "config" via package "MyApp" at
lib/MyApp/Model/DB.pm line 7.

package MyApp::Model::DB;
use strict;
use warnings;
use base 'Catalyst::Model::DBIC::Schema';
__PACKAGE__->config(
schema_class => 'MyApp::Schema',
connect_info => MyApp->config->{'DB::Schema'}->{'connect_info'},
);


and similarly:

Can't locate object method "path_to" via package "MyApp" at
lib/MyApp/View/TT.pm line 20.

package MyApp::View::TT;
use strict;
use base 'Catalyst::View::TT'
__PACKAGE__->config(
TEMPLATE_EXTENSION => '.tt2',
INCLUDE_PATH => [
MyApp->path_to('root/src'),
],
TIMER => 0,
WRAPPER => 'wrapper.tt2' ,
);


Do I need to 'use MyApp'? I am not sure why it's not searching back up
the tree to find these method from Catalyst.

Can anyone advice me please?
Dp.

Search Discussions

  • Tomas Doran at Mar 3, 2009 at 9:50 am

    On 3 Mar 2009, at 09:40, Dermot wrote:

    Hi,

    Running prove over my t directoty is giving me errors:

    Error: Can't locate object method "config" via package "MyApp" at
    lib/MyApp/Model/DB.pm line 7. <snip>
    Can't locate object method "path_to" via package "MyApp" at
    lib/MyApp/View/TT.pm line 20. <snip>
    Do I need to 'use MyApp'? Yes.
    I am not sure why it's not searching back up
    the tree to find these method from Catalyst.
    Loading a leaf node in your object graph does not imply loading all
    of its parent nodes.

    Unless you do something which implicitly loads MyApp first, then
    these classes won't work. You'll be able to see this by using perl -c
    lib/MyApp/View/TT.pm, which will break.

    Cheers
    t0m
  • Dermot at Mar 3, 2009 at 10:22 am
    2009/3/3 Tomas Doran <bobtfish@bobtfish.net>:
    On 3 Mar 2009, at 09:40, Dermot wrote:

    Hi,
    Do I need to 'use MyApp'? Yes.
    I am not sure why it's not searching back up
    the tree to find these method from Catalyst.
    Loading a leaf node in your object graph does not imply loading all of its
    parent nodes.
    Is this because of use base? I was under the impression that the
    inheritance search would go up to the parent.
    Unless you do something which implicitly loads MyApp first, then these
    classes won't work. You'll be able to see this by using perl -c
    lib/MyApp/View/TT.pm, which will break.

    perl -c lib/MyApp/View/TT.pm is syntax OK.

    perl -Ilib -MMyApp::Model::DB -e "print MyApp::->config->{"connect_info"}"
    Can't locate object method "config" via package

    I guess -c doesn't checks for methods actually exist.

    use MyApp has fixed it.
    Thanx Tomas.
    Dp.
  • Tomas Doran at Mar 3, 2009 at 7:21 pm

    On 3 Mar 2009, at 10:22, Dermot wrote:
    Loading a leaf node in your object graph does not imply loading
    all of its
    parent nodes.
    Is this because of use base? I was under the impression that the
    inheritance search would go up to the parent.
    Correct, but MyApp::Model::Foo ISA Catalyst::Model::Foo, which ISA
    Catalyst::Model, which ISA Catalyst::Component

    No MyApp or Catalyst involved, ergo they're not loaded.
    I guess -c doesn't checks for methods actually exist.
    No, I'm just being dumb - all the code calling MyApp is runtime code,
    and -c only parses the file and runs compile time code (i..e code
    inside BEGIN blocks).

    So please excuse me for talking (partially) rubbish when I was pre-
    coffee this morning ;)

    Cheers
    t0m

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 3, '09 at 9:40a
activeMar 3, '09 at 7:21p
posts4
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Tomas Doran: 2 posts Dermot: 2 posts

People

Translate

site design / logo © 2021 Grokbase