Fix deparsing of undefined hint hash values
authorFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 06:58:31 +0000 (22:58 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 14:15:35 +0000 (06:15 -0800)
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
dist/B-Deparse/t/deparse.t

index f203a53..24d17af 100644 (file)
@@ -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) {
index 84b9925..7b11ccf 100644 (file)
@@ -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 $_;
+}