CC: | fglock [...] gmail.com, joshua.gatcomb [...] gmail.com |
Subject: | ->OUTSIDE relationships from code aren't reproduced in the output, breaks roundtrip |
fglock reports that the following snippet is "incorrect." The output
also follows. In data, the function $v[2] has an ->OUTSIDE reference to
$v[1] which means it can access anything reachable from $v[1]. The
serialized function doesn't reconstruct that. $v[2] has no direct
mention of $y so it loses access to it.
This is a failed round-trip. I suggest adding a fixup step routine to
DDS to set $v[2]->OUTSIDE = $v[1]. Not sure how best to accomplish that.
An ->OUTSIDE mutator is not currently exposed by B::Generate but it
could be. DDS already has XS, perhaps it can be be implemented here.
Filing the RT for reference purposes.
#!perl
use Data::Dump::Streamer;
use strict;
use strict;
my @v;
$v[0] = do { my $x = 3; sub { $x; eval $_[0] } }; # set up closure
$v[0]( ' print "x=$x\n" ' ); # execute in this context level
print "sub=$v[0]\n";
$v[1] = $v[0]( ' do { my $y = 4; sub { $y; eval $_[0] } } ' ); # add a
pad level
$v[1]( ' print "y=$y\n" ' ); # execute in this context level
$v[2] = $v[1]( ' do { my $z = 7; sub { $z; eval $_[0] } } ' ); # add a
pad level
$v[2]( ' $y++ ' ); # execute in this context level
$v[2]( ' print "y=$y\n" ' ); # execute in this context level
$v[2]( ' print "done\n" ' ); # execute in this context level
$v[2]( ' my $k = $y + 1; print "k=", $k, "\n" ' ); # execute in this
context level
print "Dump:\n", Dump( \@v );
__END__
x=3
sub=CODE(0x812a180)
y=4
y=5
done
k=6
Dump:
my ($x,$y,$z);
$x = 3;
$y = 5;
$z = 7;
$ARRAY1 = [
sub {
use strict 'refs';
$x;
eval $_[0];
},
sub {
use strict 'refs';
$y;
eval $_[0];
},
sub {
use strict 'refs';
$z;
eval $_[0];
}
];