note
demerphq
<p>
Seems to me that the problem with storable is that assignment to <c>$_[0]</c> doesn't work as it should work, or more specifically, as it would work in a normal perl subroutine.
</p>
<p>
For instance when I read this node my first though was "Hmm, you mean
</p>
<code>
sub STORABLE_thaw {
$_[0]= $singleton;
}
</code>
<p>
doesn't work?". And of course when I tried it, it didn't.
</p>
<p>
Anyway, it seems to me that making assignment to @_ possible in the STORABLE_freeze() hook would resolve your problem, and I think would be backwards compatible.
</p>
<p>
Ill just add the mandatory shameless plug: with [cpan://Data::Dump::Streamer] this is easy.
</p>
<code>
package Foo;
use Data::Dump::Streamer;
my $singleton=bless {},'Foo';
my $proxy=bless [],'Bar';
my $nope;
sub DDS_freeze {
return if $nope;
return ($proxy,"->DDS_thaw")
}
sub Bar::DDS_thaw {
$singleton;
}
my @array=($singleton,$singleton,$singleton);
my $array=Dump(\@array)->Names('array')->Out();
print "$array\n---\n";
eval $array or die $@;
$nope=1;
Dump($singleton,\@array,$array)->Names(qw(singleton *array array))->Out();
__END__
$array = [
bless( [], 'Bar' )->DDS_thaw(),
'V: $array->[0]',
'V: $array->[0]'
];
$array->[1] = $array->[0];
$array->[2] = $array->[0];
---
$singleton = bless( {}, 'Foo' );
@array = (
$singleton,
$singleton,
$singleton
);
$array = [
$singleton,
$singleton,
$singleton
];
</code>
<div class="pmsig"><div class="pmsig-108447">
---<br />
$world=~s/war/peace/g<br />
<br />
</div></div>
437784
437784