perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Landrum <rland...@capitoladvantage.com>
Subject Re: transient object data
Date Mon, 24 Dec 2001 19:49:33 GMT
At 11:51 AM +0000 12/23/01, Jean-Michel Hiver wrote:
>Maybe the way to do it would be to have a Serializable class that could have
>the following methods:
>
>freeze($self) : SCALAR
>thaw ($class) : OBJECT
>clone($self) : OBJECT;
>_freeze($self): SCALAR
>_remove_transient_attributes($self);

Hmmm... Maybe instead of Subclassing directly, we should implement 
some sort of wrapper which would flag transient data internally.

my $serobj = Transient::Serobj->new(
	'Serializer' => 'Storable'
);
$serobj->STORE(KEY,VALUE,TRANSIENT);

my $str = $serobj->freeze;

my $deserobj = Transient::Serobj->thaw($str,{
	'Serializer' => 'Storable',
	'Callbacks' => {
		'KEY' => [CODEREF,CBARGS],
	}

});

When the thaw method is called, it reads the stored object data 
($str) and where the transient data is normally stored, the callback 
(if specified) would be called.  Otherwise the transient data 
wouldn't be defined.

For instance, If I only wanted to store the two letter US State 
abbreviation, but wanted to automatically have access to the state 
name, you could implement it something like

my $session = Transient::Serobj->thaw($str,{
	'Serializer' => 'Storable',
	'Callbacks' => {
		'STATENAME' => [
			sub {
				$GLOBAL::STATE2STATENAME{shift->{'STATE'}}
			}
		],
	}
});

print "I live in ",$session->FETCH('STATENAME'),"\n";

It's seems a bit longwinded here, but once it was subclassed (along 
with a few modified constants or variables), it would probably be 
much cleaner...


Rob

--
When I used a Mac, they laughed because I had no command prompt. When 
I used Linux, they laughed because I had no GUI.  

Mime
View raw message