Subject: | alias local leaves hashkey set after scope |
Hello,
combining alias + local did not work as expected.
Without Data::Alias:
$ perl -MData::Dumper -MData::Alias -e '
my $foo = 1;
my $bar = {};
{
local $bar->{foo} = $foo;
print Dumper($bar);
}
print Dumper($bar);'
$VAR1 = {
'foo' => 1
};
$VAR1 = {};
With Data::Alias:
$ perl -MData::Dumper -MData::Alias -e '
my $foo = 1;
my $bar = {};
{
alias local $bar->{foo} = $foo;
print Dumper($bar);
}
print Dumper($bar);'
$VAR1 = {
'foo' => 1
};
$VAR1 = {
'foo' => undef
};
Attached is a failing test for this scenario.
Subject: | alias-local-failing-test.patch |
--- 20_alias_helem.t.orig 2018-11-18 11:36:37.057307733 +0100
+++ 20_alias_helem.t 2018-11-18 11:38:56.935701230 +0100
@@ -3,7 +3,7 @@
use strict;
use warnings qw(FATAL all);
use lib 'lib';
-use Test::More tests => 38;
+use Test::More tests => 42;
use Data::Alias;
@@ -28,6 +28,11 @@
alias { is \(local $x{0} = $x{1}), \$x{1}; is \$x{0}, \$x{1} };
is \$x{0}, \$x{2};
+ok !exists $x{3};
+
+alias { is \(local $x{3} = $x{1}), \$x{1}; is \$x{3}, \$x{1} };
+ok !exists $x{3};
+
is \alias($x{0} = undef), \undef;
ok !exists $x{0};