Subject: | Closures loose their values |
The attached script demonstrates how closures loose their captured
parameters. I would really like to have this feature for XML::Compile,
where I transform XML Schema's into trees of nested closures. Now, they
have to be rebuild each program run.
I think this is "severity Important" because the man-page does not
warn for this limitation. Fixing it probably should end-up in the wishlist.
Subject: | closure.pl |
#!/usr/bin/perl
use warnings;
use strict;
use Storable qw/freeze thaw/;
{ no warnings 'once';
$Storable::Deparse = 1;
$Storable::Eval = 1;
}
my $y = {data => 13};
{ my $x = 42;
$y->{code} = sub {$x};
}
print "Before: $y->{data} ", $y->{code}->(), "\n";
my $cold = freeze $y;
my $warm = thaw $cold;
print "Warmed: $warm->{data} ",$warm->{code}->(), "\n";