FAQ
Hello,

I have the following folder hierarchy for a project which will have a
web component that is driven by Catalyst:

MyProj/
lib/
sql/
web/ <--- Catalyst application dir created using catalyst.pl
lib/
root/
script/
t/

My DBIC::Schema ORM setup and files are in the top lib directory outside
of the Catalyst directory because I plan to use them in more than just
the web component. Now when I create my Catalyst DBIC::Schema model and
then try to start the test server as I expected it couldn't instantiate
my model component because it can't locate the DBIC::Schema file in
@INC.

What is the best way to get the top-level lib directory into Catalyst's
@INC? Should I do a "use lib '...'" somewhere in a Catalyst file?

Leandro

Search Discussions

  • Jonathan Rockway at Dec 12, 2006 at 5:12 pm

    Hermida, Leandro wrote:
    What is the best way to get the top-level lib directory into Catalyst's
    @INC? Should I do a "use lib '...'" somewhere in a Catalyst file?
    myapp_server.pl, probably (and the other ones). Catalyst::Test (etc.)
    won't use this, though, so you should run your tests with the
    appropriate -I flags (which you could do instead of changing myapp_*.pl):

    $ perl -Ilib -Iweb/lib web/script/myapp_server.pl

    or
    $ prove -Ilib -Iweb/lib web/t

    etc.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
  • Matt S Trout at Dec 12, 2006 at 5:18 pm

    On 12 Dec 2006, at 16:57, Hermida, Leandro wrote:
    Hello,

    I have the following folder hierarchy for a project which will have a
    web component that is driven by Catalyst:

    MyProj/
    lib/
    sql/
    web/ <--- Catalyst application dir created using catalyst.pl
    lib/
    root/
    script/
    t/
    Why not just make your Catalyst app as MyProj::Web so its files live in

    MyProj/lib/MyProj/Web.pm
    MyProj/lib/MyProj/Web/(Controller|Model|View)/...

    --
    Matt S Trout, Technical Director, Shadowcat Systems Ltd.
    Offering custom development, consultancy and support contracts for
    Catalyst,
    DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
    details.
    + Help us build a better perl ORM: http://dbix-
    class.shadowcatsystems.co.uk/ +
  • Leandro Hermida at Dec 13, 2006 at 10:03 am

    From: Matt S Trout
    On 12 Dec 2006, at 16:57, Hermida, Leandro wrote:

    Hello,

    I have the following folder hierarchy for a project which
    will have a
    web component that is driven by Catalyst:

    MyProj/
    lib/
    sql/
    web/ <--- Catalyst application dir created using catalyst.pl
    lib/
    root/
    script/
    t/
    Why not just make your Catalyst app as MyProj::Web so its
    files live in

    MyProj/lib/MyProj/Web.pm
    MyProj/lib/MyProj/Web/(Controller|Model|View)/...
    Hello,

    Sorry for not mentioning it in the original email but I did run
    catalyst.pl MyProj::Web to create the Catalyst project (based on your
    and A. Berlin's earlier advice, thank you) so that in the lib directory
    catalyst related stuff has its own namespace and separation. But it
    doesn't seem to fix the problem (maybe I am not seeing something?). It
    seems from what you suggest that then all web application stuff has to
    then be in the top-level MyProj folder. If I start over:

    [hermida@dla2 ~]$ catalyst.pl MyProj::Web
    created "MyProj-Web"
    created "MyProj-Web/script"
    created "MyProj-Web/lib"
    created "MyProj-Web/root"
    created "MyProj-Web/root/static"
    created "MyProj-Web/root/static/images"
    created "MyProj-Web/t"
    created "MyProj-Web/lib/MyProj/Web"
    created "MyProj-Web/lib/MyProj/Web/Model"
    created "MyProj-Web/lib/MyProj/Web/View"
    created "MyProj-Web/lib/MyProj/Web/Controller"
    created "MyProj-Web/myproj_web.yml"
    created "MyProj-Web/lib/MyProj/Web.pm"
    created "MyProj-Web/lib/MyProj/Web/Controller/Root.pm"
    created "MyProj-Web/README"
    created "MyProj-Web/Changes"
    created "MyProj-Web/t/01app.t"
    created "MyProj-Web/t/02pod.t"
    created "MyProj-Web/t/03podcoverage.t"
    created "MyProj-Web/root/static/images/catalyst_logo.png"
    created "MyProj-Web/root/static/images/btn_120x50_built.png"
    created "MyProj-Web/root/static/images/btn_120x50_built_shadow.png"
    created "MyProj-Web/root/static/images/btn_120x50_powered.png"
    created "MyProj-Web/root/static/images/btn_120x50_powered_shadow.png"
    created "MyProj-Web/root/static/images/btn_88x31_built.png"
    created "MyProj-Web/root/static/images/btn_88x31_built_shadow.png"
    created "MyProj-Web/root/static/images/btn_88x31_powered.png"
    created "MyProj-Web/root/static/images/btn_88x31_powered_shadow.png"
    created "MyProj-Web/root/favicon.ico"
    created "MyProj-Web/Makefile.PL"
    created "MyProj-Web/script/myproj_web_cgi.pl"
    created "MyProj-Web/script/myproj_web_fastcgi.pl"
    created "MyProj-Web/script/myproj_web_server.pl"
    created "MyProj-Web/script/myproj_web_test.pl"
    created "MyProj-Web/script/myproj_web_create.pl"
    [hermida@dla2 ~]$ ll MyProj-Web/
    total 32
    -rw-rw-r-- 1 hermida hermida 150 Dec 13 10:44 Changes
    drwxrwxr-x 3 hermida hermida 4096 Dec 13 10:44 lib
    -rw-rw-r-- 1 hermida hermida 462 Dec 13 10:44 Makefile.PL
    -rw-rw-r-- 1 hermida hermida 22 Dec 13 10:44 myproj_web.yml
    -rw-rw-r-- 1 hermida hermida 57 Dec 13 10:44 README
    drwxrwxr-x 3 hermida hermida 4096 Dec 13 10:44 root
    drwxrwxr-x 2 hermida hermida 4096 Dec 13 10:44 script
    drwxrwxr-x 2 hermida hermida 4096 Dec 13 10:44 t
    [hermida@dla2 ~]$

    As mentioned this will be a larger project where only a part of it is
    the web application but all the code will need to share libraries.
    Where will I put all of the directories, code and other files that are
    not related at all to the web application but will need to use libraries
    in lib? It doesn't seem to make sense to have it right in the web
    application folder. This is why I made a master MyProj folder, renamed
    MyProj-Web to "web" and put it inside of MyProj. Then there can be a
    nice separation of components and the project can grow.

    Leandro
  • Matt S Trout at Dec 13, 2006 at 2:29 pm
    On 13 Dec 2006, at 10:03, Hermida, Leandro wrote:
    From: Matt S Trout
    On 12 Dec 2006, at 16:57, Hermida, Leandro wrote:

    Hello,

    I have the following folder hierarchy for a project which
    will have a
    web component that is driven by Catalyst:

    MyProj/
    lib/
    sql/
    web/ <--- Catalyst application dir created using catalyst.pl
    lib/
    root/
    script/
    t/
    Why not just make your Catalyst app as MyProj::Web so its
    files live in

    MyProj/lib/MyProj/Web.pm
    MyProj/lib/MyProj/Web/(Controller|Model|View)/...
    Hello,

    Sorry for not mentioning it in the original email but I did run
    catalyst.pl MyProj::Web to create the Catalyst project (based on your
    and A. Berlin's earlier advice, thank you) so that in the lib
    directory
    catalyst related stuff has its own namespace and separation. But it
    doesn't seem to fix the problem (maybe I am not seeing
    something?). It
    seems from what you suggest that then all web application stuff has to
    then be in the top-level MyProj folder. If I start over:

    [hermida@dla2 ~]$ catalyst.pl MyProj::Web
    created "MyProj-Web"
    created "MyProj-Web/script"
    created "MyProj-Web/lib"
    created "MyProj-Web/root"
    created "MyProj-Web/root/static"
    created "MyProj-Web/root/static/images"
    created "MyProj-Web/t"
    created "MyProj-Web/lib/MyProj/Web"
    created "MyProj-Web/lib/MyProj/Web/Model"
    created "MyProj-Web/lib/MyProj/Web/View"
    created "MyProj-Web/lib/MyProj/Web/Controller"
    created "MyProj-Web/myproj_web.yml"
    created "MyProj-Web/lib/MyProj/Web.pm"
    created "MyProj-Web/lib/MyProj/Web/Controller/Root.pm"
    created "MyProj-Web/README"
    created "MyProj-Web/Changes"
    created "MyProj-Web/t/01app.t"
    created "MyProj-Web/t/02pod.t"
    created "MyProj-Web/t/03podcoverage.t"
    created "MyProj-Web/root/static/images/catalyst_logo.png"
    created "MyProj-Web/root/static/images/btn_120x50_built.png"
    created "MyProj-Web/root/static/images/btn_120x50_built_shadow.png"
    created "MyProj-Web/root/static/images/btn_120x50_powered.png"
    created "MyProj-Web/root/static/images/btn_120x50_powered_shadow.png"
    created "MyProj-Web/root/static/images/btn_88x31_built.png"
    created "MyProj-Web/root/static/images/btn_88x31_built_shadow.png"
    created "MyProj-Web/root/static/images/btn_88x31_powered.png"
    created "MyProj-Web/root/static/images/btn_88x31_powered_shadow.png"
    created "MyProj-Web/root/favicon.ico"
    created "MyProj-Web/Makefile.PL"
    created "MyProj-Web/script/myproj_web_cgi.pl"
    created "MyProj-Web/script/myproj_web_fastcgi.pl"
    created "MyProj-Web/script/myproj_web_server.pl"
    created "MyProj-Web/script/myproj_web_test.pl"
    created "MyProj-Web/script/myproj_web_create.pl"
    [hermida@dla2 ~]$ ll MyProj-Web/
    total 32
    -rw-rw-r-- 1 hermida hermida 150 Dec 13 10:44 Changes
    drwxrwxr-x 3 hermida hermida 4096 Dec 13 10:44 lib
    -rw-rw-r-- 1 hermida hermida 462 Dec 13 10:44 Makefile.PL
    -rw-rw-r-- 1 hermida hermida 22 Dec 13 10:44 myproj_web.yml
    -rw-rw-r-- 1 hermida hermida 57 Dec 13 10:44 README
    drwxrwxr-x 3 hermida hermida 4096 Dec 13 10:44 root
    drwxrwxr-x 2 hermida hermida 4096 Dec 13 10:44 script
    drwxrwxr-x 2 hermida hermida 4096 Dec 13 10:44 t
    [hermida@dla2 ~]$

    As mentioned this will be a larger project where only a part of it is
    the web application but all the code will need to share libraries.
    Where will I put all of the directories, code and other files that are
    not related at all to the web application but will need to use
    libraries
    in lib? It doesn't seem to make sense to have it right in the web
    application folder. This is why I made a master MyProj folder,
    renamed
    MyProj-Web to "web" and put it inside of MyProj. Then there can be a
    nice separation of components and the project can grow.
    It's a question of how you look at it -

    You're asking why the rest of the app should be in the web
    application directory

    I'm asking why the web part can't be in the main app directory :)

    --
    Matt S Trout, Technical Director, Shadowcat Systems Ltd.
    Offering custom development, consultancy and support contracts for
    Catalyst,
    DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
    details.
    + Help us build a better perl ORM: http://dbix-
    class.shadowcatsystems.co.uk/ +
  • Dave Howorth at Dec 13, 2006 at 2:59 pm

    Matt S Trout wrote:
    I'm asking why the web part can't be in the main app directory :)
    I've been reading this thread with interest because Leandro's
    description seems to fit my situation as well. This seems like a pretty
    lame response. Does it mean that Catalyst can't be configured to live in
    a separate place from the bulk of the 'business' logic?

    The ability to put different bits of an application suite in different
    places is a pretty useful capability for application designers. If every
    framework said that it was going to be top of the tree, life would be
    difficult, IMHO. I still have nightmares about all the event-driven
    frameworks that assumed *they* were going to be the one that had control
    of the select/poll loop, for example.

    The ability to separate concerns is a fundamental strategy in software
    engineering.

    Or am I misunderstanding?

    Cheers, Dave
  • Brandon Black at Dec 13, 2006 at 4:11 pm

    On 12/13/06, Dave Howorth wrote:
    Matt S Trout wrote:
    I'm asking why the web part can't be in the main app directory :)
    I've been reading this thread with interest because Leandro's
    description seems to fit my situation as well. This seems like a pretty
    lame response. Does it mean that Catalyst can't be configured to live in
    a separate place from the bulk of the 'business' logic?
    Yes, it can be separated any way you like. All of the above ideas in
    this discussion are just matters of preference and/or policy. You can
    put your cat app anywhere with respect to the rest of your business
    logic and other related scripts and modules, you'll just need to take
    the appropriate steps to get @INC set up correctly for however you've
    laid things out, so that cat can find your business logic.

    I typically put commandline scripts, database maintenance stuff, and
    my DBIx::Class schema in a seperate directory parallel with the
    related cat app, and stuff @INC via FindBin at the top of the scripts.

    -- Brandon
  • Brian Kirkbride at Dec 13, 2006 at 4:40 pm

    Dave Howorth wrote:
    Matt S Trout wrote:
    I'm asking why the web part can't be in the main app directory :)
    I've been reading this thread with interest because Leandro's
    description seems to fit my situation as well. This seems like a pretty
    lame response. Does it mean that Catalyst can't be configured to live in
    a separate place from the bulk of the 'business' logic?
    I use separate directories because my business logic and catalyst code are in
    different SVN trees. For me it's as simple as adding:

    use lib "$FindBin::Bin/../../MyApp/lib";

    to the scripts in MyApp-Web/script/.

    If you are using mod_perl for production you will need to specify both your
    MyApp-Web and MyApp paths in it's setup.

    Hope that helps,
    Brian Kirkbride
  • Christopher H. Laco at Dec 13, 2006 at 5:25 pm

    Brian Kirkbride wrote:
    Dave Howorth wrote:
    Matt S Trout wrote:
    I'm asking why the web part can't be in the main app directory :)
    I've been reading this thread with interest because Leandro's
    description seems to fit my situation as well. This seems like a pretty
    lame response. Does it mean that Catalyst can't be configured to live in
    a separate place from the bulk of the 'business' logic?
    I use separate directories because my business logic and catalyst code
    are in different SVN trees. For me it's as simple as adding:

    use lib "$FindBin::Bin/../../MyApp/lib";

    to the scripts in MyApp-Web/script/.

    If you are using mod_perl for production you will need to specify both
    your MyApp-Web and MyApp paths in it's setup.

    Hope that helps,
    Brian Kirkbride
    I can't imagine life before $FindBin::Bin

    -=Chris

    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: signature.asc
    Type: application/pgp-signature
    Size: 189 bytes
    Desc: OpenPGP digital signature
    Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061213/09705b63/signature-0001.pgp
  • Aristotle Pagaltzis at Dec 13, 2006 at 7:06 pm

    * Christopher H. Laco [2006-12-13 18:40]:
    I can't imagine life before $FindBin::Bin
    Despite the fact that it?s perverse and horribly broken [1]?

    [1]: http://www.perlmonks.org/index.pl?node_idA213

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Adam Jacob at Dec 13, 2006 at 8:27 pm

    On Wed, Dec 13, 2006 at 08:06:02PM +0100, A. Pagaltzis wrote:
    Despite the fact that it?s perverse and horribly broken [1]?

    [1]: http://www.perlmonks.org/index.pl?node_idA213
    Yes, despite that. :)

    Adam
  • Matt S Trout at Dec 13, 2006 at 7:10 pm

    On 13 Dec 2006, at 14:59, Dave Howorth wrote:

    Matt S Trout wrote:
    I'm asking why the web part can't be in the main app directory :)
    I've been reading this thread with interest because Leandro's
    description seems to fit my situation as well. This seems like a
    pretty
    lame response. Does it mean that Catalyst can't be configured to
    live in
    a separate place from the bulk of the 'business' logic?
    Yes it does, it's impossible to write an application that depends on
    external code - that's why you can't use CPAN libraries with Catalyst

    ...

    no, wait, you can :)
    The ability to put different bits of an application suite in different
    places is a pretty useful capability for application designers.
    And if you want to do that, you can happily have a MyApp-Base
    distribution, a MyApp-Web distribution, etc.

    Just make them normal perl dists with appropriate dependencies.
    catalyst.pl creates you a valid CPAN dist which makes it trivial to
    do that for the web part - anything else should be done the same way.
    The ability to separate concerns is a fundamental strategy in software
    engineering.

    Or am I misunderstanding?
    I think you and Leandro are both trying to do something the hard way.

    If it lives as part of the main dist, put it in lib/ like normal.

    If it wants to be separate, make it a separate dist that depends on
    the common stuff.

    Screwing around with @INC when you can just write stuff that can be
    'make install'ed is the only thing here I'd call lame :)

    --
    Matt S Trout, Technical Director, Shadowcat Systems Ltd.
    Offering custom development, consultancy and support contracts for
    Catalyst,
    DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
    details.
    + Help us build a better perl ORM: http://dbix-
    class.shadowcatsystems.co.uk/ +
  • Jonathan Rockway at Dec 13, 2006 at 7:41 pm

    Screwing around with @INC when you can just write stuff that can be
    'make install'ed is the only thing here I'd call lame :)
    YOU CAN'T PUT CODE IN A RANDOM LOCATION AND EXPECT CATALYST TO FIND IT,
    RETARDO.

    Apologies to MJD.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 12, '06 at 4:57p
activeDec 13, '06 at 8:27p
posts13
users9
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase