[Catalyst] setting up files and namespace for utilizing different models in the same catalyst app

John Napiorkowski jjn1056 at yahoo.com
Tue Dec 5 15:16:13 GMT 2006


--- "Hermida, Leandro" <Leandro.Hermida at fmi.ch> wrote:

> 
> 
> Hi everyone,
> 
> Sorry to send this post again, but I never really
> got any response from
> users as to advice on setting up namespaces in
> Catalyst when using more
> than one model for the same database in your
> Catalyst app.  Any
> suggestions/advice for what I have done below?  Also
> for the separate
> question about two responses saying MyApp::Web being
> the namespace for
> the catalyst app.  I didn't understand that since it
> seems that all
> Catalyst stuff should goes MyApp::Model, MyApp::View
> and
> MyApp::Controller and I have no control over this
> since when I initially
> run "catalyst.pl MyApp" it sets up these namespaces
> for me.

You can create as many of your own component
directories as you find useful.  Catalyst uses
'Module::Pluggable' for adding components, so you can
check the docs for that to see the best way to do this
for your needs.  I personally have a bunch of
controllers and views in a 'global' area that is
shared by several catalyst projects, so I have the
following in my yaml config:

setup_components:
  search_extra:
    - global

However I keep the MCV style names as I've found
trying to keep things simple and as standard as
possible makes it easier to share development with my
team.

AFAIK regarding database stuff, I also have more than
one model in most of my catalyst applications as I
break out the member and login stuff from the
application database.  The main disadvantage to doing
that is that it's hard to sensibly do joins, etc
across multiple DBIx schemas.  But if you don't need
that then if should just work by using the Catalyst
DBIC Schema helper multiple times and setting your
configuration accordingly.

--john



> 
> Thank you in advance,
> 
> Leandro Hermida
> 
> 
> -----Original Message-----
> From: Hermida, Leandro 
> Sent: Friday, November 24, 2006 17:35
> To: 'The elegant MVC web framework'
> Subject: RE: [Catalyst] setting up files and
> namespace for utilizing
> differentmodels in the same catalyst app
> 
> 
> Hello and Happy Thanksgiving,
> 
> What if one wanted to use more than one model for
> the same database?
> Sorry to make things difficult, I am a new user and
> I am trying to
> understand the proper way to set up the groundwork
> for a large project
> and I don't want there to be a gotcha or annoyance
> because I didn't
> think something through down the road. So if I
> wanted to use two models
> for the library (for example DBIx::Class and DBI)
> 
> Would it be for the database,
> 
> MyApp::Library::DBIC::Schema
> MyApp::Library::DBI
> 
> then for the model,
> 
> MyApp::Model::Library::DBIC::Schema
> MyApp::Model::Library::DBI
> 
> then in code,
> 
>
$c->model('Library::DBIC::Schema')->resultset('Book')->all;
> 
> Etc. ?
> 
> 
> I am also very confused about what both you and A.
> Berlin wrote about
> the namespace catalyst or web app.  Maybe I am not
> far enough yet in the
> tutorial?  What did you mean by:
> 
> MyApp::Web -> catalyst app
> 
> What does this tree of code hold?  It seems so far
> from the tutorial
> that everything goes under MyApp::Model,
> MyApp::View, or
> MyApp::Controller to defined the catalyst app but
> maybe I am missing
> something.
> 
> Thank you,
> 
> Leandro Hermida
> 
> 
> Matt S Trout wrote:
> > Ash Berlin wrote:
> >> Matt S Trout wrote:
> >>> Hermida, Leandro wrote:
> >>>> What would people recommend as a naming
> convention and namespace 
> >>>> setup if one wanted to eventually use more than
> one model inside of
> 
> >>>> the same Catalyst app?
> >>>
> >>> I tend to use
> >>>
> >>> MyApp::Library -> book+author DB
> >>> MyApp::Forum -> forum DB
> >>> MyApp::Web -> Catalyst app
> >>>
> >>>
> >>>
> >> 
> >> In that situation I'd go for
> >> 
> >> MyApp::Schema::Library
> >> MyApp::Schema::Forum
> >> 
> >> then MyApp or MyApp::Web
> >> 
> >> 
> >> (Or rather that's the kind of thing I've used for
> my current project)
> >> 
> >> Ash
> >
> > I don't like doing that. What if I move it to
> being a remote model via
> 
> > RPC, or an LDAP directory, or something? It isn't
> a DBIC schema 
> > anymore, so it shouldn't be named as such :)
> 
> 
>
------------------------------------------------------------------------
> --------
> From: Hermida, Leandro
> [mailto:Leandro.Hermida at fmi.ch]
> Sent: Thursday, November 23, 2006 18:09
> To: The elegant MVC web framework
> Subject: [Catalyst] setting up files and namespace
> for utilizing
> differentmodels in the same catalyst app
> 
> 
> Hello,
> 
> I am working through the tutorial and a question
> came to mind when
> looking at the naming conventions used.
> 
> For DBIx::Class,
> 
> lib/MyAppDB.pm
> lib/MyAppDB/Book.pm
> lib/MyAppDB/Author.pm
> lib/MyAppDB/BookAuthor.pm
> 
> Then for the Catalyst model,
> 
> lib/MyApp/Model/MyAppDB.pm
> 
> and in code,
> 
> $c->model('MyAppDB')->resultset('Book')->all;
> 
> What would people recommend as a naming convention
> and namespace setup
> if one wanted to 
> eventually use more than one model inside of the
> same Catalyst app?
> 
> would it be something like:
> 
> For DBIx::Class,
> 
> lib/MyApp/DBIC/Schema.pm
> lib/MyApp/DBIC/Schema/Book.pm
> lib/MyApp/DBIC/Schema/Author.pm
> lib/MyApp/DBIC/Schema/BookAuthor.pm
> 
> For Catalyst,
> 
> lib/MyApp/Model/DBIC/Schema.pm
> 
> and in code,
> 
> $c->model('DBIC::Schema')->resultset('Book')->all;
> 
> 
> Leandro Hermida
> 
> 
> 
> _______________________________________________
> List: Catalyst at 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/
> 



 
____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com.  Try it now.



More information about the Catalyst mailing list