Data::Tersify – generate terse equivalents of complex data structures
metacpan.org
metacpan.org
Supplied with a data structure, returns a data structure with the complicated bits summarised. Every attempt is made to preserve those parts of the data structure that don't need summarising.
Structures are only summarised if (1) they're blessed objects, (2) they're not the root structure passed to tersify (so if you actually to want to dump a complex DBIx::Class object, for instance, you still can), and (3) a plugin has been registered that groks that type of object.
Summaries are blessed scalars of the form "Classname (refaddr) summary", e.g. "DateTime (0xdeadbeef) 2017-08-15".
That said, I see promise with this. I use Data::Dump with a custom handler to make dumping of DateTime and specific DBIC subclass objects much more palatable based on whether the current item being recursed's ISA. e.g. 'sprintf "%s [%s]", $_[1], $_[1]->time_zone->name' for DateTime objects.
Having that abstracted away into a module with plugins would simplify that quite a bit.
1: Non-working tersification: # perl -E 'use strict; use warnings; use Data::Dumper; use Data::Tersify qw(tersify); use Data::Tersify::Plugin::DateTime; use DateTime; my $dt = DateTime->now; say "### RAW ###"; say $dt; say "\n\n### DUMPER ###"; say Dumper($dt); say "\n\n### TERSIFIED ###"; say Dumper(tersify($dt));'
So instead of…
Dumper(tersify($dt))
You would want to try… Dumper(tersify({ now => $dt }))I'm not sure the reasoning behind that behavior. Presumably if you don't want it tersified, you don't pass it to tersify, and just pass it to your dumper function directly.
That was thoughtful.