tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to serialize an object in such a way that when I retrieve it later it remembers what "type" it was blessed into?

I tried to do this with DBM::Deep, but as you see, no dice. use warnings; use strict; use Data::Dumper; use DBM::Deep; use LWP::UserAgent; use Test::More qw(no_plan); my $hash = DBM::Deep->new("foo.db"); my $user_agent = LWP::UserAgent->new; isa_ok($user_agent, 'LWP::UserAgent'); #passes $hash->{my_user_agent} = $user_agent; my $user_agent2 = $hash->{my_user_agent}; isa_ok($user_agent2, 'LWP::UserAgent');#fails print Dumper($user_agent2);
Output of 2>> and then >>
Failed test ( at line 15) The object isn't a 'LWP::UserAgent' it's a 'DBM::Deep' Looks like you failed 1 tests of 2. ok 1 - The object isa LWP::UserAgent not ok 2 - The object isa LWP::UserAgent $VAR1 = bless( { 'requests_redirectable' => bless( [ 'GET', 'HEAD' ], 'DBM::Deep' ), 'max_redirect' => '7', 'proxy' => undef, 'parse_head' => '1', 'use_eval' => '1', 'timeout' => '180', 'protocols_allowed' => undef, 'agent' => 'libwww-perl/5.79', 'protocols_forbidden' => undef, 'no_proxy' => bless( [], 'DBM::Deep' ), 'from' => undef, 'max_size' => undef }, 'DBM::Deep' ); 1..2
This is sort of a followup to How's mldbm with concurrency?, where I was doing serialization with mldbm. I wound up switching to DBM::Deep on merlyn's advice, but that was before it occurred to me I might be checking for what kind of object I pulled out.


UPDATE: I think chromatic's Object Serialization Basics is a good place to learn how to do this.