serializing objects

[prev] [thread] [next] [Date index for 2005/03/02]

From: Geoffrey Young
Subject: serializing objects
Date: 06:08 on 02 Mar 2005
hi all :)

I've been wanting to investigate Class::DBI for a while and I've recently
had the chance.  nice work all :)

one of the things I was trying to do was to serialize the various objects I
created then thaw them again later to re-populate the database.
unfortunately, I found that it's not all that easy to do, since when the
objects are thawed Class::DBI thinks the data is already in the database (as
it should I would think :)

anyway, I was able to work around this like so:

  no strict qw(refs);
  my $table = Storable::retrieve($frozentable);
  my $class = ref $table;
  my %columns = map { $_, $table->$_() } $class->primary_columns;


  $table->copy(\%columns);

but I guess I was hoping that there would be some kind of flush() object
method that would simply iterate over all the internal __Changed keys,
update them, then call update() or somesuch.

thoughts?  it doesn't seem too difficult to implement, but I wasn't sure if
I was missing the bigger picture - I'm using Essential for all my columns
and wonder if flushing a partial object would cause harm.

if this sounds kinda strange, well, I guess it is.  my goal at the moment is
to manage testing data in a very large database, and Class::DBI looks like a
great way to do that - I can provide a standard, known object from a
serialized state (created outside the test), then can use it as is or
manipulate specific fields as required in my tests.  then drop the tables
and do it all over again (and again, and again :)

anyway...

--Geoff

serializing objects
Geoffrey Young 06:08 on 02 Mar 2005

Re: serializing objects
Geoffrey Young 14:40 on 02 Mar 2005

Re: serializing objects
Michael G Schwern 20:09 on 03 Mar 2005

Generated at 00:32 on 04 Mar 2005 by mariachi v0.52