++ed by:
Author image Daniel Șuteu
and 1 contributors


Data::Dump::Perl6 - Pretty printing of data structures as Perl6 code


 use Data::Dump::Perl6 qw(dump_perl6);

 $str = dump_perl6(@list);
 print "$str\n";


This module provide functions that takes a list of values as their argument and produces a string as its result. The string contains Perl6 code that, when interpreted by perl6, produces a deep copy of the original arguments.

The main feature of the module is that it strives to produce output that is easy to read. Example:

    @a = (1, [2, 3], {4 => 5});


    "(1, [2, 3], { 4 => 5 })"

If you dump just a little data, it is output on a single line. If you dump data that is more complex or there is a lot of it, line breaks are automatically added to keep it easy to read.

The following functions are provided (only the dd* functions are exported by default):

dump_perl6( ... )
pp_perl6( ... )

If you call the function with multiple arguments then the output will be wrapped in parenthesis "( ..., ... )". If you call the function with a single argument the output will not have the wrapping. If you call the function with a single scalar (non-reference) argument it will just return the scalar quoted if needed, but never break it into multiple lines. If you pass multiple arguments or references to arrays of hashes then the return value might contain line breaks to format it for easier reading. The returned string will never be "\n" terminated, even if contains multiple lines. This allows code like this to place the semicolon in the expected place:

   print '$obj = ', dump_perl6($obj), ";\n";

If dump_perl6() is called in void context, then the dump is printed on STDERR and then "\n" terminated. You might find this useful for quick debug printouts, but the dd*() functions might be better alternatives for this.

There is no difference between dump_perl6() and pp_perl6().

quote_perl6( $string )

Returns a quoted version of the provided string.

It differs from dump_perl6($string) in that it will quote even numbers and not try to come up with clever expressions that might shorten the output. If a non-scalar argument is provided then it's just stringified instead of traversed.

dd_perl6( ... )
ddx_perl6( ... )

These functions will call dump_perl6() on their argument and print the result to STDOUT (actually, it's the currently selected output handle, but STDOUT is the default for that).

The difference between them is only that ddx_perl6() will prefix the lines it prints with "# " and mark the first line with the file and line number where it was called. This is meant to be useful for debug printouts of state within programs.


There are a few global variables that can be set to modify the output generated by the dump functions. It's wise to localize the setting of these.


This holds the string that's used for indenting multiline data structures. It's default value is " " (two spaces). Set it to "" to suppress indentation.


A true value will dump strings with original Unicode letters, symbols, numbers and marks. By default, hexadecimal escapes are used for non-ASCII code points.


This holds the name of a class parameter, which is used in creating Perl6 blessed objects. The default value is content.


 bless([], "Foo")

is dumped as:

 Foo.bless(content => [])


Code references will be dumped as sub { ... }.

Regular expressions are currently unsupported. An exception will be thrown when any regular expression is encountered.

Filehandles are limited to STDIN, STDOUT and STDERR.

Class names cannot contain punctuation marks.


Data::Dump (from which this codebase is based)

JSON, YAML - Another alternative to exchange data with Perl6 (and other languages) is to export/import via YAML and JSON.


Data::Dump::Perl6 is a quick hack, based on Gisle Ass' wonderful Data::Dump.




The Data::Dump::Perl6 module is written by Daniel Șuteu <trizenx@gmail.com>, based on Data::Dump module by Gisle Aas <gisle@aas.no>, based on Data::Dumper by Gurusamy Sarathy <gsar@umich.edu>.

 Copyright 2015 Daniel Șuteu.
 Copyright 1998-2010 Gisle Aas.
 Copyright 1996-1998 Gurusamy Sarathy.

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