File: 09_repeated_references.t

package info (click to toggle)
libxml-dumper-perl 0.81-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 196 kB
  • ctags: 32
  • sloc: perl: 535; makefile: 48; xml: 12
file content (106 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (7)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use strict;
use warnings;

use Test;
use XML::Dumper;

BEGIN { plan tests => 1 }

sub check( $$ );

check "hash with a repeated reference", <<XML;
<perldata>
 <hashref memory_address="0x810f394">
  <item key="c">
   <hashref memory_address="0x8103854">
    <item key="a">1</item>
    <item key="b">2</item>
   </hashref>
  </item>
  <item key="d">
   <hashref memory_address="0x8103854">
   </hashref>
  </item>
 </hashref>
</perldata>
XML

# ============================================================
sub check( $$ ) {
# ============================================================
	my $test = shift;
	my $xml = shift;

	my $perl = xml2pl( $xml );
	my $roundtrip_xml = 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 );
}

__END__

Just wanted to inform you that it doesnt deal with
reused address. Is this normal behaviour ?

For example if we had:

==code

use XML::Dumper;
my $x = { a => 1, b => 2 };
my $y = { c => $x, d => $x, };

my $xml = pl2xml( $y );
my $data = xml2pl( $xml );

==code

The $data->{d} will point to empty hash instead of $x;

Here is some debugger output:

 DB<1> x $y;
0  HASH(0x840db78)
   'c' => HASH(0x81fa33c)
      'a' => 1
      'b' => 2
   'd' => HASH(0x81fa33c)
      -> REUSED_ADDRESS
  DB<2>
main::(test.pl:14):     my $data = xml2pl( $xml );
  DB<2> x $xml;
0  '<perldata>
 <hashref>
  <item key="c">
   <hashref>
    <item key="a">1</item>
    <item key="b">2</item>
   </hashref>
  </item>
  <item key="d">
   <hashref>
   </hashref>
  </item>
 </hashref>
</perldata>
'
  DB<3> n
main::(test.pl:16):     1;
  DB<3> x $data;
0  HASH(0x8453168)
   'c' => HASH(0x845a0e4)
      'a' => 1
      'b' => 2
   'd' => HASH(0x845a0fc)
        empty hash