Subject: | Borrowed and improved name detection code. |
Hi Ovid,
I wanted to let you know that I have taken your code and used it in
Data::Dump::Streamer::DumpLex(). The function is currently undocumented,
and unattributed to you (which will change next release, please accept
my apology for that) but basically functions as your code does.
I made some improvements to the code to avoid the problem of
my @array;
my $foo = \@array;
warn Dumper( $foo, \@array );
DDS has slightly different requirements than DD, so for instance my code
doesn't need to make a name for things it can't identify, thats done
elsewhere in the DDS code, so leaving them undefined is fine. But I'm
sure you can adapt this as is required:
my $pad = peek_my(1);
my %pad_vars;
while (my ($var,$ref) = each %$pad) {
$pad_vars{ refaddr $ref } = $var;
}
my @names;
my $varcount = 1;
foreach (@_) {
my $name;
INNER:foreach ( \$_, $_ ) {
$name=$pad_vars{refaddr $_}
and last INNER;
}
push @names, $name;
}
The problem in your code is that the way you did the _address() function
you ignore the container sv when it holds a ref. You need to check to
see if you know the sv first, and only when you don't know it check to
see whether it holds a ref to something you know about.
cheers,
demerphq
ps: Heh, you can even see the $varcount variable is an artifact from
when I borrowed your code. :-)