++ed by:

1 PAUSE user

Sam Kington


Data::Tersify - generate terse equivalents of complex data structures


 use Data::Dumper;
 use Data::Tersify qw(tersify);
 my $complicated_data_structure = ...;
 print Dumper(tersify($complicated_data_structure));
 # Your scrollback is not full of DateTime, DBIx::Class, Moose etc.
 # spoor which you weren't interested in.


Complex data structures are useful; necessary, even. But they're not helpful. In particular, when you're buried in the guts of some code you don't fully understand and you have a variable you want to inspect, and you say x $foo in the debugger, or print STDERR Dumper($foo) from your code, or something very similar with the dumper module of your choice, and you then get pages upon pages of unhelpful stuff because $foo contained, somewhere a reference to a DateTime, DBIx::Class, Moose or other verbose object... you didn't need that.

Data::Tersify looks at any data structure it's given, and if it finds a blessed object that it knows about, anywhere, it replaces it in the data structure by a terser equivalent, designed to (a) not use up all of your scrollback, but (b) be blatantly clear that this is not the original object that was in that data structure originally, but a terser equivalent.

Do not use Data::Tersify as part of any serialisation implementation! By design, Data::Tersify is lossy and will throw away information! That's because it supposes that that if you're using it, you want to dump information about a complex data structure, and you don't care about the fine details.


 In: $data_structure
 In: $terser_data_structure

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".


Out of the box, Data::Tersify comes with plugins for DateTime objects.