Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show variable name as __VAR__ #74

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

hakonhagland
Copy link
Contributor

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 :-)

@hakonhagland
Copy link
Contributor Author

Added PPI support and some tests..

@jayallen
Copy link

Nice one! I've been wanting this same thing for a while now.

@hakonhagland
Copy link
Contributor Author

I am not sure why the tests failed here.. the tests passes on my machine using perl v5.20 on Ubuntu 14.10.

@garu
Copy link
Owner

garu commented Dec 29, 2015

@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!

@garu garu changed the title Initial commit show variable name as __VAR__ Dec 29, 2015
hakonhagland added a commit to hakonhagland/Data-Printer that referenced this pull request Jul 17, 2020
Pull request garu#74 'show variable name as __VAR__' had a dependency on
the PPI module which made its inclusion in the master less atractive
for the users not using the feature. By refactoring the part of the
code that depended on PPI out in a separate module, only the users
that would like to use the feature needs to install PPI.

The code remaining in master (that does not depend on PPI) now implements
a plugin hook in the write_label() sub in Data::Printer::Object. An
option in the configuration file called 'caller_plugin' is used to
register a caller plugin. If such a plugin is registered,
write_label() will load the plugin and then call the plugin to do the
generation of the label string.

The refactored part of garu#74 that depends on PPI has been included in
the module Data::Printer::Plugin::Caller::PPI (currently on Github).
Base automatically changed from master to main February 24, 2021 04:14
hakonhagland added a commit to hakonhagland/Data-Printer that referenced this pull request Mar 9, 2021
Pull request garu#74 'show variable name as __VAR__' had a dependency on
the PPI module which made its inclusion in the master less atractive
for the users not using the feature. By refactoring the part of the
code that depended on PPI out in a separate module, only the users
that would like to use the feature needs to install PPI.

The code remaining in master (that does not depend on PPI) now implements
a plugin hook in the write_label() sub in Data::Printer::Object. An
option in the configuration file called 'caller_plugin' is used to
register a caller plugin. If such a plugin is registered,
write_label() will load the plugin and then call the plugin to do the
generation of the label string.

The refactored part of garu#74 that depends on PPI has been included in
the module Data::Printer::Plugin::Caller::PPI (currently on Github).
@grr
Copy link

grr commented Dec 25, 2022

How about using PadWalker? Data::Dumper::Names and Data::Dump::Streamer both do this, though they are both really old.

@hakonhagland
Copy link
Contributor Author

hakonhagland added a commit to hakonhagland/Data-Printer that referenced this pull request Jan 2, 2023
Pull request garu#74 'show variable name as __VAR__' had a dependency on
the PPI module which made its inclusion in the master less atractive
for the users not using the feature. By refactoring the part of the
code that depended on PPI out in a separate module, only the users
that would like to use the feature needs to install PPI.

The code remaining in master (that does not depend on PPI) now implements
a plugin hook in the write_label() sub in Data::Printer::Object. An
option in the configuration file called 'caller_plugin' is used to
register a caller plugin. If such a plugin is registered,
write_label() will load the plugin and then call the plugin to do the
generation of the label string.

The refactored part of garu#74 that depends on PPI has been included in
the module Data::Printer::Plugin::Caller::PPI (currently on Github).
hakonhagland added a commit to hakonhagland/Data-Printer that referenced this pull request Jan 14, 2023
Pull request garu#74 'show variable name as __VAR__' had a dependency on
the PPI module which made its inclusion in the master less atractive
for the users not using the feature. By refactoring the part of the
code that depended on PPI out in a separate module, only the users
that would like to use the feature needs to install PPI.

The code remaining in master (that does not depend on PPI) now implements
a plugin hook in the write_label() sub in Data::Printer::Object. An
option in the configuration file called 'caller_plugin' is used to
register a caller plugin. If such a plugin is registered,
write_label() will load the plugin and then call the plugin to do the
generation of the label string.

The refactored part of garu#74 that depends on PPI has been included in
the module Data::Printer::Plugin::Caller::PPI (currently on Github).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants