Name
Data::Undump::PPI - Perl extension for limited undumping of data structures (via PPI, not eval)
Synopsis
use Data::Dumper;
use Data::Undump::PPI; # exports the "Undump()" function
$Data::Dumper::Purity=1; # should always be turned on for Undump
my @input = ( {foo=>"bar"}, ["Hello","World"], "undumping!" );
my $str = Dumper(@input); # dump the data structure to a string
my @parsed = Undump($str); # parse the data structure back out
# @parsed now looks identical to @input (is a deep copy)
Description
This module allows for limited undumping and round-tripping of data structures from strings generated by Data::Dumper, with some support for Data::Dump and possibly others. It is a thin wrapper around Config::Perl, so please see Config::Perl for more details, including the limitations.
This module exports a single function, Undump
, which accepts a string and attempts to return the data as it would have been passed to Data::Dumper's Dumper
, or Data::Dump's dump
functions. This means that for example, the $VAR1
variable names generated by Dumper
will be removed and the list passed to Dumper(...)
is returned. If the string doesn't look like the output of one of the dumper modules, the output of Config::Perl's parse_or_die
will be passed through. Undump
will die
if it encounters problems.
When using Data::Dumper, make sure to always turn on its Purity
option and turn off its Terse
option, as otherwise Data::Dumper may produce code that may not evaluate back to the same data structure, sometimes even though it's valid, parseable Perl!
This module aims to support most of Data::Dumper's features - except, notably, code references. If you find a Data::Dumper data structure that this module does not yet support, please feel free to send in your data structure, as it can help extend Config::Perl's features and help fix bugs. Currently, using modules other than Data::Dumper may not work, for example, Data::Dump sometimes generates code with the ..
range operator, which is currently not supported by Config::Perl. In the future, this module's features may be extended to more fully support dumper modules like Data::Dump as well.
Although Config::Perl now supports self-referential data structures, you can also use Data::Dumper's Deepcopy
option to get rid of references within data structures, if the loss of references and copying of data is acceptable for your application.
This module is part of the Config::Perl distribution, but was named separately in an attempt to make its purpose more clear and its name a little easier to remember.
This document describes version 0.04 of the module. Although this module has a fair number of tests, it still lacks some features (see Config::Perl) and there may be bugs lurking. Contributions are welcome!
Author, Copyright, and License
Copyright (c) 2015 Hauke Daempfling (haukex@zero-g.net).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command "perldoc perlartistic
" or see http://perldoc.perl.org/perlartistic.html.