in reply to Dumping opaque objects

Since further down in the thread you seem to say that other modules would be acceptable: I use Data::Dump::Filtered for these kind of things. Since in this case Math::GMP deals with integers, I think it's probably safe to not worry about escaping the stringified objects, but in theory one could use the pp function for escaping values as well.

use warnings; use strict; use Math::GMP; use Data::Dump qw/dd pp/; use Data::Dump::Filtered qw/add_dump_filter/; add_dump_filter( sub { my ($ctx, $objref) = @_; return { dump => "Math::GMP->new(\"$objref\")" } if $ctx->object_isa('Math::GMP'); return; # normal dumping } ); dd( Math::GMP->new("123"), Math::GMP->new("546745634563453111035453452346") ); __END__ ( Math::GMP->new("123"), Math::GMP->new("546745634563453111035453452346"), )

Replies are listed 'Best First'.
Re^2: Dumping opaque objects
by Fletch (Bishop) on Jan 24, 2022 at 20:24 UTC

    One's reminded of (well, I was at least) prin1 and friends in Lisp. There's a princ that's meant for displaying things in a pretty notation for hyooman consumption, whereas prin1 produces something that the read function could conceivably re-ingest and produce an equivalent value.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Dumping opaque objects
by hv (Prior) on Jan 24, 2022 at 19:02 UTC

    Thanks, and sorry I wasn't clear - I was absolutely expecting that the solution would need some other module, that's certainly acceptable. I've added a note to that effect on the OP.

    I'll have to have a play with this - I guess I skipped past it too quickly when looking at the Data::Dump docs, possibly because the only mention I saw there was the unwieldy-seeming dumpf(..., \&filter).