From 04be0204ef928fb968a23b10c5c3bc555389ad14 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 6 Dec 2011 22:58:31 -0800 Subject: [PATCH] Fix deparsing of undefined hint hash values Undefined values in the hint hash were being deparsed as empty strings. Whenever the hint hash changed, all undefined values, even those unmodified, were being printed. --- dist/B-Deparse/Deparse.pm | 6 ++++-- dist/B-Deparse/t/deparse.t | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm index f203a53..24d17af 100644 --- a/dist/B-Deparse/Deparse.pm +++ b/dist/B-Deparse/Deparse.pm @@ -1510,8 +1510,10 @@ sub declare_hinthash { my @decls; for my $key (keys %$to) { next if $ignored_hints{$key}; - if (!defined $from->{$key} or $from->{$key} ne $to->{$key}) { - push @decls, qq(\$^H{'$key'} = q($to->{$key});); + if (!exists $from->{$key} or $from->{$key} ne $to->{$key}) { + push @decls, qq(\$^H{'$key'} = ) + . (defined $to->{$key} ? qq(q($to->{$key})) : 'undef') + . qq(;); } } for my $key (keys %$from) { diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t index 84b9925..7b11ccf 100644 --- a/dist/B-Deparse/t/deparse.t +++ b/dist/B-Deparse/t/deparse.t @@ -793,3 +793,17 @@ print sort(foo('bar')); # substr assignment substr(my $a, 0, 0) = (foo(), bar()); $a++; +#### +# hint hash +BEGIN { $^H{'foo'} = undef; } +{ + BEGIN { $^H{'bar'} = undef; } + { + BEGIN { $^H{'baz'} = undef; } + { + print $_; + } + print $_; + } + print $_; +} -- 2.7.4