Re: [CDBI] Using freeze/thaw to munge a column value.
[prev]
[thread]
[next]
[Date index for 2005/10/25]
Perrin Harkins writes:
> On Mon, 2005-10-24 at 11:45 -0700, George Hartzell wrote:
> > I want to create a simple class that maps to a two-column table, with
> > a key and a value (something to pass args around in Mason components,
> > since sessions don't behave well).
> [...]
> > Does anyone have a simpleton's example?
>
> This was my solution, for passing parameters to a job queue system that
> keeps state in the database. Probably could be more efficient.
>
> __PACKAGE__->has_a(
> 'parameters' => 'Arcos::DB::Job::Serialized',
> inflate => sub { Arcos::DB::Job::Serialized->inflate(shift) },
> deflate => sub {
> Arcos::DB::Job::Serialized->deflate(shift);
> });
>
> # define simple in-line class to handle serializing parameters
> BEGIN {
>
> package Arcos::DB::Job::Serialized;
> use Storable;
>
> sub inflate {
> my ($class, $serialized) = @_;
> my $hashref = Storable::thaw($serialized);
> bless $hashref, $class;
> return $hashref;
> }
>
> sub deflate {
> my ($class, $hashref) = @_;
> my $serialized = Storable::nfreeze($hashref);
> return $serialized;
> }
> }
Thanks!
That almost worked for me. I ended up base64 {en,de}coding the
scalar that Storable returned to me, someone somewhere in the chain
between my code and sqlite was treating it as a string and truncating
it at its first null.
After that small change, it works well.
g.
_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi