<?xml version="1.0" encoding="windows-1252"?>
<node id="476806" title="Can I serialize an object and have it remember it's type?" created="2005-07-21 09:13:59" updated="2005-08-11 08:09:33">
<type id="115">
perlquestion</type>
<author id="396583">
tphyahoo</author>
<data>
<field name="doctext">
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?
&lt;p&gt;
I tried to do this with DBM::Deep, but as you see, no dice.
&lt;code&gt;
#test.pl
use warnings;
use strict;
use Data::Dumper;
use DBM::Deep;
use LWP::UserAgent;
use Test::More qw(no_plan);

my $hash = DBM::Deep-&gt;new("foo.db");

my $user_agent = LWP::UserAgent-&gt;new;
isa_ok($user_agent, 'LWP::UserAgent'); #passes
$hash-&gt;{my_user_agent} = $user_agent;
my $user_agent2 = $hash-&gt;{my_user_agent}; 
isa_ok($user_agent2, 'LWP::UserAgent');#fails

print Dumper($user_agent2);
&lt;/code&gt;
Output of 
test.pl 2&gt;&gt;test.pl and then
test.pl &gt;&gt;test.pl
&lt;code&gt;
Failed test (read.pl 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' =&gt; bless( [
                                                     'GET',
                                                     'HEAD'
                                                   ], 'DBM::Deep' ),
                 'max_redirect' =&gt; '7',
                 'proxy' =&gt; undef,
                 'parse_head' =&gt; '1',
                 'use_eval' =&gt; '1',
                 'timeout' =&gt; '180',
                 'protocols_allowed' =&gt; undef,
                 'agent' =&gt; 'libwww-perl/5.79',
                 'protocols_forbidden' =&gt; undef,
                 'no_proxy' =&gt; bless( [], 'DBM::Deep' ),
                 'from' =&gt; undef,
                 'max_size' =&gt; undef
               }, 'DBM::Deep' );
1..2
&lt;/code&gt;
This is sort of a followup to [id://439668], 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.
&lt;p&gt;
**********
&lt;p&gt;
UPDATE: I think [chromatic]'s [Object Serialization Basics] is a good place to learn how to do this.</field>
</data>
</node>
