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.
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?
That's interesting Joel. I hope someone releases a customization for Data::Printer to output Perl(-ish) code dump, so I can produce my pretty colorized dump with Data::Printer using just one line/invocation.
@djzort: That'd be nice, although if it slowed down Data::Dumper considerably, that would be a minus point. For speedy dumps I do prefer Data::Dumper, Data::Dump is considerably slower but its dumps are prettier so I use that a lot for debugging.
@Leanan: Dumping Perl code is not always for serialization and vice versa. When investigating a complex data structure, reading it in Perl helps, especially if the code is nicely formatted and syntax-highlighted. Since I'm much more familiar with Perl than with Data::Printer (or Data::TreeDumper, as its author kindly told me of its existence via email a moment ago), though it would take a couple of minutes to learn the syntax of the latter two.
About the image size on this page, as almost always it's this site's CSS. The original image URL is: http://s1-05.twitpicproxy.com/photos/full/606365451.png?key=1036130
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
Yeah, I meant among dumpers that output Perl code.
BTW, people seem hung up on serialization when discussing Data::Dump(er)?. Why would I colorize the dumps if I am geared towards serialization? :-)
An update: Data::Dump's filtering mechanism is very inadequate here, so in 0.03 I switched implementation to using Data::Dump 1.21 and patching it, adding colors directly.