1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
use strict;
use warnings;
use Test;
use XML::Dumper;
BEGIN { plan tests => 1 }
sub check( $$ );
check "OO-style use of XML::Dumper", <<XML;
<perldata>
<arrayref memory_address="0x8296934">
<item key="0" defined="false"></item>
<item key="1"></item>
<item key="2">Foo</item>
<item key="3">
<hashref memory_address="0x829c810">
<item key="a" defined="false"></item>
<item key="b"></item>
<item key="c">Bar</item>
</hashref>
</item>
</arrayref>
</perldata>
XML
# ============================================================
sub check( $$ ) {
# ============================================================
my $test = shift;
my $xml = shift;
my $dump = new XML::Dumper;
my $perl = $dump->xml2pl( $xml );
my $roundtrip_xml = $dump->pl2xml( $perl );
if( xml_compare( $xml, $roundtrip_xml )) {
ok( 1 );
return;
}
print STDERR
"\nTest for $test failed: data doesn't match!\n\n" .
"Got:\n----\n'$xml'\n----\n".
"Came up with:\n----\n'$roundtrip_xml'\n----\n";
ok( 0 );
}
|