The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Dump::Color - Like Data::Dump, but with color

VERSION

version 0.13

SYNOPSIS

Use it like you would Data::Dump, e.g.:

 use Data::Dump::Color; dd localtime;

DESCRIPTION

This module aims to be a drop-in replacement for Data::Dump. It adds colors to dumps. For more information, see Data::Dump. This documentation explains what's different between this module and Data::Dump.

RESULTS

By default Data::Dump::Color shows array indexes or hash pair sequence in comments for visual aid, e.g.:

 [
   "this",      # [0]
   "is",        # [1]
   "a",         # [2]
   "5-element", # [3]
   "array",     # [4]
   {
     0  => "with",  # .{0}
     1  => "an",    # .{1}
     2  => "extra", # .{2}
     3  => "hash",  # .{3}
     4  => "at",    # .{4}
     5  => "the",   # .{5}
     16 => "end",   # .{6}
   },           # [5]
 ]

[] and {} brackets will indicate whether they are indexes to an array or a hash. The dot prefixes will mark depth level.

To turn this off, set $INDEX to 0:

 [
   "this",
   "is",
   "a",
   "5-element",
   "array",
   {
     0  => "with",
     1  => "an",
     2  => "extra",
     3  => "hash",
     4  => "at",
     5  => "the",
     16 => "end",
   },
 ]

VARIABLES

$Data::Dump::* package variables from Data::Dump, like $Data::Dump::TRY_BASE64, etc are now in the Data::Dump::Color namespace, e.g. $Data::Dump::Color::TRY_BASE64, etc.

Additional variables include:

$COLOR => BOOL (default: undef)

Whether to force-enable or disable color. If unset, color output will be determined from $ENV{COLOR} or when in interactive terminal (when -t STDOUT is true).

%COLORS => HASH (default: default colors)

Define colors.

$INDEX => BOOL (default: 1)

Whether to add array/hash index visual aid.

ENVIRONMENT

  • COLOR

    If set, then will force color output on or off. By default, will only output color when in interactive terminal. This is consulted when $COLOR is not set.

SEE ALSO

Data::Dump, JSON::Color, YAML::Tiny::Color

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.