[CDBI] State of the DBIx::Class Class::DBI compatibility layer
Michael G Schwern <[email protected]> Wed, 13 Feb 2008 16:31:09 -0800
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi,gmane.comp.lang.perl.modules.dbix-class |
|---|---|
| Message-ID | <[email protected]> |
DBIx::Class::CDBICompat is in fantastic shape for anyone curious about
transitioning from Class::DBI to DBIx::Class. It's down to really niggling,
undocumented details, like the exact particulars of when lazy loading happens.
The improved DBIx::Class::CDBICompat is not available on CPAN but only from
its own branch. It keeps up to date with trunk changes. Eventually it will
merge into trunk once I get the attention of a DBIC person for a couple hours.
http://dev.catalyst.perl.org/repos/bast/DBIx-Class/0.08/branches/cdbicompat_integration
The critical thing to realize is that this is *not* a subclass or wrapper
around DBIx::Class but a series of plugins. When you use CDBICompat you get
DBIx::Class objects and all of DBIx::Class' features are available. This
allows one to ease into the new features offered by DBIx::Class without having
to rewrite your whole code base. One of the first things you'll want to look
at is DBIx::Class::ResultSet for all it's advanced search() features.
The CDBICompat documentation has been improved a bit to make it clearer how to
use it and what the limitations are. You should be able to just change
use base qw(Class::DBI);
with
use base qw(DBIx::Class::CDBICompat);
with the important caveat that relationships (has_a, has_many...) have to be
declared *after* all classes have been declared.
Bonus features:
$obj->{column} now works. I didn't want to emulate that hack, but the folks
who are paying me to do this needed it. Ironically, because it goes through a
tied scalar, it will be slower than $obj->column().
nocache() of Class::DBI::Plugin::NoCache is emulated so you can turn the
object cache off.
search_where() of Class::DBI::AbstractSearch is emulated, though there's not
much point because DBIC's search is almost exactly the same and better.
--
Life is like a sewer - what you get out of it depends on what you put into it.
- Tom Lehrer