I still don't get what the return value of the STORABLE_freeze function does to anything (other than returning an empty list to nullify the subroutine, I can't get the return value to do anything; maybe its broken?), but I've been messing with freeze/thaw hooks and here's what I have which may help (Maybe the secret is to just thaw it the way you want?):
#!/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' )
};
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.