Please find this module at
http://github.com/jhallock/MooseX-DBI/tree/master#<http://github.com/jhallock/MooseX-DBI/tree/master>
(for now).
I'm just looking for some feedback before I send this off to CPAN.
It is a module that works with DBI to store and retrieve objects from a
database. When storing objects have objects that implement MooseX::DBI as
attributes - the value is stored is the primary key of the object. When
restoring objects from the database - the opposite is true, MooseX::DBI will
load the object data from the database and instantiate it.
It is also possible to specify custom inflators and deflators for other kinds
of objects and data types.
subtype 'My.Date'
=> from 'DateTime';
inflate 'My.Date'
=> via { DateTime::Format::SQLite->parse($_) };
deflate 'My.Date'
=> via { $_->ymd };
has 'date_attribute' (
is => 'rw',
isa => 'My.Date'
);
I'm not stuck on the inflate and deflate methods as the sugar to perform the
flattening/instantiation. It's seems appropriate to change them to something
else, to keep the inflate and deflate words open for use in a serialization
module - where inflate would create an object from a stored format, and deflate
would turn an object into a particular format.
Originally when I started making this module - It was an extension on to
MoooseX::Storage which is a serialization package. I then moved to making it
part of a new serialization package MooseX::Serialize because of some
limitations in the MooseX::Storage design (namely, I wanted to be able to use
multiple engines at once - what if someone wanted to primarily serialize to a
DBI, but would also like to create XML files to send out).
So once I had MooseX::Serialize and MooseX::Serialize::DBI in the works inflate
and deflate came into play - and their role was to serialize/restore a data
structure/object from a specified format, where to be used more like this:
inflate 'My.Date'
=> via { date_obect_from_xml_string($_) }
=> from 'XML';
inflate 'My.Date'
=> via { DateTime::Format::SQLite->parse($_) }
=> from 'DBI';
deflate 'My.Date'
=> via { date_object_to_xml_string($_) }
=> from 'XML';
deflate 'My.Date'
=> via { $_->ymd }
=> from 'DBI';
So, then I abandoned the idea of creating another serialization package for a
couple of reasons:
1. One already existed
2. It was beyond the scope of what I really wanted to do, which is a
package to serialize/to from a DBI object
3. By using MooseX::DBI and MooseX::Storage - one can serialize the same
object to a database and another format
4.
So that is where inflate and deflate come from - should I change them, if so,
what to?
Also, please feel from to comment on any part of the module - I would like to
hear some feedback and make any significant changes before the first release on
CPAN - I don't want to be stuck with something later because it wasn't thought
through now. Please feel free to write test cases as well as suggest features.
Thank you fellow Moosers!
-Jeffrey Hallock