Data::Printer::Profile(3pm)

Data::Printer::Profile3pm

Customize your data::printer with code

Usage

    package Data::Printer::Profile::MyProfile;
    sub profile {
        return {
            show_tainted => 1,
            show_unicode => 0,
            array_max    => 30,
            # ...and so on...
        }
    }
    1;

Then put in your '.dataprinter' file:

    profile = MyProfile

or load it at compile time:

    use DDP profile => 'MyProfile';

or anytime during execution:

    p $some_data, profile => 'MyProfile';

Overview

Usually a ".dataprinter" file is enough to customize Data::Printer. But sometimes you want to use actual code to create special filters and rules, like a dynamic color scheme depending on terminal background or even the hour of the day, or a custom message that includes the hostname. Who knows!

Or maybe you just want to be able to upload your settings to CPAN and load them easily anywhere, as shown in the SYNOPSIS.

For all those cases, use a profile class!

Creating a profile class

Simply create a module named "Data::Printer::Profile::MyProfile" (replacing, of course, "MyProfile" for the name of your profile).

That class doesn't have to inherit from "Data::Printer::Profile", nor add Data::Printer as a dependency. All you have to do is implement a subroutine called profile() that returns a hash reference with all the options you want to use.

Load order

Profiles are read first and expanded into their options. So if you have a profile called MyProfile with, for example:

    show_tainted = 0
    show_lvalue  = 0

And your ".dataprinter" file contains something like:

    profile     = MyProfile
    show_lvalue = 1

The specific 'show_lvalues = 1' will override the other setting in the profile and the final outcome will be as if your setup said:

    show_tainted = 0
    show_lvalue  = 1

However, that is of course only true when the profile is loaded together with the other settings. If you set a profile later, for instance as an argument to p() or np(), then the profile will override any previous settings - though it will still be overridden by other inline arguments.

Releases

3 releases since Debian 11 (Bullseye); the text changed 2 times.

  1. 11
  2. 12
  3. 13

From libdata-printer-perl 1.002001-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.