MKDoc:...Dumper(3pm)
π NAME π
MKDoc::XML::Dumper β it's literally Data::Dumper, but with XML. That's the whole vibe. π«β¨
(Welcome to the MKDoc:...Dumper(3pm) page, bestie β yes, from User Contributed Perl Documentation, we're hanging out in the cool corner of the manual.)
β¨ SYNOPSIS β¨
use MKDoc::XML::Dumper;
use Test::More 'no_plan';
my $stuff = [ qw /foo bar baz/, [], { hello => 'world', yo => \\'boo' } ];
my $xml = MKDoc::XML::Dumper->perl2xml ($stuff);
my $stuff2 = MKDoc::XML::Dumper->xml2perl ($xml);
is_deeply ($stuff, $stuff2); # prints 'ok'
Like. Look at that. Round-trip and everything, and the test says ok. she ate. π
πΈ SUMMARY πΈ
okay so, real talk: MKDoc::XML::Dumper gives you the same functionality as Data::Dumper, except that instead of serializing your structures into a Perl string, it serializes them into a generic XML file format. different font, same energy. β¨
And obviously, since XML cannot be evaled β like, that's just not a thing XML does β it also provides a mechanism for undumping the XML back into a Perl structure. so you're never stuck holding half a structure. π«Ά
Now for the iconic part: MKDoc::XML::Dumper supports scalar references, hash references, array references, reference references, and litterals. It also supports circular structures and back references so it avoids creating unwanted extra copies of the same object. no accidental clones, no dupes, no drama. π
That's all there is to it! periodt. π
π API π
my $xml = MKDoc::XML::Dumper->perl2xml ($perl);
Turns $perl into an XML string. For instance:
my $perl = [ qw /foo bar baz/, { adam => 'apple', bruno => 'berry', chris => 'cherry' } ];
print MKDoc::XML::Dumper->perl2xml ($perl);'
Will print something like:
<array id="135338912">
<item key="0">
<litteral>foo</litteral>
</item>
<item key="1">
<litteral>bar</litteral>
</item>
<item key="2">
<litteral>baz</litteral>
</item>
<item key="3">
<hash id="135338708">
<item key="bruno">
<litteral>berry</litteral>
</item>
<item key="adam">
<litteral>apple</litteral>
</item>
<item key="chris">
<litteral>cherry</litteral>
</item>
</hash>
</item>
</array>
See how every single object has an id? that's the moment. That's what makes backreferencing possible, so like:
my $perl = undef;
$perl = \$perl;
print MKDoc::XML::Dumper->perl2xml ($perl);'
Prints something like:
<ref id="135338888">
<backref id="135338888" />
</ref>
a self-referencing little legend referencing itself. we love a main character. π¦
For the curious, these identifiers are computed using some perl black magic:
my $id = 0 + $reference;
ngl that one line is carrying so much and it's just 0 + a reference. witchy. π§
my $perl = MKDoc::XML::Dumper->perl2xml ($xml);
Does the exact reverse operation as xml2perl().
π okay bestie yes, the page really does say perl2xml ($xml) right there, and we are keeping it character for character because that's the rule. no touchy.
π AUTHOR π
Copyright 2003 - MKDoc Holdings Ltd.
Author: Jean-Michel Hiver
This module is free software and is distributed under the same license as Perl itself. Use it at your own risk.
Use it at your own risk β fr fr, that's not a bit, that's the license line. π
π SEE ALSO π
MKDoc::XML::DecodeMKDoc::XML::Encode
and that's the whole page, pookie π this was perl v5.36.0, dated 2022-10-13, and you just read MKDoc:...Dumper(3pm) from the User Contributed Perl Documentation. go dump something in XML, you're gonna slay πΈππ«Ά
π¦ where this page comes from
- ubuntu noble: libmkdoc-xml-perl 0.75-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmkdoc-xml-perl 0.75-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmkdoc-xml-perl 0.75-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms