in reply to Re: Dumping opaque objects
in thread Dumping opaque objects
Sadly that doesn't appear to do what I want (though I'd love it to): the docs for $Data::Dumper::Freezer talk only about modifying the object passed in, not about a return value. And indeed, trying it (with a different name to avoid the existing Math::GMP::stringify method) shows it is called but has no effect on the Data::Dumper output:
% perl -MData::Dumper -MMath::GMP -wle ' $Data::Dumper::Freezer = "zify"; local *UNIVERSAL::zify = sub { warn "zify $_[0]"; $_[0]->isa("Math:: +GMP") ? "z$_[0]" : $_[0] }; my $x = [ Math::GMP->new(1) ]; print "x[0]=$x->[0]"; print Dumper($x); print "x[0]=$x->[0]"; ' Name "UNIVERSAL::zify" used only once: possible typo at -e line 3. x[0]=1 zify 1 at -e line 3. $VAR1 = [ bless( do{\(my $o = 40040032)}, 'Math::GMP' ) ]; x[0]=1
If I change it to assign back to $_[0] instead, Dumper outputs garbage ("\undef") and the data structure is corrupted to have the new string instead of the original object:
% perl -MData::Dumper -MMath::GMP -wle ' $Data::Dumper::Freezer = "zify"; local *UNIVERSAL::zify = sub { warn "zify $_[0]"; $_[0]->isa("Math:: +GMP") ? "z$_[0]" : $_[0] }; my $x = [ Math::GMP->new(1) ]; print "x[0]=$x->[0]"; print Dumper($x); print "x[0]=$x->[0]"; ' Name "UNIVERSAL::zify" used only once: possible typo at -e line 1. x[0]=1 zify 1 at -e line 1. $VAR1 = [ \undef ]; x[0]=z1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dumping opaque objects
by syphilis (Archbishop) on Jan 24, 2022 at 10:58 UTC | |
by hv (Prior) on Jan 24, 2022 at 16:04 UTC | |
by syphilis (Archbishop) on Jan 25, 2022 at 10:47 UTC | |
by hv (Prior) on Jan 25, 2022 at 13:58 UTC |