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

Data::Dumper doesn't support classes #18

Open
wolfsage opened this issue Aug 24, 2022 · 3 comments
Open

Data::Dumper doesn't support classes #18

wolfsage opened this issue Aug 24, 2022 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@wolfsage
Copy link

class Hello {}
print Dumper(Hello->new);
cannot handle ref type 16 at lib/Data/Dumper.pm line 213.
$VAR1 = bless( , 'Hello' );
@wolfsage wolfsage added the bug Something isn't working label Aug 24, 2022
@wolfsage
Copy link
Author

Should it dump fields? Would be useful but that's private data unless explicitly exposed? Hmm.

@leonerd
Copy link
Owner

leonerd commented Sep 9, 2022

Should it dump fields? I don't know. Data::Dumper is duty-bound to only print valid perl code that theoretically someone could eval() again to recreate a decent approximation to the original value that was passed in.

Example, in this case:

class HiddenField {
   field $x;  ADJUST { $x = int( rand * 256 ) }
}
my $obj = HiddenField->new;
Dumper($obj)

what valid perl code should be printed? What can you possibly eval() again to recreate that object?

This was touched on by Perl-Apollo/Corinna#63

@leonerd leonerd added help wanted Extra attention is needed and removed bug Something isn't working labels Sep 9, 2022
@leonerd
Copy link
Owner

leonerd commented Sep 9, 2022

Alternative thought: Data::Dumper being duty-bound to print valid eval()-able Perl code, means it cannot and should never support this. We should train users out of expecting to use Data::Dumper just to get some human-readable debug printing, and instead supply them with a better (core-supported) mechanism that doesn't have that restriction. Something like Data::Printer perhaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants