This is a series of short notes about the famous Perl objects an data structures inspector. After reading this, you should have learned a couple of useful tricks that will simplify every-day’s debugging:

Preload Data::Printer and avoid polluting your code with debug symbols

When I work, I tend to have a lot of boilerplate. I am a great user of Data::Printer for debugging. There is no way I wouldn’t use it, even on the smallest project. Usually, I have this on all my projects: use strict; use warnings; use Data::Printer; p $object; Fellow Peter coworker saw me doing that once and said I liked typing too much: only use DDP was enough. Later I learned another solution was provided in the DDP documentation.
[Read more]

Demand Data::Printer to dump politely if it doesn’t want to

If your project got objects that use the following methods names: to_string(), as_string(), stringify(), … Data::Printer might not behave as expected… It will dump the “stringified” object (as defined in your own code, possibly $self->name or something slightly more complicated). It’s possible to disable that feature on p() call: p $fancy_object, class => { stringify => 0 }; But honestly, that’s too much typing verbosity. I prefer, to have a ~/.
[Read more]

Maximize Data::Printer strings length

The Perl data structures and objects pretty printer Data::Printer would trim strings longer than 4096 characters (this is the default value). This is something that can be parameterized in the ~/.dataprinter file: # No limit! string_max = 0 This default is sensible, though, because you usually don’t want the program output to fill with too much text. It might be necessary to change this value, only in a specific place. You can pass a false value to string_max to display the whole string fields:
[Read more]