[Catalyst] catalyst tutorial: MyAppDB/Book.pm
vs. MyApp/Model/Book.pm
Marcello Romani
mromani at ottotecnica.com
Tue May 15 07:37:26 GMT 2007
mla ha scritto:
> I just finished getting the tutorial project working.
>
> The thing I'm not clear on is this separation between lib/MyAppDB/
> and lib/MyApp/Model/
>
> The tutorial says:
>
> "With Catalyst::Model::DBIC::Schema you essentially end up with two sets
> of model classes (only one of which you write... the other set is
> created automatically in memory when your Catalyst application
> initializes). For this tutorial application, the important points to
The dbic classes can be written by hand (which I find easier), or
generated by the deploy method, and then hand-tuned.
> remember are: you write the result source files in MyAppDB, but within
> Catalyst you use the automatically created model classes in MyApp::Model."
>
> So using DBIC::Schema, I would never create anything within the
> lib/MyApp/Model directory, other than the MyAppDB.pm module?
In MyApp/Model I usually have only MyAppDB.pm, which role is to expose
the DBIC::Schema classes under MyAppDB/ as a catalyst model.
This doesn't mean however that "I would never create anything" else. If
all I need is one dbic schema, then the answer to your question is "yes".
On the other hand, if I need for example to access two databases, then I
could have another dbic-schema folder (e.g. lib/MyAppDB2) and another
model class (lib/MyApp/Model/MyAppDB2.pm) to expose it to cat like the
first one.
Or I could have some other type of data that don't live in a database or
that I can't/don't want to access via dibc-class. In this case I could
write some classes under lib/MyApp/Model that directly access that data,
or better yet, have a set of classes (not tied to Catalyst) that deal
with the data and expose them as a cat model via one or more wrapper
class(es) (e.g. lib/MyApp/Model/ExtData.pm).
>
> All the real models live in lib/MyAppDB? And if I wanted to use a
> model *outside* catalyst, I'd use MyAppDB::Book, but within
> catalyst it would be MyApp::Book?
>
> Is this how most of you structure your projects? Is there a way
> to get the real models in lib/MyApp/Model?
>
> Thanks.
>
>
> _______________________________________________
> 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/
>
>
Also, what do you mean by "real" models ?
Just my 2 cents.
HTH
--
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com
More information about the Catalyst
mailing list