Data::Dump::Color (proof of concept)

rjbs' blog post mentioning Data::Printer prompted me to try it out just now. Coincidentally, earlier today I was investing terminal's 256-color support, Emacs color themes, mc skins, all those color-related stuffs.

After seeing Data::Printer output, I think I want colors in my dumps, but I don't want some new syntax/format; I just want to see Perl. So I quickly hacked Data::Dump::Color. Data::Dump's output is nicely formatted enough as a basis, all I need is to sprinkle some colors to it. The module is barely functional and to make it more proper I'll need Data::Dump to give access to more info.

Sample output:

Eventually I think I'll use Data::Printer. It's just that glancing from the docs, there's no easy way to generate Perl-code (Data::Dumper- or Data::Dump-style) dumps.

10 Comments

I may have misunderstood, but I was under the impression from the Data::Printer talk that if you wanted the generated Perl code that Data::Dumper gave you, then Data::Printer wasn't really for you. The idea was that Data::Dumper was really meant for being able to output your objects in such a way that you could serialize/otherwise store them. It just also happened to be a decent enough way to get a peek at an object for debugging purposes. However, it's not so great on things like DBI handles and the like (which is where I think Data::Printer shines).

For me, it is now Data::Printer for debugging, Data::Dumper for stringifying my stuff.

Still, from what I can see, (the screenshot is hard for me to see) it looks like a nice bit of sugar for people who don't want/need Printer.

The thing that I learned about Data::Printer at YAPC::NA is that you can easily customize what it prints when you give it your object. I have been working on a nice output for PDL, hopefully coming soon!

perhaps someone needs to get inside Data::Dumper and add plugin hooks?

For data serialization, Data::Dumper is horrifically slow. Unless you absolutely need its ability to dump objects (warning, that might be a security problem, too), then I would suggest something simpler, faster, and more special purpose: JSON::XS, Avro (lacks a good Perl binding), ProtocolBuffer, or Thrift. That can gain two orders of magnitude in performance. If you are have decided to use Data::Dumper for serialization nonetheless, then check out Yves Orton's Data::Undump, which parses the JSON-alike subset of Data::Dumper output at JSON::XS speeds.

Cheers,
Steffen

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays). My CPAN ID: SHARYANTO. I'm sedusedan on perlmonks. My twitter is stevenharyanto (but I don't tweet much). Follow me on github: sharyanto.