[CDBI] Does Class::DBI require hash-based objects?

Steven Mackenzie steven.mackenzie at aptile.co.uk
Tue Jan 3 19:12:48 GMT 2006

Jesse Sookne wrote:

> Does Class::DBI require that its subclasses (application base classes
> as described in the Class::DBI doc) use hash-based objects?
I've been adding attributes to Class::DBI objects using the "inside out"
classes/hashes described in Perl Best Practices. I haven't seen any
conflict with the hash based attributes used in the CDBI part of the
hierarchy, though I don't actually use Class::Std, just the technique
described in that book.

Also, I think that Class::DBI uses closures internally, though I'm not
sure what for (I'm only really interested in the API, and new to Perl).
I don't think that will conflict with add new attributes via the
Class::Std mechanisms either.

A part of the API that did cause me confusion though was that I found
objects being DESTROYed before I expected them to be. I had assumed, for
example, that if I accessed rows in a child table via an accessor in the
parent (via a has_many relation) that the children would stay referenced
while I maintained the reference to the parent table. I don't know why I
assumed that, and it is wrong.

As long as I maintain my own references to objects, my attributes remain
with the object.

However, a further wrinkle, which you will find in the list archives, is
that in certain scenarios Class::DBI will return more than one object to
represent the same row in the database. Look in the archives for "Bug
with sequences and the object cache".

More information about the ClassDBI mailing list