[Dbix-class] load_classes and common base class

Bill Moseley moseley at hank.org
Sat Apr 21 14:53:44 GMT 2007


Ok, get ready for a bunch of beginner questions...


What's the recommended was to setup a common base class for all the
result sources (table classes)?  A base class where I can put methods
that can be called on any table object.

Should I have each class inherit from a base class and then have that
base class inherit from DBIx::Class?  Or specify both DBIx::Class and
my base class in 'use base'?

I assume I can't use my base schema class (where I call load_classes)
as my base class as is done with CDBI.  Although that would seem a
natural place.


I looked at compose_namespace(), but I'm not clear from the docs if
that's what I need.



With CDBI I got tired or typing the same things in my table classes --
plus table classes were useful in more than on project, so I set them
up so I didn't type the namespace more than once.

So instead of:

    package My::App::Foo::Album;
    use base 'My::App::Foo';

    __PACKAGE->table( 'album' );
    __PACKAGE->has_many( tracks => 'My::App::Foo::Track' );

I just wrote:

    package My::App::Foo::Album;

    __PACKAGE__->table( 'album' );
    __PACKAGE__->has_many( tracks => 'Track' );

Where my load_classes would setup the inheritance before loading the
class, and relationship setup assumed the base class (a "+" prefix on
a class would say to not prefix it automatically).





-- 
Bill Moseley
moseley at hank.org




More information about the Dbix-class mailing list