in reply to Persistent Class data

Um, yeah, use Data::Dumper, or Data::DumpXML see XML-ish Data::Dumper?, which won't work always, or use Storable or even FreezeThaw.

Whichever fits the bill for you.

update: I hope this clears things up.

As you see, your little bless trick won't work quite so well. Most of the time, Data::Dumper/Storable can handle such things properly, but not always.

You'd be better off storing a simple hash, from which you create a new object, like

#persistB.obj $VAR1 = { foo => 'bar' }; my $object = do "persistB.obj"; $object = b->new($object);
When you bless something directly, you avoid all the stuff b::new does. By properly serializing your variables with one of the modules I mentioned above, you avoid this issue (there are other issues of course, but the docs for the modules above discuss them).

You'll also be wanting to reconsider the implications of

my $self = bless {}, ref($class)||$class;
See Re: perl oo for discussion about that.

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Persistent Class data
by webby (Acolyte) on Oct 13, 2002 at 09:24 UTC
    Alas, I can't quite see how this answers the question (which was about class data, not instance data). Could you be a bit clearer?

    Thanks.
Re: Re: Persistent Class data
by webby (Acolyte) on Oct 13, 2002 at 09:59 UTC
    Thankyou - The example that you used doesn't quite work in my real world situation, but serializing is it. I'll change all of my Data::Dumper calls to Data::Dumper::Toaster, and specify a method to call that re-populates class data.