Re: transient object data

2001-12-24 Thread Robert Landrum

At 11:51 AM + 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.  



Re: transient object data

2001-12-23 Thread Jean-Michel Hiver

> By attribute do you mean an element of the data structure that is blessed
> in the object? Or do you mean some sort of new attribute you would assign
a
> new Serializable data type (ala something to suggest for Perl 6).

I think that what Brian was trying to say is that you could mark an object
attribute as being transient and Data::Dumper would ignore it.

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);

The transient attributes names could be stored in @TRANSIENT.
Maybe we could also have a more generic $TRANSIENT coderef as well.

Whenever you want to serialize an object calling freeze, then the object is
cloned and the clone gets its transient attributes removed. That we can call
_freeze on the modified copy.

With this interface it would be possible to subclass Serializable with
Serializable::FreezeThaw, Serializable::DataDenter or
Serializable::XMLDumper for instance (just override the _freeze and thaw
methods). The objects can also redefine the clone() method if they need to.

Now there's only one drawback that I can see - It needs to be written :-)
Cheers,

--
Jean-Michel Hiver.




Re: transient object data

2001-12-22 Thread Gunther Birznieks

At 03:33 PM 12/23/2001, brian moseley wrote:
>On Sat, 22 Dec 2001, brian moseley wrote:
>
>
> > doesn't it seem like there should be a way to denote
> > object data as transient so that it doesn't get
> > serialized by Storable, etc?
>
>dammit, i keep deleting peoples' replies before i am able to
>reply to them myself.
>
>gunther's suggestion was to use multiple inheritance. would
>it be possible to use an attribute instead?

By attribute do you mean an element of the data structure that is blessed 
in the object? Or do you mean some sort of new attribute you would assign a 
new Serializable data type (ala something to suggest for Perl 6).

Actually I think I was suggesting multiple inheritence as the 3rd 
mechanism. But I think it is fairly mandatory that the Transient object be 
an attribute or element of the data structure hash or array.  Because not 
only objects should be serializable with transient elements, but so should 
general data structures I suspect.

This is not so in Java so much, but definitely in Perl with it's more 
flexible ideas of what constitutes a data structure vs object then 
serialization needs to be equally flexible I suspect. Of course, this 
brings us back to the discussion of what a Perl bean would be like and how 
different it should be from Java.



__
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Open Web Technology Company
http://www.eXtropia.com/




Re: transient object data

2001-12-22 Thread brian moseley

On Sat, 22 Dec 2001, brian moseley wrote:


> doesn't it seem like there should be a way to denote
> object data as transient so that it doesn't get
> serialized by Storable, etc?

dammit, i keep deleting peoples' replies before i am able to
reply to them myself.

gunther's suggestion was to use multiple inheritance. would
it be possible to use an attribute instead?




Re: transient object data

2001-12-22 Thread Gunther Birznieks

At 10:19 PM 12/22/2001, DeWitt Clinton wrote:
>On Sat, Dec 22, 2001 at 06:11:33AM -0800, brian moseley wrote:
>
> > doesn't it seem like there should be a way to denote object
> > data as transient so that it doesn't get serialized by
> > Storable, etc?
>
>I'd love that as well.  For example, when persisting Cache::Object
>instances I manually strip out transient (in this case, it is
>re-creatable) data such as the name of the key and the size of the
>object, in order to save space in storage.
>
>Sounds like Perl 6 needs a generic notion of Serializable.

I think that is fine for Perl 6, but what do we do now?

I think implementation wise it seems that there are several ways to 
serialize objects in Perl. So the natural thing to do is come up with some 
"meta data" standard that perhaps all the various authors (Data::Dumper, 
Storable, etc) like and use efficiently.

I think an object of type Transient seems OK. Then, to make an element of a 
Perl data structure transient, you would add another element to that data 
structure of type Transient.

If the data structure is an array, then the value of the Transient object 
should be an array of index numbers related to values that are supposed to 
be Transient.

If the data structure is a hash, then the value of the Transient object 
should be an array of key names related to the values that are supposed to 
be Transient.

If the data structure is an object, you would alternatively look and see if 
@ISA Transient, if it is a transient (through multiple inheritence) then 
that object type would never get serialized.

Would this cover most general cases?

So should this be a thread on p5ee or on mod_perl? :)

Later,
Gunther





Re: transient object data

2001-12-22 Thread DeWitt Clinton

On Sat, Dec 22, 2001 at 06:11:33AM -0800, brian moseley wrote:

> doesn't it seem like there should be a way to denote object
> data as transient so that it doesn't get serialized by
> Storable, etc?

I'd love that as well.  For example, when persisting Cache::Object
instances I manually strip out transient (in this case, it is
re-creatable) data such as the name of the key and the size of the
object, in order to save space in storage.

Sounds like Perl 6 needs a generic notion of Serializable.  

-DeWitt





transient object data

2001-12-22 Thread brian moseley


doesn't it seem like there should be a way to denote object
data as transient so that it doesn't get serialized by
Storable, etc?

i've solved this problem in the past by writing a
class-specific serialization method that undefs things i
don't want serialized. but it seems like something that the
core should support, especially since there are so many
serialization mechanisms available.

thoughts?