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

Hermida, Leandro Leandro.Hermida at fmi.ch
Mon Dec 4 14:11:05 GMT 2006



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.

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





More information about the Catalyst mailing list