Subject: | Typeglob handling is quirky, also behavior varies by Perl version |
Compare the output of these slight variations (running under perl-5.8.9):
perl -MData::Dumper -MData::Visitor::Callback \
-e '$in = { foo => \*STDERR };
$out = Data::Visitor::Callback->new(
glob => sub { *{$_} },
plain_value => sub { $_ })->visit($in);
print Dumper($out)'
### Output: $VAR1 = { 'foo' => \*::STDERR }; # notice the reference that stays
perl -MData::Dumper -MData::Visitor::Callback \
-e '$in = { foo => \*STDERR };
$out = Data::Visitor::Callback->new(
glob => sub { *{$_} })->visit($in);
print Dumper($out)'
### Output: $VAR1 = { 'foo' => *::STDERR }; # notice the reference that disappears
Now the same programs running under perl-5.10.1 have this output, respectively:
### Output: $VAR1 = { 'foo' => undef } # now undefined
### Output: $VAR1 = { 'foo' => *::STDERR } # now still disappearing reference
If I change the \*STDERR in these programs to just *STDERR, any use of plain_value => sub {
$_ } causes the value to become undefined.