[Dbix-class] minimalistic Moose / DBIC glue module

BUCHMULLER Norbert norbi.lists at nix.hu
Tue May 25 19:28:45 GMT 2010


Hi Guys,

at the company where I work we are trying to make DBIC and Moose
befriend: ie. making the Result (Row) objects regular Moose objects (as
much as reasonable), so that we can use type constraints, triggers, ... on
columns as if they were normal attributes.

With the current best practice of double-declaring the accessors - ie.
using both "has 'x' => ..." and "__PACKAGE__>add_columns('x', ...)" - it
does not work, as Class::Accessor::Grouped overwrites the Moose-generated
accessors with its own generated accessors; also it's ugly to repeat each
column name. (Even if it had not overwritten it, it still wouldn't work
for at least 2 reasons: 1. the slots accessed by the Moose accessors are
in the top-level of the blessed hashref, while the CAG accessors
generated by DBIC are in the hashref under '_column_data', 2. the Moose
accessors don't know about inflation/deflation, the dirty flag, etc.)

I've heard about MooseX::DBIC, but we want something that works *now*.
Having something simpler than that is also an advantage for us (till it
matures). I'd also prefer a solution that does not define a new syntax
(for now, while all the existing docs/examples are using the plain old
DBIC syntax).

So I came up with a more minimalistic approach that only solves the above
two problems and nothing else:

1. it installs Moose accessors on the Result (Row) objects that perform
get_column()/set_column() under the hood

2. it saves you from repeating the column definition ("has" and
"->add_columns")

You can find the code here: http://github.com/mendel/MooseX-DBIC-AddColumn

What do you think of it? Am I on the right track at all?

norbi



More information about the DBIx-Class mailing list