Nicer dumping of data structure in Log::Any
When you log data structures with Log::Any, e.g.:
% DEBUG=1 perl -MLog::Any::App='$log' -e '... $log->debugf("ccls=%s", $ccls); ...'
do you often see something like this?
[38] ccls=[{fmt => ['integer','integers'],text => ['integer','integers'],type => 'noun'},{expr => 1,fmt => 'default value %s',text => 'default value 1',type => 'clause'},{expr => 1,fmt => '%(modal_verb)s be divisi ble by %s',multi => 1,text => 'must be divisible by 2 and 3',type => 'clause'},{expr => 1,fmt => '%(modal_ verb)s be at least %s',multi => 1,text => 'must be at least 1',type => 'clause'},{expr => 1,fmt => '%(moda l_verb)s be at most %s',multi => 1,text => 'must be at most 100',type => 'clause'}]
Log::Any uses Data::Dumper with Indent setting of 0. This is compact, but hard to read. Tired of scanning hash keys with my fingers or mouse pointer, I finally spent about 5 minutes creating two patch modules to fix this annoyance. The first one is Log::Any::Adapter::Core::Patch::SetDumperIndent to let you set indent level, and the second is Log::Any::Adapter::Core::Patch::UseDataDump to use Data::Dump instead of Data::Dumper.
For convenience when typing these module aliases are provided: Log::Any::{DD,DI1,DI2,DI3}.
Now you can conveniently do this:
% DEBUG=1 perl -MLog::Any::App='$log' -MLog::Any::DD -e'... $log->debugf("ccls=%s", $ccls); ...'
and see something like:
[38] ccls=[ { fmt => ["integer", "integers"], text => ["integer", "integers"], type => "noun", }, { expr => 1, fmt => "default value %s", text => "default value 1", type => "clause", }, { expr => 1, fmt => "%(modal_verb)s be divisible by %s", multi => 1, text => "must be divisible by 2 and 3", type => "clause", }, { expr => 1, fmt => "%(modal_verb)s be at least %s", multi => 1, text => "must be at least 1", type => "clause", }, { expr => 1, fmt => "%(modal_verb)s be at most %s", multi => 1, text => "must be at most 100", type => "clause", }, ]
Small stuff, but my eyes have already thanked me for it.
I'm considering making Log::Any::App supporting or picking a nice default for this.
This is very nice.
There probably isn't any advantage over the Data::Dump format, which is already quite nice, but you could also try it with Data::Dumper::Perltidy.
Hi John, thanks for pointing out about Data::Dumper::Perltidy. I'm concerned with the startup overhead (almost 0.1s, Perl::Tidy is about 30K lines and brings in HTML::Parser et al) and runtime performance (it's about 500x slower than Data::Dumper and 50x slower than Data::Dump).
On the other hand, its output is indeed nicer sometimes. Perl::Tidy is more aggresive in doing vertical alignment and keeping right margin. Might be handy at times. I'm creating a patch for it :)
Here it is :)
http://metacpan.org/module/Log::Any::Adapter::Core::Patch::UseDataDumperPerltidy
Hi Steven
I would have patched Log::Any to use Data::Dumper::Concise.
Hi Ron,
Deparse and Useqq settings are nice. Perhaps all Data::Dumper settings should be configurable from the patch.