NAME

Loo - Pure XS data introspector and code deparser with customisable colour output

SYNOPSIS

use Loo qw(Dump cDump ncDump dDump);

# Functional - colour auto-detected
print Dump({ name => 'Perl', version => 5.40 });

# Always colour
print cDump([1, 2, 3]);

# Never colour
print ncDump(\%ENV);

# Deparse a code reference
print dDump(sub { my ($x) = @_; return $x * 2 });

# OO interface
my $loo = Loo->new([{ key => 'value' }], ['data']);
$loo->Indent(1)->Sortkeys(1)->Theme('monokai');
print $loo->Dump;

# Custom indentation: 4 spaces
my $loo = Loo->new([{ key => 'value' }]);
$loo->Indentwidth(4);
print $loo->Dump;

# Use tabs instead of spaces
my $loo = Loo->new([{ key => 'value' }]);
$loo->Usetabs(1)->Indentwidth(1);
print $loo->Dump;

# Deparse via OO
my $loo = Loo->new([\&Some::function]);
$loo->Deparse(1);
print $loo->Dump;

DESCRIPTION

Loo is a pure XS Perl data introspector and code deparser with built-in ANSI colour support. It provides a Data::Dumper-compatible interface for serialising Perl data structures, and can also deparse code references back to Perl source by walking the op tree directly in C.

Colour output is auto-detected based on $ENV{NO_COLOR}, terminal capability (-t STDOUT), and $ENV{TERM}, but can be forced on or off via the functional shortcuts or OO methods.

EXPORTS

The following functions are available for import:

Dump(@values)

Dump values with colour auto-detected.

cDump(@values)

Dump values with colour always enabled.

ncDump(@values)

Dump values with colour always disabled (plain text).

dDump(@values)

Dump values with deparse mode enabled. Code references are deparsed back to Perl source; other values are dumped normally.

METHODS

new(\@values, \@names)

my $loo = Loo->new(\@values);
my $loo = Loo->new(\@values, \@names);

Create a new Loo object. \@values is an array reference of the values to dump. \@names is an optional array reference of variable names (without sigils) to use in the output instead of the default $VAR1, $VAR2, etc.

Dump

my $output = $loo->Dump;

Produce the dump string.

Colour(\%spec)

$loo->Colour({
    string_fg  => 'green',
    key_fg     => 'magenta',
    number_bg  => 'bright_black',
});

Set colour configuration. Keys are colour element names with a _fg or _bg suffix. The recognised element names are:

string    number    key       brace     bracket   paren
arrow     comma     undef     blessed   regex     code
variable  quote     keyword   operator  comment

Valid colour values are standard ANSI names: black, red, green, yellow, blue, magenta, cyan, white, and their bright_ variants (e.g. bright_red).

Returns $self for chaining.

Theme($name)

$loo->Theme('monokai');

Apply a built-in colour theme. Available themes:

default - standard colour scheme
light - optimised for light terminal backgrounds
monokai - Monokai-inspired palette
none - disables all colour element settings

Returns $self for chaining.

Data::Dumper-compatible accessors

The following methods mirror the Data::Dumper interface. Each accepts an optional value (and returns $self for chaining) or no arguments (and returns the current value).

Indent($n)

Indentation style (0-3). Default: 2.

Indentwidth($n)

Number of characters per indentation level. Default: 2. For example, set to 4 for four-space indentation:

$loo->Indentwidth(4);
Usetabs($bool)

When true, use tab characters for indentation instead of spaces. Default: 0 (spaces).

$loo->Usetabs(1);

When combined with Indentwidth, the width controls how many tab characters are emitted per level (typically you want Indentwidth(1) with Usetabs(1) for one tab per level):

$loo->Usetabs(1)->Indentwidth(1);
Pad($string)

Prefix string added to every line of output. Default: "".

Varname($prefix)

Variable name prefix. Default: "VAR".

Terse($bool)

When true, omit the $VARn = prefix. Default: 0.

Purity($bool)

When true, emit extra statements to recreate circular references and tied values. Default: 0.

Useqq($bool)

When true, use double-quoted strings (with escape sequences) instead of single-quoted. Default: 0.

Quotekeys($bool)

When true, always quote hash keys. Default: 1.

Sortkeys($value)

When set to a true value, sort hash keys alphabetically. When set to a code reference, use that subroutine to sort keys (it receives a hash reference and should return an array reference of keys). Default: 0.

Maxdepth($n)

Maximum depth to traverse. 0 means unlimited. Default: 0.

Maxrecurse($n)

Maximum recursion depth before croaking. Default: 1000.

Pair($string)

String used between hash keys and values. Default: " => ".

Trailingcomma($bool)

When true, add a trailing comma after the last element in hashes and arrays. Default: 0.

Deepcopy($bool)

When true, perform a deep copy of the structure. Default: 0.

Freezer($method)

Name of a method to call on objects before dumping. Default: "".

Toaster($method)

Name of a method to call in the dump output to recreate objects. Default: "".

Bless($function)

Function name used for blessing in the output. Default: "bless".

Deparse($bool)

When true, deparse code references back to Perl source. Default: 0.

Sparseseen($bool)

When true, only populate the "Seen" hash for repeated references. Default: 0.

UTILITY FUNCTIONS

Loo::strip_colour($string)

my $plain = Loo::strip_colour($coloured_output);

Remove all ANSI escape sequences from a string. Useful when you want to post-process coloured output into plain text.

COLOUR AUTO-DETECTION

When using Dump() or the OO interface without explicitly setting colour, Loo auto-detects whether to enable ANSI colour output:

  • Colour is disabled if $ENV{NO_COLOR} is set (see https://no-color.org/).

  • Colour is disabled if STDOUT is not a terminal (-t STDOUT).

  • Colour is disabled if $ENV{TERM} is "dumb".

  • Otherwise colour is enabled.

Use cDump() or ncDump() to bypass auto-detection.

SEE ALSO

Data::Dumper, B::Deparse

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)