NAME

Data::XDumper - Accurate human-readable dumps of perl data structures with labeled cross-references.

SYNOPSIS

use Data::XDumper;

my $dump = new Data::XDumper usehex => 1;
print scalar $dump->dump([1, 2, 1024]);
print "$_\n" for $dump->dump({ foo => sub{}, 'bar ' => ["\n"] });
$dump->usehex = 0;
print scalar $dump->dump(bless [1, 2, 1024], 'MyClass');

my $test = ["foo"];
push @$test, \$test;
Data::XDumper::Dump $test;

use Data::XDumper qw(Dump DumpVar);

print scalar Dump [1, "x" x 50, \"hi!", \*Foo::Bar, 42];

my %x = (foo => 1, bar => 2, baz => 3);
DumpVar %x;		# requires perl 5.8 or later

Synopsis output

        [1, 2, 0x400]

        {'bar ' => ["\n"], foo => \&(synopsis.pl:5)}

        \MyClass @(1, 2, 1024)

$L001:  ['foo', \$L001]

        [
           1,
           'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
           \<ro> 'hi!',
           \*Foo::Bar
           42
        ]

        %(bar => 2, baz => 3, foo => 1)

DESCRIPTION

Produces dumps of almost any kind of perl datastructure, in a format which I personally find a lot more readable than that of Data::Dumper.

Perhaps more important is that it produces much more accurate dumps, that almost exactly mirror the internal structure of the data.

The dump returns the output lines in list context. Otherwise it produces a big string containing the whole dump, and in void context prints it too.

There are a few settings you can set on the dumper object. When you create a new dumper, it inherits the settings from the default object, which is returned by Data::XDumper::Default.

Methods

$OBJ->dumprefs(LIST)

Dump the list of references. This is the primary dumping method. Everything else eventually calls this method.

$OBJ->dump(LIST)

Dump the list of scalars.

PACKAGE->dump(LIST)

Dump the list of scalars using the default object (see Functions below).

$OBJ->reset

Reset the dumper object to its initial state. This clears the list of references it has seen, and resets the label counter.

Properties

$OBJ->usehex

Use hexadecimal notation for integers in range -0xFFFFFFFF .. -0xA and 0xA .. 0xFFFFFFFF. Default: off

$OBJ->indent

The string used to increase the indentation level. Default: 3 spaces

$OBJ->prefix

The string prefixed to every output line. Note that this string should accomodate space for the labels. Default: 8 spaces

$OBJ->linelen

The maximum desired line length. If a single-line form of a value exceeds this length, XDumper will use multi-line form instead. Default: 75

$OBJ->lformat

The format for labels. Must match /^[A-Za-z0-9]+\z/. You need to reset the object before change of label format takes effect. Default: "L001"

$OBJ->markro

Whether to explicitly mark read-only values by prefixing them with <ro>. Default: on

Functions

Dump LIST

Dump the list of scalars using the default object.

DumpVar VARIABLE

Dump the variable using the default object. Requires perl 5.8 or later.

Default

Returns the default object, to allow you to change its settings.

KNOWN ISSUES

The code is ugly and devoid of comments. The documentation is too brief. But it does seem to work though :-)

Formatting GVs, CVs and FMs still needs improvement. And I don't really know yet what to do with IO (if anything).

AUTHOR

Matthijs van Duin <xmath@cpan.org>

Copyright (C) 2003 Matthijs van Duin. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.