show variable name as __VAR__
Hi guys!
Background: It could be useful to have the original variable name included in the output from the p command.
When I debug a program I often have many p statements following each other.
In order to easily see which output belongs to which variable, it would be nice if I could type:
my $var = 3;
p $var;
with output: $var = 2. I would like to avoid repeating myself like:
say "printing \$var"; p $var;
To me, this seems to be a difficult problem, that would involve parsing Perl code and probably should be done using the PPI module for parsing. However, my first strategy for building a solution to this was to get started somehow :-) something is better than nothing.
So this pull request is indeed a very crude first attempt, and I hope it will be accepted so it could be gradually improved with time :-)
Added PPI support and some tests..
Nice one! I've been wanting this same thing for a while now.
I am not sure why the tests failed here.. the tests passes on my machine using perl v5.20 on Ubuntu 14.10.
@hakonhagland @jayallen YES! That's a very nice feature indeed. Sorry for not reviewing this before, I'll definitely look into reviewing and merging this right after the holidays.
Thanks!
How about using PadWalker? Data::Dumper::Names and Data::Dump::Streamer both do this, though they are both really old.
How about using PadWalker?
@grr Yes I have considered those also, see https://github.com/hakonhagland/Data-Printer-Plugin-Caller-PPI/blob/b8d9eb2ec5ad2c5a9d6addc5a2f7cf91365b1f4d/lib/Data/Printer/Plugin/Caller/PPI/Parser.pm#L21