Re: [CDBI] Using freeze/thaw to munge a column value.

[prev] [thread] [next] [Date index for 2005/10/24]

From: Perrin Harkins
Subject: Re: [CDBI] Using freeze/thaw to munge a column value.
Date: 18:53 on 24 Oct 2005
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;
    }
}

- Perrin


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] Using freeze/thaw to munge a column value.
George Hartzell 18:45 on 24 Oct 2005

Re: [CDBI] Using freeze/thaw to munge a column value.
Perrin Harkins 18:53 on 24 Oct 2005

Re: [CDBI] Using freeze/thaw to munge a column value.
George Hartzell 18:10 on 25 Oct 2005

Generated at 14:18 on 27 Oct 2005 by mariachi v0.52