[Dbix-class] using DBIx::Class::CDBICompat

Brandon Black blblack at gmail.com
Tue May 22 21:57:24 GMT 2007


On 5/22/07, John Goulah <jgoulah at gmail.com> wrote:
> On 5/22/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
> > What I'd tend to do is have 'MyApp::Schema::Foo' and then
> > 'MyApp::ResultSet::Foo' - putting the DB in 'MyDB' is awful design, your
> > project should only use *one* top-level namespace.
>
> Fair enough, and good to know.
>
> The only reason I did it that way is because I'm new to Catalyst and thats
> what the tutorial suggests
>
> from the Calalyst::Manual::Tutorial
> "First, create a directory to hold the class: $ mkdir lib/MyAppDB
>
>
> so probably teaching newbs bad design isnt the best idea....
>

Well, first off, you can't help the fact that newbies have bad design :)

But secondly, Matt's point about namespaces doesn't mean you can't
separate your DBIC stuff from your Cat stuff.  I won't bother you with
examples, but obviously your namespace is yours, do something that
makes sense to you and do it cleanly.

Ignoring the Cat-vs-DBIC namespace issue, within the namespace of a
DBIC Schema, I prefer to do:

Foo (my schema class)
Foo::Result::Frub (a result class)
Foo::ResultSet::Frub (corresponding resultset class)

When DBIC 0.08 goes out (fairly soon I think), there will be a new
optional replacement for load_classes available, called
"load_namespaces", which supports just such a layout without manually
listing all of the classes involved.  It also automatically sets
Foo::ResultSet::Frub as Foo::Result::Frub's resultset_class based on
the matching names, if you didn't manually do something different
yourself.

See: http://search.cpan.org/~jrobinson/DBIx-Class-0.07999_02/lib/DBIx/Class/Schema.pm#load_namespaces



More information about the Dbix-class mailing list