in reply to Avoiding DBI handles with Storable
#!/usr/local/bin/perl -l -w use strict; use Storable; use Data::Dumper; package MyPack; sub new { my $class = shift; bless {attrib=>"red"}, $class; } sub STORABLE_freeze { my ($self, $cloning) = @_; return if $cloning; return $self; } # $self always seems to be an empty object # blessed into the class, so lets re-bless it. sub STORABLE_thaw { my ($self, $cloning) = @_; return if $cloning; bless $self, 'NoPackage'; $self->{mykey} = "value"; return $self; } package main; my $obj = MyPack->new; my $thing = { a=>"abc", b=>$obj }; print Dumper($thing); store $thing, 'store.tmp'; my $another_thing = retrieve('store.tmp'); print Dumper($another_thing); Output: $VAR1 = { 'a' => 'abc', 'b' => bless( { 'attrib' => 'red' }, 'MyPack' ) }; $VAR1 = { 'a' => 'abc', 'b' => bless( { 'mykey' => 'value' }, 'NoPackage' ) };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Avoiding DBI handles with Storable
by Fastolfe (Vicar) on Jan 31, 2001 at 05:05 UTC |