FAQ
Is there a variable somewhere that can tell me when Catalyst's
dev-server is starting up? Because it seems to be calling every method
I've written, but without parameters, which intentionally causes errors
when in production, but shouldn't during automated tests.



Thanks in anticipation

Lee

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070427/44b1af10/attachment.htm

Search Discussions

  • Marcello Romani at Apr 27, 2007 at 1:13 pm

    Lee Goddard ha scritto:
    Is there a variable somewhere that can tell me when Catalyst?s
    dev-server is starting up? Because it seems to be calling every method
    I?ve written, but without parameters, which intentionally causes errors
    when in production, but shouldn?t during automated tests.



    Thanks in anticipation

    Lee


    ------------------------------------------------------------------------

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    Can you be more specific ?

    What do you mean by 'calling every method I've written ?'

    --
    Marcello Romani
    Responsabile IT
    Ottotecnica s.r.l.
    http://www.ottotecnica.com
  • Lee Goddard at Apr 27, 2007 at 1:52 pm
    From: Marcello Romani
    Lee Goddard ha scritto:
    Is there a variable somewhere that can tell me when Catalyst's
    dev-server is starting up? Because it seems to be calling every
    method
    I've written, but without parameters, which intentionally causes
    errors
    when in production, but shouldn't during automated tests.

    Thanks in anticipation
    Can you be more specific ?

    What do you mean by 'calling every method I've written ?'
    Sorry: I meant when the server starts, it seems to attempt to call 'new'
    for every *.pm in MyApp::Model::* :

    Couldn't instantiate component "CTT::Model::SWF"

    Thanks
    Lee


    [undef] | Missing fields: path, filebase, filename |
    CTT/Model/File.pm CTT::Model::File::new 107
    [undef] | Couldn't instantiate component "CTT::Model::SWF", "Missing
    fields: path, filebase, filename at ../lib/CTT/Model/File.pm line 109
    CTT::Model::File::new('CTT::Model::SWF', 'CTT',
    'HASH(0x902fc10)') called at
    /usr/local/share/perl/5.8.4/Catalyst/Component.pm line 76
    Catalyst::Component::COMPONENT('CTT::Model::SWF', 'CTT',
    'HASH(0x902fc10)') called at /usr/local/share/perl/5.8.4/Catalyst.pm
    line 1873
    eval {...} called at /usr/local/share/perl/5.8.4/Catalyst.pm
    line 1873
    Catalyst::setup_component('CTT', 'CTT::Model::SWF') called at
    /usr/local/share/perl/5.8.4/Catalyst.pm line 1845
    Catalyst::setup_components('CTT') called at
    /usr/local/share/perl/5.8.4/Catalyst.pm line 872
    Catalyst::setup('CTT') called at ../lib/CTT.pm line 74
    require CTT.pm called at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90
    Catalyst::Test::import('Catalyst::Test', 'CTT') called at (eval
    3) line 2
    main::BEGIN() called at ../lib/CTT.pm line 0
    eval {...} called at ../lib/CTT.pm line 0
    eval 'package main;
    use Catalyst::Test @imports;

    ;' called at /usr/local/share/perl/5.8.4/Test/More.pm line 673
    Test::More::use_ok('Catalyst::Test', 'CTT') called at 01app.t
    line 9
    main::BEGIN() called at ../lib/CTT.pm line 0
    eval {...} called at ../lib/CTT.pm line 0" at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90
    Compilation failed in require at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90.
    5.8.4/Catalyst/Test.pm Catalyst::Test::import 90
  • Marcello Romani at Apr 27, 2007 at 2:55 pm

    Lee Goddard ha scritto:
    From: Marcello Romani
    Lee Goddard ha scritto:
    Is there a variable somewhere that can tell me when Catalyst's
    dev-server is starting up? Because it seems to be calling every
    method
    I've written, but without parameters, which intentionally causes
    errors
    when in production, but shouldn't during automated tests.

    Thanks in anticipation
    Can you be more specific ?

    What do you mean by 'calling every method I've written ?'
    Sorry: I meant when the server starts, it seems to attempt to call 'new'
    for every *.pm in MyApp::Model::* :

    Couldn't instantiate component "CTT::Model::SWF"

    Thanks
    Lee


    [undef] | Missing fields: path, filebase, filename |
    CTT/Model/File.pm CTT::Model::File::new 107
    [undef] | Couldn't instantiate component "CTT::Model::SWF", "Missing
    fields: path, filebase, filename at ../lib/CTT/Model/File.pm line 109
    CTT::Model::File::new('CTT::Model::SWF', 'CTT',
    'HASH(0x902fc10)') called at
    /usr/local/share/perl/5.8.4/Catalyst/Component.pm line 76
    Catalyst::Component::COMPONENT('CTT::Model::SWF', 'CTT',
    'HASH(0x902fc10)') called at /usr/local/share/perl/5.8.4/Catalyst.pm
    line 1873
    eval {...} called at /usr/local/share/perl/5.8.4/Catalyst.pm
    line 1873
    Catalyst::setup_component('CTT', 'CTT::Model::SWF') called at
    /usr/local/share/perl/5.8.4/Catalyst.pm line 1845
    Catalyst::setup_components('CTT') called at
    /usr/local/share/perl/5.8.4/Catalyst.pm line 872
    Catalyst::setup('CTT') called at ../lib/CTT.pm line 74
    require CTT.pm called at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90
    Catalyst::Test::import('Catalyst::Test', 'CTT') called at (eval
    3) line 2
    main::BEGIN() called at ../lib/CTT.pm line 0
    eval {...} called at ../lib/CTT.pm line 0
    eval 'package main;
    use Catalyst::Test @imports;

    ;' called at /usr/local/share/perl/5.8.4/Test/More.pm line 673
    Test::More::use_ok('Catalyst::Test', 'CTT') called at 01app.t
    line 9
    main::BEGIN() called at ../lib/CTT.pm line 0
    eval {...} called at ../lib/CTT.pm line 0" at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90
    Compilation failed in require at
    /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 90.
    5.8.4/Catalyst/Test.pm Catalyst::Test::import 90
    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    I suppose your model modules have something like:

    sub new {
    ...
    die unless defined ($options->{path});
    etc.
    }

    I've never written such Model/ modules. So far I've always used Model/
    modules to access DBIC schemas (and CDBI before that), so I've never had
    to write a new() method for those modules.

    Having said that, I think that one possible solution could be to get
    those parameters from the application config hash instead of expecting
    to have them passed to the constructor.

    Or maybe you should put those modules outside the Catalyst application,
    and write a Module/ wrapper that instantiates them by calling their
    constructors with appropriate arguments.

    Just my 2 (euro)cents.

    HTH.

    --
    Marcello Romani
    Responsabile IT
    Ottotecnica s.r.l.
    http://www.ottotecnica.com
  • Brian Cassidy at Apr 27, 2007 at 3:07 pm

    Lee Goddard wrote:

    Sorry: I meant when the server starts, it seems to attempt to call 'new'
    for every *.pm in MyApp::Model::* :
    Hopefully I recall how this works...

    Every Model::*, Controller::*, View::* (plus their short-names for
    back-compat) are instantiated via setup_components (see Catalyst.pm).

    Assuming the model inherits from Catalyst::Model, then the COMPONENT()
    sub is called. It in turn will either call in the parent COMPONENT()
    method or failing that, new() -- passing the context + config options.

    So, if you have a normal module that is used outside of Catalyst as your
    base class, then you have to work around that.

    package MyApp::Model::NormalThing;

    use base qw( NormalThing );

    sub COMPONENT {
    my( $class, $c, $config ) = @_;

    # return an instance of something
    }

    Sometimes that instance can be of the parent class, such as the case
    with my Gedcom model [1]:

    return $class->new( %$config );

    Othertimes you'd write a wrapper class does some re-dispatching.

    -Brian

    (Please, someone correct me if I'm in any way off on this.)

    [1]
    http://search.cpan.org/src/BRICAS/Catalyst-Model-Gedcom-0.03/lib/Catalyst/Model/Gedcom.pm
  • Matt S Trout at May 8, 2007 at 2:18 pm

    On Fri, Apr 27, 2007 at 01:53:00PM +0100, Lee Goddard wrote:
    From: Marcello Romani
    Lee Goddard ha scritto:
    Is there a variable somewhere that can tell me when Catalyst's
    dev-server is starting up? Because it seems to be calling every
    method
    I've written, but without parameters, which intentionally causes
    errors
    when in production, but shouldn't during automated tests.

    Thanks in anticipation
    Can you be more specific ?

    What do you mean by 'calling every method I've written ?'
    Sorry: I meant when the server starts, it seems to attempt to call 'new'
    for every *.pm in MyApp::Model::* :

    Couldn't instantiate component "CTT::Model::SWF"
    That's supposed to happen. Try making sure the tests can find a config file
    (see Plugin::ConfigLoader docs for what env var to set for this) that provides
    a suitable set of config info for them to be instantiated with.

    If you don't want the ::Model::* object instantiated, don't inherit from
    Catalyst::Model.

    Oh, and next time you ask the list for help, please explain the -actual-
    problem and the behaviour you're seeing rather than asking for help with
    your half-assed hack around it, you'll get better answers faster (nothing
    personal, this mistake is so common it's got its own name - "XY problem" :)

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director Want a managed development or deployment platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
    http://www.shadowcatsystems.co.uk/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 27, '07 at 12:32p
activeMay 8, '07 at 2:18p
posts6
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase