Live data from Hacker News

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

metacpan.org

1–8 of 8 posts

Re: Data::Tersify – generate terse equivalents of complex data structures

#3

The description sounds cool but nowhere on metacpan or github does the author provide an example of what this module outputs.

Here's what I could find on the page:

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

Re: Data::Tersify – generate terse equivalents of complex data structures

#4

The description sounds cool but nowhere on metacpan or github does the author provide an example of what this module outputs.

Here's what I could find on the page: 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 inst…

Even after installing the DateTime plugin for it, it's not tersifying for me. I'm not sure if it's me using it incorrectly, or if it's not working for some other reason[1].

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));'

Re: Data::Tersify – generate terse equivalents of complex data structures

#5
post #4

Earlier quoted context omitted.

Here's what I could find on the page: 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 inst…

Even after installing the DateTime plugin for it, it's not tersifying for me. I'm not sure if it's me using it incorrectly, or if it's not working for some other reason[1]. 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], $…

The Data::Tersify documentation mentions that it only summarizes if the object is “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)”.

So instead of…

  Dumper(tersify($dt))
You would want to try…

  Dumper(tersify({ now => $dt }))

Re: Data::Tersify – generate terse equivalents of complex data structures

#6
post #4

Earlier quoted context omitted.

Even after installing the DateTime plugin for it, it's not tersifying for me. I'm not sure if it's me using it incorrectly, or if it's not working for some other reason[1]. 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], $…

The Data::Tersify documentation mentions that it only summarizes if the object is “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)”. So instead of… Dumper(tersify($dt)) You would want to try… Dumper(tersify({ now => $dt }))

Ah, that explains it. I had noticed that's how they specified it in Data::Tersify::Plugin::DateTime, but had missed that note.

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.