Reader/Testcases.pm untested

filter: Statementstmt 0.0% 0 / 1041 Branchbran 0.0% 0 / 180 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 1250 CC 3 SCAR 17.5
CC
3
Cov
0%
tresult
12.0
new
2.0
DESTROY
2.0
CRAP 5.8
1 use strict;
2 use warnings;
3  
4 package XML::Reader::Testcases;
5 $XML::Reader::Testcases::VERSION = '0.67';
6 require Exporter;
7  
8 our @ISA = qw(Exporter);
9 our %EXPORT_TAGS = ( all => [ qw(Get_TestCntr Get_TestProg) ] );
10 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
11 our @EXPORT = qw();
12  
13 our %TestProg;
14  
15 $TestProg{'0010_test_Module.t'} = [67, sub {
16 my ($XML_Reader_Any) = @_;
17  
18 Test::More::use_ok($XML_Reader_Any);
19  
20 {
21 my $line = '';
22 $line .= '<data>' for 1..10;
23 $line .= '<item name="abc" id="123">xyz</item>';
24 $line .= '</data>' for 1..10;
25  
26 {
27 my $count = 0;
28 my $rdr = $XML_Reader_Any->new(\$line, {filter => 2});
29 while ($rdr->iterate) { $count++; }
30 Test::More::is($count, 23, 'counting values {filter => 2}');
31 }
32 }
33  
34 {
35 my $line = q{<data><dummy></dummy>a <!-- b --> c</data>};
36 my $out = '';
37 my $rdr = $XML_Reader_Any->new(\$line);
38 while ($rdr->iterate) { $out .= '['.$rdr->tag.'='.$rdr->value.']'; }
39 Test::More::is($out, '[data=][dummy=][data=a c]', 'defaults are ok {strip => 1, filter => 2}');
40 }
41  
42 {
43 my $line = q{<data><dummy><!-- test --></dummy></data>};
44 my $out = '';
45 my $rdr = $XML_Reader_Any->new(\$line, {parse_ct => 1});
46 while ($rdr->iterate) { $out .= '['.$rdr->path.'='.$rdr->comment.']'; }
47 Test::More::is($out, '[/data=][/data/dummy=][/data/dummy=test][/data=]', 'comment is produced');
48 }
49  
50 {
51 my $line = q{<data> a b c </data>};
52 my $out = '';
53 my $rdr = $XML_Reader_Any->new(\$line, {strip => 1});
54 while ($rdr->iterate) { $out .= '['.$rdr->type.'='.$rdr->value.']'; }
55 Test::More::is($out, '[T=a b c]', 'field is stripped of spaces');
56 }
57  
58 {
59 my $line = q{<data> a b c </data>};
60 my $out = '';
61 my $rdr = $XML_Reader_Any->new(\$line, {strip => 0});
62 while ($rdr->iterate) { $out .= '['.$rdr->type.'='.$rdr->value.']'; }
63 Test::More::is($out, '[T= a b c ]', 'field is not stripped of spaces');
64 }
65  
66 {
67 my $line = q{
68 <data>
69 <item>abc</item>
70 <item>
71 <dummy/>
72 fgh
73 <inner name="ttt" id="fff">
74 o <!-- comment --> p <!-- comment2 --> q
75 </inner>
76 </item>
77 </data>
78 };
79  
80 {
81 my $start_seq = '';
82 my $end_seq = '';
83 my $lvl_seq = '';
84  
85 my $rdr = $XML_Reader_Any->new(\$line);
86 while ($rdr->iterate) {
87 $start_seq .= $rdr->is_start;
88 $end_seq .= $rdr->is_end;
89 $lvl_seq .= '['.$rdr->level.']';
90 }
91  
92 Test::More::is($start_seq, '11011000100', 'sequence of start-tags (with new)');
93 Test::More::is($end_seq, '01001000111', 'sequence of end-tags (with new)');
94 Test::More::is($lvl_seq, '[1][2][1][2][3][2][4][4][3][2][1]', 'sequence of level information (with new)');
95 }
96 }
97  
98 {
99 my $line = q{<a><b><c><d></d></c></b></a>};
100  
101 {
102 my $info = '';
103  
104 my $rdr = $XML_Reader_Any->new(\$line);
105 while ($rdr->iterate) {
106 $info .= '['.$rdr->path.'='.$rdr->value.']';
107 }
108 Test::More::is($info, '[/a=][/a/b=][/a/b/c=][/a/b/c/d=][/a/b/c=][/a/b=][/a=]', 'an empty, 4-level deep, nested XML (with new)');
109 }
110 }
111  
112 {
113 my $line = q{
114 <data>
115 ooo <!-- hello --> ppp
116 </data>
117 };
118  
119 {
120 my $data = '';
121 my $comment = '';
122  
123 my $rdr = $XML_Reader_Any->new(\$line, {parse_ct => 1});
124 my $i = 0;
125 while ($rdr->iterate) { $i++;
126 $comment = $rdr->comment if $i == 2;
127 $data = $rdr->value if $i == 2;
128 }
129 Test::More::is($comment, 'hello', 'comment is correctly recognised');
130 Test::More::is($data, 'ppp', 'data is broken up by comments');
131 }
132  
133 {
134 my $data = '';
135 my $comment = '';
136  
137 my $rdr = $XML_Reader_Any->new(\$line, {parse_ct => 1});
138 my $i = 0;
139 while ($rdr->iterate) { $i++;
140 $comment .= $rdr->comment if $rdr->type eq 'T';
141 $data .= $rdr->value if $rdr->type eq 'T';
142 }
143 Test::More::is($i, 2, 'only one line is produced (with new)');
144 Test::More::is($comment, 'hello', 'comment is found to be correct (with new)');
145 Test::More::is($data, 'oooppp', 'data is not empty (with new)');
146 }
147 {
148 my $data = '';
149 my $comment = '';
150  
151 my $rdr = $XML_Reader_Any->new(\$line, {parse_ct => 1});
152 my $i = 0;
153 while ($rdr->iterate) { $i++;
154 $comment .= $rdr->comment if $rdr->type eq 'T';
155 $data .= $rdr->value if $rdr->type eq 'T';
156 }
157 Test::More::is($i, 2, 'only one line is produced (with new)');
158 Test::More::is($comment, 'hello', 'comment is found to be correct (with new)');
159 Test::More::is($data, 'oooppp', 'data is not empty (with new)');
160 }
161 }
162  
163 {
164 my $line = q{
165 <data>
166 <item>abc</item>
167 <item>
168 <dummy/>
169 fgh
170 <inner name="ttt" id="fff">
171 ooo <!-- comment --> ppp
172 </inner>
173 </item>
174 <btem>
175 <record id="77" used="no">Player 1</record>
176 <record id="88" used="no">Player 2</record>
177 <user>
178 <level>
179 <agreement>
180 <line water="abc" ice="iii">jump</line>
181 <line water="def" ice="jjj">go</line>
182 <line water="ghi" ice="kkk">crawl</line>
183 </agreement>
184 </level>
185 </user>
186 <record id="99" used="no">Player 3</record>
187 </btem>
188 <item>
189 <alpha name="lll" type="qqq" age="999" />
190 <beta test="successful">
191 <gamma>
192 <delta number="undef">
193 letter
194 </delta>
195 </gamma>
196 <test>number one</test>
197 <test>number two</test>
198 <test>number three</test>
199 </beta>
200 </item>
201 </data>
202 };
203  
204 {
205 my $att_seq = '';
206  
207 my $rdr = $XML_Reader_Any->new(\$line, {filter => 3, using => ['/data/item/alpha', '/data/item/beta']});
208 my $i = 0;
209 while ($rdr->iterate) { $i++;
210 my %at = %{$rdr->att_hash};
211 $att_seq .= '['.join(' ', map {qq($_="$at{$_}")} sort keys %at).']';
212 }
213 Test::More::is($att_seq, '[age="999" name="lll" type="qqq"][test="successful"][][number="undef"][][][][][][][][]',
214 'check $rdr->att_hash {filter => 3}');
215 }
216  
217 {
218 my $point_01 = '';
219 my $point_09 = '';
220 my $point_10 = '';
221 my $point_25 = '';
222 my $point_26 = '';
223 my $point_38 = '';
224 my $point_48 = '';
225  
226 my $rdr = $XML_Reader_Any->new(\$line, {using => ['/data/item', '/data/btem/user/level/agreement']});
227 my $i = 0;
228 while ($rdr->iterate) { $i++;
229 my $point = '['.$rdr->prefix.']['.$rdr->path.']['.$rdr->is_start.']['.$rdr->is_end.']['.$rdr->level.']';
230 if ($i == 1) { $point_01 = $point; }
231 elsif ($i == 9) { $point_09 = $point; }
232 elsif ($i == 10) { $point_10 = $point; }
233 elsif ($i == 25) { $point_25 = $point; }
234 elsif ($i == 26) { $point_26 = $point; }
235 elsif ($i == 38) { $point_38 = $point; }
236 elsif ($i == 48) { $point_48 = $point; }
237 }
238 Test::More::is($point_01, '[/data/item][/][1][1][0]', 'check using at data point 01 (using)');
239 Test::More::is($point_09, '[/data/btem/user/level/agreement][/][1][0][0]', 'check using at data point 09 (using)');
240 Test::More::is($point_10, '[/data/btem/user/level/agreement][/line/@ice][0][0][2]', 'check using at data point 10 (using)');
241 Test::More::is($point_25, '[/data/item][/alpha/@type][0][0][2]', 'check using at data point 25 (using)');
242 Test::More::is($point_26, '[/data/item][/alpha][1][1][1]', 'check using at data point 26 (using)');
243 Test::More::is($point_38, '[/data/item][/beta][0][0][1]', 'check using at data point 38 (using)');
244 Test::More::is($point_48, '', 'check using at data point 48 (using)');
245 }
246  
247 {
248 my $point_01 = '';
249 my $point_07 = '';
250 my $point_08 = '';
251 my $point_09 = '';
252 my $point_15 = '';
253 my $point_18 = '';
254 my $point_19 = '';
255 my $point_30 = '';
256 my $point_41 = '';
257  
258 my $rdr = $XML_Reader_Any->new(\$line, {using => ['/data/item', '/data/btem/user/level/agreement']});
259 my $i = 0;
260 while ($rdr->iterate) { $i++;
261 my $point = '['.$rdr->prefix.']['.$rdr->path.']['.$rdr->is_start.$rdr->is_end.']['.$rdr->level.']';
262 if ($i == 1) { $point_01 = $point; }
263 elsif ($i == 7) { $point_07 = $point; }
264 elsif ($i == 8) { $point_08 = $point; }
265 elsif ($i == 9) { $point_09 = $point; }
266 elsif ($i == 15) { $point_15 = $point; }
267 elsif ($i == 18) { $point_18 = $point; }
268 elsif ($i == 19) { $point_19 = $point; }
269 elsif ($i == 30) { $point_30 = $point; }
270 elsif ($i == 41) { $point_41 = $point; }
271 }
272 Test::More::is($point_01, '[/data/item][/][11][0]', 'check using at data point 01 {filter => 2}');
273 Test::More::is($point_07, '[/data/item][/inner][11][1]', 'check using at data point 07 {filter => 2}');
274 Test::More::is($point_08, '[/data/item][/][01][0]', 'check using at data point 08 {filter => 2}');
275 Test::More::is($point_09, '[/data/btem/user/level/agreement][/][10][0]', 'check using at data point 09 {filter => 2}');
276 Test::More::is($point_15, '[/data/btem/user/level/agreement][/line/@water][00][2]', 'check using at data point 15 {filter => 2}');
277 Test::More::is($point_18, '[/data/btem/user/level/agreement][/line/@ice][00][2]', 'check using at data point 18 {filter => 2}');
278 Test::More::is($point_19, '[/data/btem/user/level/agreement][/line/@water][00][2]', 'check using at data point 19 {filter => 2}');
279 Test::More::is($point_30, '[/data/item][/beta/gamma][10][2]', 'check using at data point 30 {filter => 2}');
280 Test::More::is($point_41, '[/data/item][/][01][0]', 'check using at data point 41 {filter => 2}');
281 }
282 }
283  
284 {
285 my $line = q{<data />};
286  
287 my $output = '';
288  
289 my $rdr = $XML_Reader_Any->new(\$line);
290 my $i = 0;
291 while ($rdr->iterate) { $i++;
292 $output .= '['.$rdr->path.'-'.$rdr->value.']['.$rdr->is_start.$rdr->is_end.']['.$rdr->level.']';
293 }
294 Test::More::is($output, '[/data-][11][1]', 'the simplest XML possible');
295 }
296  
297 {
298 my $line = q{<data id="z" />};
299  
300 my $output = '';
301  
302 my $rdr = $XML_Reader_Any->new(\$line);
303 my $i = 0;
304 while ($rdr->iterate) { $i++;
305 $output .= '['.$rdr->path.'-'.$rdr->value.']['.$rdr->is_start.$rdr->is_end.']['.$rdr->level.']';
306 }
307 Test::More::is($output, '[/data/@id-z][00][2][/data-][11][1]', 'a simple XML with attribute');
308 }
309  
310 {
311 my $line = q{<apple orange="banana" />};
312  
313 my $tag = '';
314 my $attr = '';
315  
316 my $rdr = $XML_Reader_Any->new(\$line);
317 my $i = 0;
318 while ($rdr->iterate) { $i++;
319 $tag .= '['.$rdr->tag.']';
320 $attr .= '['.$rdr->attr.']';
321 }
322 Test::More::is($tag, '[@orange][apple]', 'verify tags');
323 Test::More::is($attr, '[orange][]', 'verify attributes');
324 }
325  
326 {
327 my $line = q{<data>abc<![CDATA[ x y z > < & ]]>def</data>};
328  
329 my $output = '';
330  
331 my $rdr = $XML_Reader_Any->new(\$line);
332 my $i = 0;
333 while ($rdr->iterate) { $i++;
334 $output .= '['.$rdr->value.']';
335 }
336 Test::More::is($output, '[abc x y z > < & def]', 'CDATA is processed correctly');
337 }
338  
339 {
340 my $line = q{<root><id order='desc' nb='no' screen='color'>show
341 <data name='abc' addr='def'>definition</data>text</id></root>};
342  
343 my $rdr = $XML_Reader_Any->new(\$line);
344  
345 my $output = '';
346  
347 my $i = 0;
348 while ($rdr->iterate) { $i++;
349 $output .= '['.$rdr->is_start.$rdr->is_end.']';
350 }
351 Test::More::is($output, '[10][00][00][00][10][00][00][11][01][01]',
352 'filter => 2 for is_start, is_end');
353 }
354  
355 {
356 my $line = q{
357 <data>
358 <item>abc</item>
359 <item>
360 <dummy/>
361 fgh
362 <inner name="ttt" id="fff">
363 o <!-- comment --> p
364 </inner>
365 </item>
366 <btem>
367 <record id="77" used="no">Player 1</record>
368 <record id="88" used="no">Player 2</record>
369 <user>
370 <lvl>
371 <a>
372 <line water="abc" ice="iii">jump</line>
373 <line water="def" ice="jjj">go</line>
374 <line water="ghi" ice="kkk">crawl</line>
375 </a>
376 </lvl>
377 </user>
378 <record id="99" used="no">Player 3</record>
379 </btem>
380 <item ts="vy">
381 <alpha name="lll" type="qqq" age="999" />
382 <beta test="sful">
383 <gamma>
384 <d num="undef">
385 letter
386 </d>
387 </gamma>
388 <test>one</test>
389 <test>t o</test>
390 <test>three</test>
391 </beta>
392 </item>
393 </data>
394 };
395  
396 my $point_01 = '';
397 my $point_05 = '';
398 my $point_08 = '';
399 my $point_14 = '';
400 my $point_15 = '';
401 my $point_16 = '';
402 my $point_22 = '';
403 my $point_38 = '';
404 my $point_42 = '';
405  
406 my $rdr = $XML_Reader_Any->new(\$line, {using => ['/data/item', '/data/btem/user/lvl/a']});
407  
408 my $i = 0;
409 while ($rdr->iterate) { $i++;
410 my $point = '['.$rdr->prefix.']['.$rdr->path.']['.$rdr->value.']['.$rdr->type.
411 ']['.$rdr->is_start.$rdr->is_end.']['.$rdr->tag.']['.$rdr->attr.']';
412  
413 if ($i == 1) { $point_01 = $point; }
414 elsif ($i == 5) { $point_05 = $point; }
415 elsif ($i == 8) { $point_08 = $point; }
416 elsif ($i == 14) { $point_14 = $point; }
417 elsif ($i == 15) { $point_15 = $point; }
418 elsif ($i == 16) { $point_16 = $point; }
419 elsif ($i == 22) { $point_22 = $point; }
420 elsif ($i == 38) { $point_38 = $point; }
421 elsif ($i == 42) { $point_42 = $point; }
422 }
423 Test::More::is($point_01, '[/data/item][/][abc][T][11][][]', 'check filter=>2 at data point 01');
424 Test::More::is($point_05, '[/data/item][/inner/@id][fff][@][00][@id][id]', 'check filter=>2 at data point 05');
425 Test::More::is($point_08, '[/data/item][/][][T][01][][]', 'check filter=>2 at data point 08');
426 Test::More::is($point_14, '[/data/btem/user/lvl/a][/line/@ice][jjj][@][00][@ice][ice]', 'check filter=>2 at data point 14');
427 Test::More::is($point_15, '[/data/btem/user/lvl/a][/line/@water][def][@][00][@water][water]', 'check filter=>2 at data point 15');
428 Test::More::is($point_16, '[/data/btem/user/lvl/a][/line][go][T][11][line][]', 'check filter=>2 at data point 16');
429 Test::More::is($point_22, '[/data/item][/@ts][vy][@][00][@ts][ts]', 'check filter=>2 at data point 22');
430 Test::More::is($point_38, '[/data/item][/beta/test][t o][T][11][test][]', 'check filter=>2 at data point 38');
431 Test::More::is($point_42, '[/data/item][/][][T][01][][]', 'check filter=>2 at data point 42');
432 }
433  
434 {
435 my $line = qq{<root>\n}.
436 qq{ test1 \\n \\t \\ \\\\ \\\\\\ \t \n}.
437 qq{ test2\n}.
438 qq{\t<item />\n}.
439 qq{</root>};
440 my $out = '';
441 my $rdr = $XML_Reader_Any->new(\$line, {filter => 4, strip => 0});
442 while ($rdr->iterate) { $out .= '['.$rdr->pyx.']'; }
443 Test::More::is($out, '[(root][-\\n test1 \\\\n \\\\t \\\\ \\\\\\\\ \\\\\\\\\\\\ \\t \\n test2\\n\\t][(item][)item][-\\n][)root]', 'PYX escapes work as expected');
444 }
445  
446 # stress tests
447  
448 {
449 my $len = 10000;
450  
451 my $c_tag = 'ab'.('c' x $len).'de';
452 my $c_attr = 'fg'.('h' x $len).'ij';
453 my $c_value = 'kl'.('m' x $len).'no';
454 my $c_text = 'pq'.('r' x $len).'st';
455 my $c_comment = 'uv'.('w' x $len).'xy';
456 my $c_pi1 = 'z0'.('1' x $len).'23';
457 my $c_pi2 = '45'.('6' x $len).'78';
458  
459 my $v_starttag = '?';
460 my $v_endtag = '?';
461 my $v_attr = '?';
462 my $v_value = '?';
463 my $v_text = '?';
464 my $v_comment = '?';
465 my $v_pi1 = '?';
466 my $v_pi2 = '?';
467  
468 my $line = qq{<$c_tag $c_attr='$c_value'> $c_text <?$c_pi1 $c_pi2?> <!-- $c_comment --> </$c_tag>};
469  
470 my $rdr = $XML_Reader_Any->new(\$line, {filter => 4, parse_pi => 1, parse_ct => 1});
471  
472 while ($rdr->iterate) {
473 if ($rdr->is_start) { $v_starttag = $rdr->tag; }
474 elsif ($rdr->is_end) { $v_endtag = $rdr->tag; }
475 elsif ($rdr->is_proc) { $v_pi1 = $rdr->proc_tgt;
476 $v_pi2 = $rdr->proc_data; }
477 elsif ($rdr->is_comment) { $v_comment = $rdr->comment; }
478 elsif ($rdr->is_attr) { $v_attr = $rdr->attr;
479 $v_value = $rdr->value; }
480 elsif ($rdr->is_text) { $v_text = $rdr->value; }
481 }
482  
483 Test::More::is(length($v_starttag), $len + 4, 'length of variable $v_starttag');
484 Test::More::is(length($v_endtag), $len + 4, 'length of variable $v_endtag');
485 Test::More::is(length($v_attr), $len + 4, 'length of variable $v_attr');
486 Test::More::is(length($v_value), $len + 4, 'length of variable $v_value');
487 Test::More::is(length($v_text), $len + 4, 'length of variable $v_text');
488 Test::More::is(length($v_comment), $len + 4, 'length of variable $v_comment');
489 Test::More::is(length($v_pi1), $len + 4, 'length of variable $v_pi1');
490 Test::More::is(length($v_pi2), $len + 4, 'length of variable $v_pi2');
491  
492 Test::More::is(substr($v_starttag, 0, 3).'...'.substr($v_starttag, -3), 'abc...cde', 'content of variable $v_starttag');
493 Test::More::is(substr($v_endtag, 0, 3).'...'.substr($v_endtag, -3), 'abc...cde', 'content of variable $v_endtag');
494 Test::More::is(substr($v_attr, 0, 3).'...'.substr($v_attr, -3), 'fgh...hij', 'content of variable $v_attr');
495 Test::More::is(substr($v_value, 0, 3).'...'.substr($v_value, -3), 'klm...mno', 'content of variable $v_value');
496 Test::More::is(substr($v_text, 0, 3).'...'.substr($v_text, -3), 'pqr...rst', 'content of variable $v_text');
497 Test::More::is(substr($v_comment, 0, 3).'...'.substr($v_comment, -3), 'uvw...wxy', 'content of variable $v_comment');
498 Test::More::is(substr($v_pi1, 0, 3).'...'.substr($v_pi1, -3), 'z01...123', 'content of variable $v_pi1');
499 Test::More::is(substr($v_pi2, 0, 3).'...'.substr($v_pi2, -3), '456...678', 'content of variable $v_pi2');
500 }
501 }];
502  
503 $TestProg{'0020_test_Module.t'} = [281, sub {
504 my ($XML_Reader_Any) = @_;
505  
506 Test::More::use_ok($XML_Reader_Any, qw(slurp_xml));
507  
508 {
509 my $text = q{<init>n <?test pi?> t<page node="400">m <!-- remark --> r</page></init>};
510 my @lines;
511 my $rdr = $XML_Reader_Any->new(\$text);
512 while ($rdr->iterate) {
513 push @lines, sprintf("Path: %-19s, Value: %s", $rdr->path, $rdr->value);
514 }
515  
516 Test::More::is(scalar(@lines), 4, 'Pod-Test case no 1: number of output lines');
517 Test::More::is($lines[0], 'Path: /init , Value: n t', 'Pod-Test case no 1: output line 0');
518 Test::More::is($lines[1], 'Path: /init/page/@node , Value: 400', 'Pod-Test case no 1: output line 1');
519 Test::More::is($lines[2], 'Path: /init/page , Value: m r', 'Pod-Test case no 1: output line 2');
520 Test::More::is($lines[3], 'Path: /init , Value: ', 'Pod-Test case no 1: output line 3');
521 }
522  
523 {
524 my $line1 =
525 q{<?xml version="1.0" encoding="ISO-8859-1"?>
526 <data>
527 <item>abc</item>
528 <item><!-- c1 -->
529 <dummy/>
530 fgh
531 <inner name="ttt" id="fff">
532 ooo <!-- c2 --> ppp
533 </inner>
534 </item>
535 </data>
536 };
537  
538 {
539 my $rdr = $XML_Reader_Any->new(\$line1);
540 my $i = 0;
541 my @lines;
542 while ($rdr->iterate) { $i++;
543 push @lines, sprintf("%3d. pat=%-22s, val=%-9s, s=%-1s, e=%-1s, tag=%-6s, atr=%-6s, t=%-1s, lvl=%2d, c=%s",
544 $i, $rdr->path, $rdr->value, $rdr->is_start,
545 $rdr->is_end, $rdr->tag, $rdr->attr, $rdr->type, $rdr->level, $rdr->comment);
546 }
547  
548 Test::More::is(scalar(@lines), 11, 'Pod-Test case no 2: number of output lines');
549 Test::More::is($lines[ 0], ' 1. pat=/data , val= , s=1, e=0, tag=data , atr= , t=T, lvl= 1, c=', 'Pod-Test case no 2: output line 0');
550 Test::More::is($lines[ 1], ' 2. pat=/data/item , val=abc , s=1, e=1, tag=item , atr= , t=T, lvl= 2, c=', 'Pod-Test case no 2: output line 1');
551 Test::More::is($lines[ 2], ' 3. pat=/data , val= , s=0, e=0, tag=data , atr= , t=T, lvl= 1, c=', 'Pod-Test case no 2: output line 2');
552 Test::More::is($lines[ 3], ' 4. pat=/data/item , val= , s=1, e=0, tag=item , atr= , t=T, lvl= 2, c=', 'Pod-Test case no 2: output line 3');
553 Test::More::is($lines[ 4], ' 5. pat=/data/item/dummy , val= , s=1, e=1, tag=dummy , atr= , t=T, lvl= 3, c=', 'Pod-Test case no 2: output line 4');
554 Test::More::is($lines[ 5], ' 6. pat=/data/item , val=fgh , s=0, e=0, tag=item , atr= , t=T, lvl= 2, c=', 'Pod-Test case no 2: output line 5');
555 Test::More::is($lines[ 6], ' 7. pat=/data/item/inner/@id , val=fff , s=0, e=0, tag=@id , atr=id , t=@, lvl= 4, c=', 'Pod-Test case no 2: output line 6');
556 Test::More::is($lines[ 7], ' 8. pat=/data/item/inner/@name, val=ttt , s=0, e=0, tag=@name , atr=name , t=@, lvl= 4, c=', 'Pod-Test case no 2: output line 7');
557 Test::More::is($lines[ 8], ' 9. pat=/data/item/inner , val=ooo ppp , s=1, e=1, tag=inner , atr= , t=T, lvl= 3, c=', 'Pod-Test case no 2: output line 8');
558 Test::More::is($lines[ 9], ' 10. pat=/data/item , val= , s=0, e=1, tag=item , atr= , t=T, lvl= 2, c=', 'Pod-Test case no 2: output line 9');
559 Test::More::is($lines[10], ' 11. pat=/data , val= , s=0, e=1, tag=data , atr= , t=T, lvl= 1, c=', 'Pod-Test case no 2: output line 10');
560 }
561 }
562  
563 {
564 my $line2 = q{
565 <data>
566 <order>
567 <database>
568 <customer name="aaa" />
569 <customer name="bbb" />
570 <customer name="ccc" />
571 <customer name="ddd" />
572 </database>
573 </order>
574 <dummy value="ttt">test</dummy>
575 <supplier>hhh</supplier>
576 <supplier>iii</supplier>
577 <supplier>jjj</supplier>
578 </data>
579 };
580  
581 {
582 my $rdr = $XML_Reader_Any->new(\$line2,
583 {using => ['/data/order/database/customer', '/data/supplier']});
584 my $i = 0;
585 my @lines;
586 while ($rdr->iterate) { $i++;
587 push @lines, sprintf("%3d. prf=%-29s, pat=%-7s, val=%-3s, tag=%-6s, t=%-1s, lvl=%2d",
588 $i, $rdr->prefix, $rdr->path, $rdr->value, $rdr->tag, $rdr->type, $rdr->level);
589 }
590  
591 Test::More::is(scalar(@lines), 11, 'Pod-Test case no 4: number of output lines');
592 Test::More::is($lines[ 0], ' 1. prf=/data/order/database/customer, pat=/@name , val=aaa, tag=@name , t=@, lvl= 1', 'Pod-Test case no 4: output line 0');
593 Test::More::is($lines[ 1], ' 2. prf=/data/order/database/customer, pat=/ , val= , tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 1');
594 Test::More::is($lines[ 2], ' 3. prf=/data/order/database/customer, pat=/@name , val=bbb, tag=@name , t=@, lvl= 1', 'Pod-Test case no 4: output line 2');
595 Test::More::is($lines[ 3], ' 4. prf=/data/order/database/customer, pat=/ , val= , tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 3');
596 Test::More::is($lines[ 4], ' 5. prf=/data/order/database/customer, pat=/@name , val=ccc, tag=@name , t=@, lvl= 1', 'Pod-Test case no 4: output line 4');
597 Test::More::is($lines[ 5], ' 6. prf=/data/order/database/customer, pat=/ , val= , tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 5');
598 Test::More::is($lines[ 6], ' 7. prf=/data/order/database/customer, pat=/@name , val=ddd, tag=@name , t=@, lvl= 1', 'Pod-Test case no 4: output line 6');
599 Test::More::is($lines[ 7], ' 8. prf=/data/order/database/customer, pat=/ , val= , tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 7');
600 Test::More::is($lines[ 8], ' 9. prf=/data/supplier , pat=/ , val=hhh, tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 8');
601 Test::More::is($lines[ 9], ' 10. prf=/data/supplier , pat=/ , val=iii, tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 9');
602 Test::More::is($lines[10], ' 11. prf=/data/supplier , pat=/ , val=jjj, tag= , t=T, lvl= 0', 'Pod-Test case no 4: output line 10');
603 }
604  
605 {
606 my $rdr = $XML_Reader_Any->new(\$line2);
607 my $i = 0;
608 my @lines;
609 while ($rdr->iterate) { $i++;
610 push @lines, sprintf("%3d. prf=%-1s, pat=%-37s, val=%-6s, tag=%-11s, t=%-1s, lvl=%2d",
611 $i, $rdr->prefix, $rdr->path, $rdr->value, $rdr->tag, $rdr->type, $rdr->level);
612 }
613  
614 Test::More::is(scalar(@lines), 26, 'Pod-Test case no 5: number of output lines');
615 Test::More::is($lines[ 0], ' 1. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 0');
616 Test::More::is($lines[ 1], ' 2. prf= , pat=/data/order , val= , tag=order , t=T, lvl= 2', 'Pod-Test case no 5: output line 1');
617 Test::More::is($lines[ 2], ' 3. prf= , pat=/data/order/database , val= , tag=database , t=T, lvl= 3', 'Pod-Test case no 5: output line 2');
618 Test::More::is($lines[ 3], ' 4. prf= , pat=/data/order/database/customer/@name , val=aaa , tag=@name , t=@, lvl= 5', 'Pod-Test case no 5: output line 3');
619 Test::More::is($lines[ 4], ' 5. prf= , pat=/data/order/database/customer , val= , tag=customer , t=T, lvl= 4', 'Pod-Test case no 5: output line 4');
620 Test::More::is($lines[ 5], ' 6. prf= , pat=/data/order/database , val= , tag=database , t=T, lvl= 3', 'Pod-Test case no 5: output line 5');
621 Test::More::is($lines[ 6], ' 7. prf= , pat=/data/order/database/customer/@name , val=bbb , tag=@name , t=@, lvl= 5', 'Pod-Test case no 5: output line 6');
622 Test::More::is($lines[ 7], ' 8. prf= , pat=/data/order/database/customer , val= , tag=customer , t=T, lvl= 4', 'Pod-Test case no 5: output line 7');
623 Test::More::is($lines[ 8], ' 9. prf= , pat=/data/order/database , val= , tag=database , t=T, lvl= 3', 'Pod-Test case no 5: output line 8');
624 Test::More::is($lines[ 9], ' 10. prf= , pat=/data/order/database/customer/@name , val=ccc , tag=@name , t=@, lvl= 5', 'Pod-Test case no 5: output line 9');
625 Test::More::is($lines[10], ' 11. prf= , pat=/data/order/database/customer , val= , tag=customer , t=T, lvl= 4', 'Pod-Test case no 5: output line 10');
626 Test::More::is($lines[11], ' 12. prf= , pat=/data/order/database , val= , tag=database , t=T, lvl= 3', 'Pod-Test case no 5: output line 11');
627 Test::More::is($lines[12], ' 13. prf= , pat=/data/order/database/customer/@name , val=ddd , tag=@name , t=@, lvl= 5', 'Pod-Test case no 5: output line 12');
628 Test::More::is($lines[13], ' 14. prf= , pat=/data/order/database/customer , val= , tag=customer , t=T, lvl= 4', 'Pod-Test case no 5: output line 13');
629 Test::More::is($lines[14], ' 15. prf= , pat=/data/order/database , val= , tag=database , t=T, lvl= 3', 'Pod-Test case no 5: output line 14');
630 Test::More::is($lines[15], ' 16. prf= , pat=/data/order , val= , tag=order , t=T, lvl= 2', 'Pod-Test case no 5: output line 15');
631 Test::More::is($lines[16], ' 17. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 16');
632 Test::More::is($lines[17], ' 18. prf= , pat=/data/dummy/@value , val=ttt , tag=@value , t=@, lvl= 3', 'Pod-Test case no 5: output line 17');
633 Test::More::is($lines[18], ' 19. prf= , pat=/data/dummy , val=test , tag=dummy , t=T, lvl= 2', 'Pod-Test case no 5: output line 18');
634 Test::More::is($lines[19], ' 20. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 19');
635 Test::More::is($lines[20], ' 21. prf= , pat=/data/supplier , val=hhh , tag=supplier , t=T, lvl= 2', 'Pod-Test case no 5: output line 20');
636 Test::More::is($lines[21], ' 22. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 21');
637 Test::More::is($lines[22], ' 23. prf= , pat=/data/supplier , val=iii , tag=supplier , t=T, lvl= 2', 'Pod-Test case no 5: output line 22');
638 Test::More::is($lines[23], ' 24. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 23');
639 Test::More::is($lines[24], ' 25. prf= , pat=/data/supplier , val=jjj , tag=supplier , t=T, lvl= 2', 'Pod-Test case no 5: output line 24');
640 Test::More::is($lines[25], ' 26. prf= , pat=/data , val= , tag=data , t=T, lvl= 1', 'Pod-Test case no 5: output line 25');
641 }
642 }
643  
644 {
645 my $text = q{<root><test param="v"><a><b>e<data id="z">g</data>f</b></a></test>x <!-- remark --> yz</root>};
646  
647 my $rdr = $XML_Reader_Any->new(\$text);
648 my @lines;
649 while ($rdr->iterate) {
650 push @lines, sprintf("Path: %-24s, Value: %s", $rdr->path, $rdr->value);
651 }
652  
653 Test::More::is(scalar(@lines), 11, 'Pod-Test case no 6: number of output lines');
654 Test::More::is($lines[ 0], 'Path: /root , Value: ', 'Pod-Test case no 6: output line 0');
655 Test::More::is($lines[ 1], 'Path: /root/test/@param , Value: v', 'Pod-Test case no 6: output line 1');
656 Test::More::is($lines[ 2], 'Path: /root/test , Value: ', 'Pod-Test case no 6: output line 2');
657 Test::More::is($lines[ 3], 'Path: /root/test/a , Value: ', 'Pod-Test case no 6: output line 3');
658 Test::More::is($lines[ 4], 'Path: /root/test/a/b , Value: e', 'Pod-Test case no 6: output line 4');
659 Test::More::is($lines[ 5], 'Path: /root/test/a/b/data/@id , Value: z', 'Pod-Test case no 6: output line 5');
660 Test::More::is($lines[ 6], 'Path: /root/test/a/b/data , Value: g', 'Pod-Test case no 6: output line 6');
661 Test::More::is($lines[ 7], 'Path: /root/test/a/b , Value: f', 'Pod-Test case no 6: output line 7');
662 Test::More::is($lines[ 8], 'Path: /root/test/a , Value: ', 'Pod-Test case no 6: output line 8');
663 Test::More::is($lines[ 9], 'Path: /root/test , Value: ', 'Pod-Test case no 6: output line 9');
664 Test::More::is($lines[10], 'Path: /root , Value: x yz', 'Pod-Test case no 6: output line 10');
665 }
666  
667 {
668 my $text = q{<?xml version="1.0"?><dummy>xyz <!-- remark --> stu <?ab cde?> test</dummy>};
669  
670 {
671 my $rdr = $XML_Reader_Any->new(\$text);
672 my @lines;
673 while ($rdr->iterate) {
674 if ($rdr->is_decl) { my %h = %{$rdr->dec_hash};
675 push @lines, "Found decl ".join('', map{" $_='$h{$_}'"} sort keys %h); }
676 if ($rdr->is_proc) { push @lines, "Found proc "."t=".$rdr->proc_tgt.", d=". $rdr->proc_data; }
677 if ($rdr->is_comment) { push @lines, "Found comment ".$rdr->comment; }
678 push @lines, "Text '".$rdr->value."'" unless $rdr->is_decl;
679 }
680  
681 Test::More::is(scalar(@lines), 1, 'Pod-Test case no 7: number of output lines');
682 Test::More::is($lines[ 0], "Text 'xyz stu test'", 'Pod-Test case no 7: output line 0');
683 }
684  
685 {
686 my $rdr = $XML_Reader_Any->new(\$text, {parse_ct => 1});
687 my @lines;
688 while ($rdr->iterate) {
689 if ($rdr->is_decl) { my %h = %{$rdr->dec_hash};
690 push @lines, "Found decl ".join('', map{" $_='$h{$_}'"} sort keys %h); }
691 if ($rdr->is_proc) { push @lines, "Found proc "."t=".$rdr->proc_tgt.", d=". $rdr->proc_data; }
692 if ($rdr->is_comment) { push @lines, "Found comment ".$rdr->comment; }
693 push @lines, "Text '".$rdr->value."'" unless $rdr->is_decl;
694 }
695  
696 Test::More::is(scalar(@lines), 3, 'Pod-Test case no 8: number of output lines');
697 Test::More::is($lines[ 0], "Text 'xyz'", 'Pod-Test case no 8: output line 0');
698 Test::More::is($lines[ 1], "Found comment remark", 'Pod-Test case no 8: output line 1');
699 Test::More::is($lines[ 2], "Text 'stu test'", 'Pod-Test case no 8: output line 2');
700 }
701  
702 {
703 my $rdr = $XML_Reader_Any->new(\$text, {parse_ct => 1, parse_pi => 1});
704 my @lines;
705 while ($rdr->iterate) {
706 if ($rdr->is_decl) { my %h = %{$rdr->dec_hash};
707 push @lines, "Found decl ".join('', map{" $_='$h{$_}'"} sort keys %h); }
708 if ($rdr->is_proc) { push @lines, "Found proc "."t=".$rdr->proc_tgt.", d=". $rdr->proc_data; }
709 if ($rdr->is_comment) { push @lines, "Found comment ".$rdr->comment; }
710 push @lines, "Text '".$rdr->value."'" unless $rdr->is_decl;
711 }
712  
713 Test::More::is(scalar(@lines), 6, 'Pod-Test case no 9: number of output lines');
714 Test::More::is($lines[ 0], "Found decl version='1.0'", 'Pod-Test case no 9: output line 0');
715 Test::More::is($lines[ 1], "Text 'xyz'", 'Pod-Test case no 9: output line 1');
716 Test::More::is($lines[ 2], "Found comment remark", 'Pod-Test case no 9: output line 2');
717 Test::More::is($lines[ 3], "Text 'stu'", 'Pod-Test case no 9: output line 3');
718 Test::More::is($lines[ 4], "Found proc t=ab, d=cde", 'Pod-Test case no 9: output line 4');
719 Test::More::is($lines[ 5], "Text 'test'", 'Pod-Test case no 9: output line 5');
720 }
721 }
722  
723 {
724 my $text = q{<root><test param="v"><a><b>e<data id="z">g</data>f</b></a></test>x <!-- remark --> yz</root>};
725  
726 {
727 my $rdr = $XML_Reader_Any->new(\$text, {filter => 2});
728 my @lines;
729 while ($rdr->iterate) {
730 push @lines, sprintf "Path: %-24s, Value: %s", $rdr->path, $rdr->value;
731 }
732  
733 Test::More::is(scalar(@lines), 11, 'Pod-Test case no 10: number of output lines');
734 Test::More::is($lines[ 0], 'Path: /root , Value: ', 'Pod-Test case no 10: output line 0');
735 Test::More::is($lines[ 1], 'Path: /root/test/@param , Value: v', 'Pod-Test case no 10: output line 1');
736 Test::More::is($lines[ 2], 'Path: /root/test , Value: ', 'Pod-Test case no 10: output line 2');
737 Test::More::is($lines[ 3], 'Path: /root/test/a , Value: ', 'Pod-Test case no 10: output line 3');
738 Test::More::is($lines[ 4], 'Path: /root/test/a/b , Value: e', 'Pod-Test case no 10: output line 4');
739 Test::More::is($lines[ 5], 'Path: /root/test/a/b/data/@id , Value: z', 'Pod-Test case no 10: output line 5');
740 Test::More::is($lines[ 6], 'Path: /root/test/a/b/data , Value: g', 'Pod-Test case no 10: output line 6');
741 Test::More::is($lines[ 7], 'Path: /root/test/a/b , Value: f', 'Pod-Test case no 10: output line 7');
742 Test::More::is($lines[ 8], 'Path: /root/test/a , Value: ', 'Pod-Test case no 10: output line 8');
743 Test::More::is($lines[ 9], 'Path: /root/test , Value: ', 'Pod-Test case no 10: output line 9');
744 Test::More::is($lines[10], 'Path: /root , Value: x yz', 'Pod-Test case no 10: output line 10');
745 }
746  
747 {
748 my $rdr = $XML_Reader_Any->new(\$text, {filter => 2});
749 my @lines;
750 my %at;
751 while ($rdr->iterate) {
752 my $indentation = ' ' x ($rdr->level - 1);
753  
754 if ($rdr->type eq '@') { $at{$rdr->attr} = $rdr->value; }
755  
756 if ($rdr->is_start) {
757 push @lines, $indentation.'<'.$rdr->tag.join('', map{" $_='$at{$_}'"} sort keys %at).'>';
758 }
759  
760 if ($rdr->type eq 'T' and $rdr->value ne '') {
761 push @lines, $indentation.' '.$rdr->value;
762 }
763  
764 unless ($rdr->type eq '@') { %at = (); }
765  
766 if ($rdr->is_end) {
767 push @lines, $indentation.'</'.$rdr->tag.'>';
768 }
769 }
770  
771 Test::More::is(scalar(@lines), 14, 'Pod-Test case no 11: number of output lines');
772 Test::More::is($lines[ 0], q{<root>}, 'Pod-Test case no 11: output line 0');
773 Test::More::is($lines[ 1], q{ <test param='v'>}, 'Pod-Test case no 11: output line 1');
774 Test::More::is($lines[ 2], q{ <a>}, 'Pod-Test case no 11: output line 2');
775 Test::More::is($lines[ 3], q{ <b>}, 'Pod-Test case no 11: output line 3');
776 Test::More::is($lines[ 4], q{ e}, 'Pod-Test case no 11: output line 4');
777 Test::More::is($lines[ 5], q{ <data id='z'>}, 'Pod-Test case no 11: output line 5');
778 Test::More::is($lines[ 6], q{ g}, 'Pod-Test case no 11: output line 6');
779 Test::More::is($lines[ 7], q{ </data>}, 'Pod-Test case no 11: output line 7');
780 Test::More::is($lines[ 8], q{ f}, 'Pod-Test case no 11: output line 8');
781 Test::More::is($lines[ 9], q{ </b>}, 'Pod-Test case no 11: output line 9');
782 Test::More::is($lines[10], q{ </a>}, 'Pod-Test case no 11: output line 10');
783 Test::More::is($lines[11], q{ </test>}, 'Pod-Test case no 11: output line 11');
784 Test::More::is($lines[12], q{ x yz}, 'Pod-Test case no 11: output line 12');
785 Test::More::is($lines[13], q{</root>}, 'Pod-Test case no 11: output line 13');
786 }
787  
788 {
789 my $rdr = $XML_Reader_Any->new(\$text, {filter => 3});
790 my @lines;
791 while ($rdr->iterate) {
792 my $indentation = ' ' x ($rdr->level - 1);
793  
794 if ($rdr->is_start) {
795 push @lines, $indentation.'<'.$rdr->tag.
796 join('', map{" $_='".$rdr->att_hash->{$_}."'"} sort keys %{$rdr->att_hash}).'>';
797 }
798  
799 if ($rdr->type eq 'T' and $rdr->value ne '') {
800 push @lines, $indentation.' '.$rdr->value;
801 }
802  
803 if ($rdr->is_end) {
804 push @lines, $indentation.'</'.$rdr->tag.'>';
805 }
806 }
807  
808 Test::More::is(scalar(@lines), 14, 'Pod-Test case no 12: number of output lines');
809 Test::More::is($lines[ 0], q{<root>}, 'Pod-Test case no 12: output line 0');
810 Test::More::is($lines[ 1], q{ <test param='v'>}, 'Pod-Test case no 12: output line 1');
811 Test::More::is($lines[ 2], q{ <a>}, 'Pod-Test case no 12: output line 2');
812 Test::More::is($lines[ 3], q{ <b>}, 'Pod-Test case no 12: output line 3');
813 Test::More::is($lines[ 4], q{ e}, 'Pod-Test case no 12: output line 4');
814 Test::More::is($lines[ 5], q{ <data id='z'>}, 'Pod-Test case no 12: output line 5');
815 Test::More::is($lines[ 6], q{ g}, 'Pod-Test case no 12: output line 6');
816 Test::More::is($lines[ 7], q{ </data>}, 'Pod-Test case no 12: output line 7');
817 Test::More::is($lines[ 8], q{ f}, 'Pod-Test case no 12: output line 8');
818 Test::More::is($lines[ 9], q{ </b>}, 'Pod-Test case no 12: output line 9');
819 Test::More::is($lines[10], q{ </a>}, 'Pod-Test case no 12: output line 10');
820 Test::More::is($lines[11], q{ </test>}, 'Pod-Test case no 12: output line 11');
821 Test::More::is($lines[12], q{ x yz}, 'Pod-Test case no 12: output line 12');
822 Test::More::is($lines[13], q{</root>}, 'Pod-Test case no 12: output line 13');
823 }
824 }
825  
826 {
827 my $text = q{<?xml version="1.0" encoding="ISO-8859-1"?>
828 <delta>
829 <dim alter="511">
830 <gamma />
831 <beta>
832 car <?tt dat?>
833 </beta>
834 </dim>
835 dskjfh <!-- remark --> uuu
836 </delta>};
837  
838 my $rdr = $XML_Reader_Any->new(\$text, {filter => 4, parse_pi => 1});
839 my @lines;
840 while ($rdr->iterate) {
841 push @lines, sprintf "Type = %1s, pyx = %s", $rdr->type, $rdr->pyx;
842 }
843  
844 Test::More::is(scalar(@lines), 13, 'Pod-Test case no 13: number of output lines');
845 Test::More::is($lines[ 0], "Type = D, pyx = ?xml version='1.0' encoding='ISO-8859-1'", 'Pod-Test case no 13: output line 0');
846 Test::More::is($lines[ 1], "Type = S, pyx = (delta", 'Pod-Test case no 13: output line 1');
847 Test::More::is($lines[ 2], "Type = S, pyx = (dim", 'Pod-Test case no 13: output line 2');
848 Test::More::is($lines[ 3], "Type = @, pyx = Aalter 511", 'Pod-Test case no 13: output line 3');
849 Test::More::is($lines[ 4], "Type = S, pyx = (gamma", 'Pod-Test case no 13: output line 4');
850 Test::More::is($lines[ 5], "Type = E, pyx = )gamma", 'Pod-Test case no 13: output line 5');
851 Test::More::is($lines[ 6], "Type = S, pyx = (beta", 'Pod-Test case no 13: output line 6');
852 Test::More::is($lines[ 7], "Type = T, pyx = -car", 'Pod-Test case no 13: output line 7');
853 Test::More::is($lines[ 8], "Type = ?, pyx = ?tt dat", 'Pod-Test case no 13: output line 8');
854 Test::More::is($lines[ 9], "Type = E, pyx = )beta", 'Pod-Test case no 13: output line 9');
855 Test::More::is($lines[10], "Type = E, pyx = )dim", 'Pod-Test case no 13: output line 10');
856 Test::More::is($lines[11], "Type = T, pyx = -dskjfh uuu", 'Pod-Test case no 13: output line 11');
857 Test::More::is($lines[12], "Type = E, pyx = )delta", 'Pod-Test case no 13: output line 12');
858 }
859  
860 {
861 my $text = q{
862 <delta>
863 <!-- remark -->
864 </delta>};
865  
866 my $rdr = $XML_Reader_Any->new(\$text, {filter => 4, parse_ct => 1});
867 my @lines;
868 while ($rdr->iterate) {
869 push @lines, sprintf "Type = %1s, pyx = %s", $rdr->type, $rdr->pyx;
870 }
871  
872 Test::More::is(scalar(@lines), 3, 'Pod-Test case no 14: number of output lines');
873 Test::More::is($lines[ 0], "Type = S, pyx = (delta", 'Pod-Test case no 14: output line 0');
874 Test::More::is($lines[ 1], "Type = #, pyx = #remark", 'Pod-Test case no 14: output line 1');
875 Test::More::is($lines[ 2], "Type = E, pyx = )delta", 'Pod-Test case no 14: output line 2');
876 }
877  
878 {
879 my $text = q{<?xml version="1.0"?>
880 <parent abc="def"> <?pt hmf?>
881 dskjfh <!-- remark -->
882 <child>ghi</child>
883 </parent>};
884  
885 my $rdr = $XML_Reader_Any->new(\$text, {filter => 4, parse_pi => 1, parse_ct => 1});
886 my @lines;
887 while ($rdr->iterate) {
888 my $txt = sprintf "Path %-15s v=%s ", $rdr->path, $rdr->is_value;
889  
890 if ($rdr->is_start) { push @lines, $txt."Found start tag ".$rdr->tag; }
891 elsif ($rdr->is_end) { push @lines, $txt."Found end tag ".$rdr->tag; }
892 elsif ($rdr->is_decl) { my %h = %{$rdr->dec_hash};
893 push @lines, $txt."Found decl ".join('', map{" $_='$h{$_}'"} sort keys %h); }
894 elsif ($rdr->is_proc) { push @lines, $txt."Found proc "."t=".$rdr->proc_tgt.", d=".$rdr->proc_data; }
895 elsif ($rdr->is_comment) { push @lines, $txt."Found comment ".$rdr->comment; }
896 elsif ($rdr->is_attr) { push @lines, $txt."Found attribute ".$rdr->attr."='".$rdr->value."'"; }
897 elsif ($rdr->is_text) { push @lines, $txt."Found text ".$rdr->value; }
898 }
899  
900 Test::More::is(scalar(@lines), 10, 'Pod-Test case no 15: number of output lines');
901 Test::More::is($lines[ 0], "Path / " ."v=0 Found decl version='1.0'", 'Pod-Test case no 15: output line 0');
902 Test::More::is($lines[ 1], "Path /parent " ."v=0 Found start tag parent", 'Pod-Test case no 15: output line 1');
903 Test::More::is($lines[ 2], "Path /parent/\@abc "."v=1 Found attribute abc='def'", 'Pod-Test case no 15: output line 2');
904 Test::More::is($lines[ 3], "Path /parent " ."v=0 Found proc t=pt, d=hmf", 'Pod-Test case no 15: output line 3');
905 Test::More::is($lines[ 4], "Path /parent " ."v=1 Found text dskjfh", 'Pod-Test case no 15: output line 4');
906 Test::More::is($lines[ 5], "Path /parent " ."v=0 Found comment remark", 'Pod-Test case no 15: output line 5');
907 Test::More::is($lines[ 6], "Path /parent/child " ."v=0 Found start tag child", 'Pod-Test case no 15: output line 6');
908 Test::More::is($lines[ 7], "Path /parent/child " ."v=1 Found text ghi", 'Pod-Test case no 15: output line 7');
909 Test::More::is($lines[ 8], "Path /parent/child " ."v=0 Found end tag child", 'Pod-Test case no 15: output line 8');
910 Test::More::is($lines[ 9], "Path /parent " ."v=0 Found end tag parent", 'Pod-Test case no 15: output line 9');
911 }
912  
913 {
914 my $text = q{
915 <start>
916 <param>
917 <data>
918 <item p1="a" p2="b" p3="c">start1 <inner p1="p">i1</inner> end1</item>
919 <item p1="d" p2="e" p3="f">start2 <inner p1="q">i2</inner> end2</item>
920 <item p1="g" p2="h" p3="i">start3 <inner p1="r">i3</inner> end3</item>
921 </data>
922 <dataz>
923 <item p1="j" p2="k" p3="l">start9 <inner p1="s">i9</inner> end9</item>
924 </dataz>
925 <data>
926 <item p1="m" p2="n" p3="o">start4 <inner p1="t">i4</inner> end4</item>
927 </data>
928 </param>
929 </start>};
930  
931 {
932 my $rdr = $XML_Reader_Any->new(\$text,
933 {filter => 2, using => '/start/param/data/item'});
934 my @lines;
935  
936 my ($p1, $p3);
937  
938 while ($rdr->iterate) {
939 if ($rdr->path eq '/@p1') { $p1 = $rdr->value; }
940 elsif ($rdr->path eq '/@p3') { $p3 = $rdr->value; }
941 elsif ($rdr->path eq '/' and $rdr->is_start) {
942 push @lines, sprintf("item = '%s', p1 = '%s', p3 = '%s'",
943 $rdr->value, $p1, $p3);
944 }
945 unless ($rdr->is_attr) { $p1 = undef; $p3 = undef; }
946 }
947  
948 Test::More::is(scalar(@lines), 4, 'Pod-Test case no 16: number of output lines');
949 Test::More::is($lines[ 0], "item = 'start1', p1 = 'a', p3 = 'c'", 'Pod-Test case no 16: output line 0');
950 Test::More::is($lines[ 1], "item = 'start2', p1 = 'd', p3 = 'f'", 'Pod-Test case no 16: output line 1');
951 Test::More::is($lines[ 2], "item = 'start3', p1 = 'g', p3 = 'i'", 'Pod-Test case no 16: output line 2');
952 Test::More::is($lines[ 3], "item = 'start4', p1 = 'm', p3 = 'o'", 'Pod-Test case no 16: output line 3');
953 }
954  
955 {
956 my $rdr = $XML_Reader_Any->new(\$text,
957 {filter => 3, using => '/start/param/data/item'});
958 my @lines;
959  
960 while ($rdr->iterate) {
961 if ($rdr->path eq '/' and $rdr->is_start) {
962 push @lines, sprintf("item = '%s', p1 = '%s', p3 = '%s'",
963 $rdr->value, $rdr->att_hash->{p1}, $rdr->att_hash->{p3});
964 }
965 }
966  
967 Test::More::is(scalar(@lines), 4, 'Pod-Test case no 17: number of output lines');
968 Test::More::is($lines[ 0], "item = 'start1', p1 = 'a', p3 = 'c'", 'Pod-Test case no 17: output line 0');
969 Test::More::is($lines[ 1], "item = 'start2', p1 = 'd', p3 = 'f'", 'Pod-Test case no 17: output line 1');
970 Test::More::is($lines[ 2], "item = 'start3', p1 = 'g', p3 = 'i'", 'Pod-Test case no 17: output line 2');
971 Test::More::is($lines[ 3], "item = 'start4', p1 = 'm', p3 = 'o'", 'Pod-Test case no 17: output line 3');
972 }
973  
974 {
975 my $rdr = $XML_Reader_Any->new(\$text,
976 {filter => 4, using => '/start/param/data/item'});
977 my @lines;
978  
979 my ($count, $p1, $p3);
980  
981 while ($rdr->iterate) {
982 if ($rdr->path eq '/@p1') { $p1 = $rdr->value; }
983 elsif ($rdr->path eq '/@p3') { $p3 = $rdr->value; }
984 elsif ($rdr->path eq '/') {
985 if ($rdr->is_start) { $count = 0; $p1 = undef; $p3 = undef; }
986 elsif ($rdr->is_text) {
987 $count++;
988 if ($count == 1) {
989 push @lines, sprintf("item = '%s', p1 = '%s', p3 = '%s'",
990 $rdr->value, $p1, $p3);
991 }
992 }
993 }
994 }
995  
996 Test::More::is(scalar(@lines), 4, 'Pod-Test case no 18: number of output lines');
997 Test::More::is($lines[ 0], "item = 'start1', p1 = 'a', p3 = 'c'", 'Pod-Test case no 18: output line 0');
998 Test::More::is($lines[ 1], "item = 'start2', p1 = 'd', p3 = 'f'", 'Pod-Test case no 18: output line 1');
999 Test::More::is($lines[ 2], "item = 'start3', p1 = 'g', p3 = 'i'", 'Pod-Test case no 18: output line 2');
1000 Test::More::is($lines[ 3], "item = 'start4', p1 = 'm', p3 = 'o'", 'Pod-Test case no 18: output line 3');
1001 }
1002 }
1003  
1004 {
1005 my $line2 = q{
1006 <data>
1007 aa
1008 <supplier>ggg</supplier>
1009 <supplier>hhh</supplier>
1010 <order>
1011 cc
1012 <database>
1013 <customer name="smith" id="652">
1014 <street>high street</street>
1015 <city>boston</city>
1016 </customer>
1017 <customer name="jones" id="184">
1018 <street>maple street</street>
1019 <city>new york</city>
1020 </customer>
1021 <customer name="stewart" id="520">
1022 <street>ring road</street>
1023 <city>dallas</city>
1024 </customer>
1025 </database>
1026 dd
1027 </order>
1028 <dummy value="ttt">test</dummy>
1029 <supplier>iii</supplier>
1030 <supplier>jjj</supplier>
1031 bb
1032 </data>
1033 };
1034  
1035 my $aref = slurp_xml(\$line2,
1036 { root => '/data/order/database/customer', branch => ['/@name', '/street', '/city'] },
1037 { root => '/data/supplier', branch => ['/'] },
1038 { root => '/', branch => ['/data'] },
1039 { root => '/', branch => ['/data/order'] },
1040 { root => '/', branch => ['data/order'] },
1041 );
1042  
1043 my @lines;
1044  
1045 for (@{$aref->[0]}) {
1046 push @lines, sprintf("Cust: Name = %-7s Street = %-12s City = %s", $_->[0], $_->[1], $_->[2]);
1047 }
1048  
1049 for (@{$aref->[1]}) {
1050 push @lines, sprintf("Supp: Name = %s", $_->[0]);
1051 }
1052  
1053 for (@{$aref->[2]}) {
1054 push @lines, sprintf("Root: Data = %s", $_->[0]);
1055 }
1056  
1057 for (@{$aref->[3]}) {
1058 push @lines, sprintf("Root: Ordr = %s", $_->[0]);
1059 }
1060  
1061 for (@{$aref->[4]}) {
1062 push @lines, sprintf("Root: Ord2 = %s", $_->[0]);
1063 }
1064  
1065 Test::More::is(scalar(@lines), 10, 'Pod-Test case no 19: number of output lines');
1066 Test::More::is($lines[ 0], "Cust: Name = smith Street = high street City = boston", 'Pod-Test case no 19: output line 0');
1067 Test::More::is($lines[ 1], "Cust: Name = jones Street = maple street City = new york", 'Pod-Test case no 19: output line 1');
1068 Test::More::is($lines[ 2], "Cust: Name = stewart Street = ring road City = dallas", 'Pod-Test case no 19: output line 2');
1069 Test::More::is($lines[ 3], "Supp: Name = ggg", 'Pod-Test case no 19: output line 3');
1070 Test::More::is($lines[ 4], "Supp: Name = hhh", 'Pod-Test case no 19: output line 4');
1071 Test::More::is($lines[ 5], "Supp: Name = iii", 'Pod-Test case no 19: output line 5');
1072 Test::More::is($lines[ 6], "Supp: Name = jjj", 'Pod-Test case no 19: output line 6');
1073 Test::More::is($lines[ 7], "Root: Data = aabb", 'Pod-Test case no 19: output line 7');
1074 Test::More::is($lines[ 8], "Root: Ordr = ccdd", 'Pod-Test case no 19: output line 8');
1075 Test::More::is($lines[ 9], "Root: Ord2 = ccdd", 'Pod-Test case no 19: output line 9');
1076 }
1077  
1078 {
1079 my $line2 = q{
1080 <data>
1081 aa
1082 <supplier>ggg</supplier>
1083 <supplier>hhh</supplier>
1084 <order no="A">
1085 cc
1086 <database loc='alpha'>
1087 <item>
1088 <customer name="smith" id="652">
1089 <street>high street</street>
1090 <city>boston</city>
1091 </customer>
1092 <customer name="jones" id="184">
1093 <street>maple street</street>
1094 <city>new york</city>
1095 </customer>
1096 <customer name="stewart" id="520">
1097 <street>ring road</street>
1098 <city>dallas</city>
1099 </customer>
1100 </item>
1101 <item>
1102 <customer name="smith" id="444">
1103 <street>upton way</street>
1104 <city>motown</city>
1105 </customer>
1106 <customer name="gates" id="959">
1107 <street>leave me thhis way</street>
1108 <city>cambridge</city>
1109 </customer>
1110 <customer name="stewart" id="914">
1111 <street>impossible way</street>
1112 <city>chicago</city>
1113 </customer>
1114 </item>
1115 </database>
1116 <database loc='beta'>
1117 <item>
1118 <customer name="smith" id="211">
1119 <street>place republique</street>
1120 <city>paris</city>
1121 </customer>
1122 <customer name="smith" id="123">
1123 <street>test drive</street>
1124 <city>Moscow</city>
1125 </customer>
1126 <customer name="stewart" id="999">
1127 <street>subway</street>
1128 <city>london</city>
1129 </customer>
1130 </item>
1131 </database>
1132 </order>
1133 <dummy value="ttt">test</dummy>
1134 <supplier>iii</supplier>
1135 <supplier>jjj</supplier>
1136 bb
1137 </data>
1138 };
1139  
1140 my $aref = slurp_xml(\$line2,
1141 { root => '/data/order/database[@loc="alpha"]/item', branch => [
1142 'customer[@name="smith"]/street',
1143 'customer[@name="stewart"]/street',
1144 ] },
1145 );
1146  
1147 my @lines;
1148  
1149 for (@{$aref->[0]}) {
1150 push @lines, sprintf("Test2: smith = %-15s stewart = %s", $_->[0], $_->[1]);
1151 }
1152  
1153 Test::More::is(scalar(@lines), 2, 'Pod-Test case no 19a: number of output lines');
1154 Test::More::is($lines[ 0], "Test2: smith = high street stewart = ring road", 'Pod-Test case no 19a: output line 0');
1155 Test::More::is($lines[ 1], "Test2: smith = upton way stewart = impossible way", 'Pod-Test case no 19a: output line 1');
1156 }
1157  
1158 {
1159 my $line2 = q{
1160 <data>
1161 <database loc="alpha">
1162 <item>
1163 <customer name="smith" id="652">
1164 <street>high street</street>
1165 <city>rio</city>
1166 </customer>
1167 <customer name="jones" id="184">
1168 <street>maple street</street>
1169 <city>new york</city>
1170 </customer>
1171 <customer name="gates" id="520">
1172 <street>ring road</street>
1173 <city>dallas</city>
1174 </customer>
1175 <customer name="smith" id="800">
1176 <street>which way</street>
1177 <city>ny</city>
1178 </customer>
1179 </item>
1180 </database>
1181 <database loc="beta">
1182 <item>
1183 <customer name="smith" id="001">
1184 <street>nowhere</street>
1185 <city>st malo</city>
1186 </customer>
1187 <customer name="jones" id="002">
1188 <street>all the way</street>
1189 <city>leeds</city>
1190 </customer>
1191 <customer name="gates" id="003">
1192 <street>bypass</street>
1193 <city>rome</city>
1194 </customer>
1195 </item>
1196 </database>
1197 <database loc="alpha">
1198 <item>
1199 <customer name="peter" id="444">
1200 <street>upton way</street>
1201 <city>motown</city>
1202 </customer>
1203 <customer name="gates" id="959">
1204 <street>don't leave me this way</street>
1205 <city>cambridge</city>
1206 </customer>
1207 </item>
1208 </database>
1209 <database loc="alpha">
1210 <item>
1211 <customer name="smith" id="881">
1212 <street>anyway</street>
1213 <city>big apple</city>
1214 </customer>
1215 <customer name="thatcher" id="504">
1216 <street>baker street</street>
1217 <city>oxford</city>
1218 </customer>
1219 </item>
1220 </database>
1221 </data>
1222 };
1223  
1224 my @lines;
1225  
1226 my $rdr = $XML_Reader_Any->new(\$line2, { mode => 'branches', sepchar => '|' }, {
1227 root => '/data/database[@loc="alpha"]',
1228 branch => [
1229 'item/customer[@name="smith"]/city',
1230 'item/customer[@name="gates"]/city',
1231 ]});
1232  
1233 while ($rdr->iterate) {
1234 my ($smith, $gates) = $rdr->value;
1235  
1236 $smith = defined($smith) ? "($smith)" : 'undef';
1237 $gates = defined($gates) ? "($gates)" : 'undef';
1238  
1239 push @lines, sprintf("smith = %-12s, gates = %s", $smith, $gates);
1240 }
1241  
1242 Test::More::is(scalar(@lines), 3, 'Pod-Test case no 19b: number of output lines');
1243 Test::More::is($lines[ 0], "smith = (rio|ny) , gates = (dallas)", 'Pod-Test case no 19b: output line 0');
1244 Test::More::is($lines[ 1], "smith = undef , gates = (cambridge)", 'Pod-Test case no 19b: output line 1');
1245 Test::More::is($lines[ 2], "smith = (big apple) , gates = undef", 'Pod-Test case no 19b: output line 2');
1246 }
1247  
1248 {
1249 my $line2 = q{
1250 <data>
1251 <supplier>ggg</supplier>
1252 <supplier>hhh</supplier>
1253 <order>
1254 <database>
1255 <customer name="smith" id="652">
1256 <street>high street</street>
1257 <city>boston</city>
1258 </customer>
1259 <customer name="jones" id="184">
1260 <street>maple street</street>
1261 <city>new york</city>
1262 </customer>
1263 <customer name="stewart" id="520">
1264 <street>ring road</street>
1265 <city>dallas</city>
1266 </customer>
1267 </database>
1268 </order>
1269 <dummy value="ttt">test</dummy>
1270 <supplier>iii</supplier>
1271 <supplier>jjj</supplier>
1272 </data>
1273 };
1274  
1275 my $rdr = $XML_Reader_Any->new(\$line2, {filter => 5},
1276 { root => '/data/order/database/customer', branch => ['/@name', '/street', '/city'] },
1277 { root => '/data/supplier', branch => ['/'] },
1278 );
1279  
1280 my @lines;
1281  
1282 while ($rdr->iterate) {
1283 if ($rdr->rx == 0) {
1284 for ($rdr->rvalue) {
1285 push @lines, sprintf("Cust: Name = %-7s Street = %-12s City = %s", $_->[0], $_->[1], $_->[2]);
1286 }
1287 }
1288 elsif ($rdr->rx == 1) {
1289 for ($rdr->rvalue) {
1290 push @lines, sprintf("Supp: Name = %s", $_->[0]);
1291 }
1292 }
1293 }
1294  
1295 Test::More::is(scalar(@lines), 7, 'Pod-Test case no 20: number of output lines');
1296 Test::More::is($lines[ 0], "Supp: Name = ggg", 'Pod-Test case no 20: output line 0');
1297 Test::More::is($lines[ 1], "Supp: Name = hhh", 'Pod-Test case no 20: output line 1');
1298 Test::More::is($lines[ 2], "Cust: Name = smith Street = high street City = boston", 'Pod-Test case no 20: output line 2');
1299 Test::More::is($lines[ 3], "Cust: Name = jones Street = maple street City = new york", 'Pod-Test case no 20: output line 3');
1300 Test::More::is($lines[ 4], "Cust: Name = stewart Street = ring road City = dallas", 'Pod-Test case no 20: output line 4');
1301 Test::More::is($lines[ 5], "Supp: Name = iii", 'Pod-Test case no 20: output line 5');
1302 Test::More::is($lines[ 6], "Supp: Name = jjj", 'Pod-Test case no 20: output line 6');
1303 }
1304  
1305 # Pod-Test case no 21: for XML-Reader ver 0.33 (25 Apr 2010), test for {filter => 5}:
1306 # - you can now have duplicate roots (which was not possible before)
1307 # - allow branch => '*' which will effectively collect all events and construct a sub-tree in XML format
1308 # - allow relative roots, such as 'tag1/tag2' or '//tag1/tag2'
1309 # that XML-format has the correct translations
1310 # + < into &lt;
1311 # + > into &gt;
1312 # + & into &amp;
1313 # + ' into &apos;
1314 # + " into &quot;
1315  
1316 {
1317 my $line2 = q{
1318 <data>
1319 <supplier>ggg</supplier>
1320 <customer name="o'rob" id="444">
1321 <street>pod alley</street>
1322 <city>no city</city>
1323 </customer>
1324 <zcustomer name="ggg" id="842">
1325 <street>uuu</street>
1326 <city>rrr</city>
1327 </zcustomer>
1328 <customerz name="nnn" id="88">
1329 <street>oo</street>
1330 <city>yy</city>
1331 </customerz>
1332 <section>
1333 <tcustomer name="troy">
1334 <street>on</street>
1335 <city>rr</city>
1336 </tcustomer>
1337 <tcustomer id="44">
1338 <street></street>
1339 <city> </city>
1340 </tcustomer>
1341 </section>
1342 <section9>
1343 <tcustomer>
1344 <d1>f</d1>
1345 <d2>g</d2>
1346 </tcustomer>
1347 <tcustomer z="">
1348 <d1></d1>
1349 <d2> </d2>
1350 </tcustomer>
1351 </section9>
1352 <section>
1353 <tcustomer name="" />
1354 <tcustomer name="nb" id5="33">
1355 <street>aw</street>
1356 <city>ac</city>
1357 </tcustomer>
1358 <tcustomer name="john" id5="33">
1359 <city>abc</city>
1360 </tcustomer>
1361 <tcustomer name="bob" id1="22">
1362 <street>sn</street>
1363 </tcustomer>
1364 </section>
1365 <supplier>hhh</supplier>
1366 <zzz>
1367 <customer name='"sue"' id="111">
1368 <street>baker street</street>
1369 <city>sidney</city>
1370 </customer>
1371 </zzz>
1372 <order>
1373 <database>
1374 <customer name="&lt;smith&gt;" id="652">
1375 <street>high street</street>
1376 <city>boston</city>
1377 </customer>
1378 <customer name="&amp;jones" id="184">
1379 <street>maple street</street>
1380 <city>new york</city>
1381 </customer>
1382 <customer name="stewart" id="520">
1383 <street> ring road </street>
1384 <city> "'&amp;&lt;&#65;&gt;'" </city>
1385 </customer>
1386 </database>
1387 </order>
1388 <dummy value="ttt">test</dummy>
1389 <supplier>iii</supplier>
1390 <supplier>jjj</supplier>
1391 </data>
1392 };
1393  
1394 {
1395 my $rdr = $XML_Reader_Any->new(\$line2, {filter => 5},
1396 { root => 'customer', branch => ['/@name', '/street', '/city'] },
1397 { root => '/data/supplier', branch => ['/'] },
1398 { root => '//customer', branch => '*' },
1399 { root => '//customer', branch => '**' },
1400 { root => '//customer', branch => '+' },
1401 );
1402  
1403 my @stm0;
1404 my @stm1;
1405 my @stm2;
1406  
1407 my @lin0;
1408 my @lin1;
1409 my @lin2;
1410 my @lin3;
1411 my @lin4;
1412  
1413 my @lrv0;
1414 my @lrv2;
1415  
1416 while ($rdr->iterate) {
1417 if ($rdr->rx == 0) {
1418 push @stm0, $rdr->path;
1419 for ($rdr->rvalue) {
1420 push @lin0, sprintf("Cust: Name = %-7s Street = %-12s City = %s", $_->[0], $_->[1], $_->[2]);
1421 }
1422 my @rv = $rdr->value;
1423 push @lrv0, sprintf("C-rv: Name = %-7s Street = %-12s City = %s", $rv[0], $rv[1], $rv[2]);
1424 }
1425 elsif ($rdr->rx == 1) {
1426 push @stm1, $rdr->path;
1427 for ($rdr->rvalue) {
1428 push @lin1, sprintf("Supp: Name = %s", $_->[0]);
1429 }
1430 }
1431 elsif ($rdr->rx == 2) {
1432 push @stm2, $rdr->path;
1433 for ($rdr->rvalue) {
1434 push @lin2, $_;
1435 }
1436 push @lrv2, $rdr->value;
1437 }
1438 elsif ($rdr->rx == 3) {
1439 for ($rdr->rvalue) {
1440 push @lin3, $_;
1441 }
1442 }
1443 elsif ($rdr->rx == 4) {
1444 for ($rdr->rvalue) {
1445 local $" = "', '";
1446 push @lin4, "Pyx: '@$_'";
1447 }
1448 }
1449 }
1450  
1451 Test::More::is(scalar(@stm0), 5, 'Pod-Test case no 21-a: number of stems');
1452 Test::More::is($stm0[ 0], q{/data/customer}, 'Pod-Test case no 21-a: stem 0');
1453 Test::More::is($stm0[ 1], q{/data/zzz/customer}, 'Pod-Test case no 21-a: stem 1');
1454 Test::More::is($stm0[ 2], q{/data/order/database/customer}, 'Pod-Test case no 21-a: stem 2');
1455 Test::More::is($stm0[ 3], q{/data/order/database/customer}, 'Pod-Test case no 21-a: stem 3');
1456 Test::More::is($stm0[ 4], q{/data/order/database/customer}, 'Pod-Test case no 21-a: stem 4');
1457  
1458 Test::More::is(scalar(@stm1), 4, 'Pod-Test case no 21-b: number of stems');
1459 Test::More::is($stm1[ 0], q{/data/supplier}, 'Pod-Test case no 21-b: stem 0');
1460 Test::More::is($stm1[ 1], q{/data/supplier}, 'Pod-Test case no 21-b: stem 1');
1461 Test::More::is($stm1[ 2], q{/data/supplier}, 'Pod-Test case no 21-b: stem 2');
1462 Test::More::is($stm1[ 3], q{/data/supplier}, 'Pod-Test case no 21-b: stem 3');
1463  
1464 Test::More::is(scalar(@stm2), 5, 'Pod-Test case no 21-c: number of stems');
1465 Test::More::is($stm2[ 0], q{/data/customer}, 'Pod-Test case no 21-c: stem 0');
1466 Test::More::is($stm2[ 1], q{/data/zzz/customer}, 'Pod-Test case no 21-c: stem 1');
1467 Test::More::is($stm2[ 2], q{/data/order/database/customer}, 'Pod-Test case no 21-c: stem 2');
1468 Test::More::is($stm2[ 3], q{/data/order/database/customer}, 'Pod-Test case no 21-c: stem 3');
1469 Test::More::is($stm2[ 4], q{/data/order/database/customer}, 'Pod-Test case no 21-c: stem 4');
1470  
1471 Test::More::is(scalar(@lin0), 5, 'Pod-Test case no 21-d: number of output lines');
1472 Test::More::is($lin0[ 0], q{Cust: Name = o'rob Street = pod alley City = no city}, 'Pod-Test case no 21-d: output line 0');
1473 Test::More::is($lin0[ 1], q{Cust: Name = "sue" Street = baker street City = sidney}, 'Pod-Test case no 21-d: output line 1');
1474 Test::More::is($lin0[ 2], q{Cust: Name = <smith> Street = high street City = boston}, 'Pod-Test case no 21-d: output line 2');
1475 Test::More::is($lin0[ 3], q{Cust: Name = &jones Street = maple street City = new york}, 'Pod-Test case no 21-d: output line 3');
1476 Test::More::is($lin0[ 4], q{Cust: Name = stewart Street = ring road City = "'&<A>'"}, 'Pod-Test case no 21-d: output line 4');
1477  
1478 Test::More::is(scalar(@lin1), 4, 'Pod-Test case no 21-e: number of output lines');
1479 Test::More::is($lin1[ 0], q{Supp: Name = ggg}, 'Pod-Test case no 21-e: output line 0');
1480 Test::More::is($lin1[ 1], q{Supp: Name = hhh}, 'Pod-Test case no 21-e: output line 1');
1481 Test::More::is($lin1[ 2], q{Supp: Name = iii}, 'Pod-Test case no 21-e: output line 2');
1482 Test::More::is($lin1[ 3], q{Supp: Name = jjj}, 'Pod-Test case no 21-e: output line 3');
1483  
1484 Test::More::is(scalar(@lin2), 5, 'Pod-Test case no 21-f: number of output lines');
1485  
1486 Test::More::is($lin2[ 0],
1487 q{<customer id='444' name='o&apos;rob'>}.
1488 q{<street>pod alley</street>}.
1489 q{<city>no city</city>}.
1490 q{</customer>},
1491 'Pod-Test case no 21-f: output line 0');
1492  
1493 Test::More::is($lin2[ 1],
1494 q{<customer id='111' name='"sue"'>}.
1495 q{<street>baker street</street>}.
1496 q{<city>sidney</city>}.
1497 q{</customer>},
1498 'Pod-Test case no 21-f: output line 1');
1499  
1500 Test::More::is($lin2[ 2],
1501 q{<customer id='652' name='&lt;smith&gt;'>}.
1502 q{<street>high street</street>}.
1503 q{<city>boston</city>}.
1504 q{</customer>},
1505 'Pod-Test case no 21-f: output line 2');
1506  
1507 Test::More::is($lin2[ 3],
1508 q{<customer id='184' name='&amp;jones'>}.
1509 q{<street>maple street</street>}.
1510 q{<city>new york</city>}.
1511 q{</customer>},
1512 'Pod-Test case no 21-f: output line 3');
1513  
1514 Test::More::is($lin2[ 4],
1515 q{<customer id='520' name='stewart'>}.
1516 q{<street>ring road</street>}.
1517 q{<city>"'&amp;&lt;A&gt;'"</city>}.
1518 q{</customer>},
1519 'Pod-Test case no 21-f: output line 4');
1520  
1521 Test::More::is(scalar(@lin3), 5, 'Pod-Test case no 21-g: number of output lines');
1522  
1523 Test::More::is($lin3[ 0], undef, 'Pod-Test case no 21-g: output line 0');
1524 Test::More::is($lin3[ 1], undef, 'Pod-Test case no 21-g: output line 1');
1525 Test::More::is($lin3[ 2], undef, 'Pod-Test case no 21-g: output line 2');
1526 Test::More::is($lin3[ 3], undef, 'Pod-Test case no 21-g: output line 3');
1527 Test::More::is($lin3[ 4], undef, 'Pod-Test case no 21-g: output line 4');
1528  
1529  
1530 Test::More::is(scalar(@lrv0), 5, 'Pod-Test case no 21-h: number of output lines');
1531 Test::More::is($lrv0[ 0], q{C-rv: Name = o'rob Street = pod alley City = no city}, 'Pod-Test case no 21-h: output line 0');
1532 Test::More::is($lrv0[ 1], q{C-rv: Name = "sue" Street = baker street City = sidney}, 'Pod-Test case no 21-h: output line 1');
1533 Test::More::is($lrv0[ 2], q{C-rv: Name = <smith> Street = high street City = boston}, 'Pod-Test case no 21-h: output line 2');
1534 Test::More::is($lrv0[ 3], q{C-rv: Name = &jones Street = maple street City = new york}, 'Pod-Test case no 21-h: output line 3');
1535 Test::More::is($lrv0[ 4], q{C-rv: Name = stewart Street = ring road City = "'&<A>'"}, 'Pod-Test case no 21-h: output line 4');
1536  
1537 Test::More::is(scalar(@lrv2), 5, 'Pod-Test case no 21-i: number of output lines');
1538  
1539 Test::More::is($lrv2[ 0],
1540 q{<customer id='444' name='o&apos;rob'>}.
1541 q{<street>pod alley</street>}.
1542 q{<city>no city</city>}.
1543 q{</customer>},
1544 'Pod-Test case no 21-i: output line 0');
1545  
1546 Test::More::is($lrv2[ 1],
1547 q{<customer id='111' name='"sue"'>}.
1548 q{<street>baker street</street>}.
1549 q{<city>sidney</city>}.
1550 q{</customer>},
1551 'Pod-Test case no 21-i: output line 1');
1552  
1553 Test::More::is($lrv2[ 2],
1554 q{<customer id='652' name='&lt;smith&gt;'>}.
1555 q{<street>high street</street>}.
1556 q{<city>boston</city>}.
1557 q{</customer>},
1558 'Pod-Test case no 21-i: output line 2');
1559  
1560 Test::More::is($lrv2[ 3],
1561 q{<customer id='184' name='&amp;jones'>}.
1562 q{<street>maple street</street>}.
1563 q{<city>new york</city>}.
1564 q{</customer>},
1565 'Pod-Test case no 21-i: output line 3');
1566  
1567 Test::More::is($lrv2[ 4],
1568 q{<customer id='520' name='stewart'>}.
1569 q{<street>ring road</street>}.
1570 q{<city>"'&amp;&lt;A&gt;'"</city>}.
1571 q{</customer>},
1572 'Pod-Test case no 21-i: output line 4');
1573  
1574 Test::More::is(scalar(@lin4), 5, 'Pod-Test case no 21-j: number of output lines');
1575  
1576 Test::More::is($lin4[ 0],
1577 q{Pyx: }.
1578 q{'(customer', }.
1579 q{'Aid 444', }.
1580 q{'Aname o'rob', }.
1581 q{'(street', }.
1582 q{'-pod alley', }.
1583 q{')street', }.
1584 q{'(city', }.
1585 q{'-no city', }.
1586 q{')city', }.
1587 q{')customer'},
1588 'Pod-Test case no 21-j: output line 0');
1589  
1590 Test::More::is($lin4[ 1],
1591 q{Pyx: }.
1592 q{'(customer', }.
1593 q{'Aid 111', }.
1594 q{'Aname "sue"', }.
1595 q{'(street', }.
1596 q{'-baker street', }.
1597 q{')street', }.
1598 q{'(city', }.
1599 q{'-sidney', }.
1600 q{')city', }.
1601 q{')customer'},
1602 'Pod-Test case no 21-j: output line 1');
1603  
1604 Test::More::is($lin4[ 2],
1605 q{Pyx: }.
1606 q{'(customer', }.
1607 q{'Aid 652', }.
1608 q{'Aname <smith>', }.
1609 q{'(street', }.
1610 q{'-high street', }.
1611 q{')street', }.
1612 q{'(city', }.
1613 q{'-boston', }.
1614 q{')city', }.
1615 q{')customer'},
1616 'Pod-Test case no 21-j: output line 2');
1617  
1618 Test::More::is($lin4[ 3],
1619 q{Pyx: }.
1620 q{'(customer', }.
1621 q{'Aid 184', }.
1622 q{'Aname &jones', }.
1623 q{'(street', }.
1624 q{'-maple street', }.
1625 q{')street', }.
1626 q{'(city', }.
1627 q{'-new york', }.
1628 q{')city', }.
1629 q{')customer'},
1630 'Pod-Test case no 21-j: output line 3');
1631  
1632 Test::More::is($lin4[ 4],
1633 q{Pyx: }.
1634 q{'(customer', }.
1635 q{'Aid 520', }.
1636 q{'Aname stewart', }.
1637 q{'(street', }.
1638 q{'-ring road', }.
1639 q{')street', }.
1640 q{'(city', }.
1641 q{'-"'&<A>'"', }.
1642 q{')city', }.
1643 q{')customer'},
1644 'Pod-Test case no 21-j: output line 4');
1645 }
1646  
1647 {
1648 my $rdr = $XML_Reader_Any->new(\$line2, {filter => 5, sepchar => ' ! '},
1649 { root => '/data/section', branch => [
1650 '/tcustomer/@name',
1651 '/tcustomer/@id',
1652 '/tcustomer/street',
1653 '/tcustomer/city',
1654 ] },
1655 );
1656  
1657 my @l_name;
1658 my @l_id;
1659 my @l_street;
1660 my @l_city;
1661  
1662 while ($rdr->iterate) {
1663 my ($name, $id, $street, $city) = $rdr->value;
1664 for ($name, $id, $street, $city) { $_ = '*undef*' unless defined $_; }
1665  
1666 push @l_name, $name;
1667 push @l_id, $id;
1668 push @l_street, $street;
1669 push @l_city, $city;
1670 }
1671  
1672 Test::More::is(scalar(@l_name), 2, 'Pod-Test case no 21-k: l_name - number of output lines');
1673 Test::More::is($l_name[ 0], q{troy}, 'Pod-Test case no 21-k: l_name - output line 0');
1674 Test::More::is($l_name[ 1], q{ ! nb ! john ! bob}, 'Pod-Test case no 21-k: l_name - output line 1');
1675  
1676 Test::More::is(scalar(@l_id), 2, 'Pod-Test case no 21-k: l_id - number of output lines');
1677 Test::More::is($l_id[ 0], q{44}, 'Pod-Test case no 21-k: l_id - output line 0');
1678 Test::More::is($l_id[ 1], q{*undef*}, 'Pod-Test case no 21-k: l_id - output line 1');
1679  
1680 Test::More::is(scalar(@l_street), 2, 'Pod-Test case no 21-k: l_street - number of output lines');
1681 Test::More::is($l_street[ 0], q{on}, 'Pod-Test case no 21-k: l_street - output line 0');
1682 Test::More::is($l_street[ 1], q{aw ! sn}, 'Pod-Test case no 21-k: l_street - output line 1');
1683  
1684 Test::More::is(scalar(@l_city), 2, 'Pod-Test case no 21-k: l_city - number of output lines');
1685 Test::More::is($l_city[ 0], q{rr}, 'Pod-Test case no 21-k: l_city - output line 0');
1686 Test::More::is($l_city[ 1], q{ac ! abc}, 'Pod-Test case no 21-k: l_city - output line 1');
1687 }
1688  
1689 {
1690 my $rdr = $XML_Reader_Any->new(\$line2, {filter => 5}, # ... the same as the previous case, except here is no {sepchar => }
1691 { root => '/data/section', branch => [
1692 '/tcustomer/@name',
1693 '/tcustomer/@id',
1694 '/tcustomer/street',
1695 '/tcustomer/city',
1696 ] },
1697 );
1698  
1699 my @l_name;
1700 my @l_id;
1701 my @l_street;
1702 my @l_city;
1703  
1704 while ($rdr->iterate) {
1705 my ($name, $id, $street, $city) = $rdr->value;
1706 for ($name, $id, $street, $city) { $_ = '*undef*' unless defined $_; }
1707  
1708 push @l_name, $name;
1709 push @l_id, $id;
1710 push @l_street, $street;
1711 push @l_city, $city;
1712 }
1713  
1714 Test::More::is(scalar(@l_name), 2, 'Pod-Test case no 21-l: l_name - number of output lines');
1715 Test::More::is($l_name[ 0], q{troy}, 'Pod-Test case no 21-l: l_name - output line 0');
1716 Test::More::is($l_name[ 1], q{nbjohnbob}, 'Pod-Test case no 21-l: l_name - output line 1');
1717  
1718 Test::More::is(scalar(@l_id), 2, 'Pod-Test case no 21-l: l_id - number of output lines');
1719 Test::More::is($l_id[ 0], q{44}, 'Pod-Test case no 21-l: l_id - output line 0');
1720 Test::More::is($l_id[ 1], q{*undef*}, 'Pod-Test case no 21-l: l_id - output line 1');
1721  
1722 Test::More::is(scalar(@l_street), 2, 'Pod-Test case no 21-l: l_street - number of output lines');
1723 Test::More::is($l_street[ 0], q{on}, 'Pod-Test case no 21-l: l_street - output line 0');
1724 Test::More::is($l_street[ 1], q{awsn}, 'Pod-Test case no 21-l: l_street - output line 1');
1725  
1726 Test::More::is(scalar(@l_city), 2, 'Pod-Test case no 21-l: l_city - number of output lines');
1727 Test::More::is($l_city[ 0], q{rr}, 'Pod-Test case no 21-l: l_city - output line 0');
1728 Test::More::is($l_city[ 1], q{acabc}, 'Pod-Test case no 21-l: l_city - output line 1');
1729 }
1730  
1731 {
1732 my $rdr_strip_0 = $XML_Reader_Any->new(\$line2, {filter => 5, sepchar => '*', strip => 0},
1733 { root => '/data/section9', branch => [
1734 '/tcustomer/@y',
1735 '/tcustomer/@z',
1736 '/tcustomer/d1',
1737 '/tcustomer/d2',
1738 ] },
1739 );
1740  
1741 my $txt_strip_0 = '';
1742 while ($rdr_strip_0->iterate) {
1743 my ($y, $z, $d1, $d2) = $rdr_strip_0->value;
1744 for ($y, $z, $d1, $d2) { $_ = '?' unless defined $_; }
1745 $txt_strip_0 .= "[y='$y', z='$z', d1='$d1', d2='$d2']";
1746 }
1747  
1748 my $rdr_strip_1 = $XML_Reader_Any->new(\$line2, {filter => 5, sepchar => '*', strip => 1},
1749 { root => '/data/section9', branch => [
1750 '/tcustomer/@y',
1751 '/tcustomer/@z',
1752 '/tcustomer/d1',
1753 '/tcustomer/d2',
1754 ] },
1755 );
1756  
1757 my $txt_strip_1 = '';
1758 while ($rdr_strip_1->iterate) {
1759 my ($y, $z, $d1, $d2) = $rdr_strip_1->value;
1760 for ($y, $z, $d1, $d2) { $_ = '?' unless defined $_; }
1761 $txt_strip_1 .= "[y='$y', z='$z', d1='$d1', d2='$d2']";
1762 }
1763  
1764 Test::More::is($txt_strip_0, q{[y='?', z='', d1='f', d2='g}.q{* }.q{']}, 'Pod-Test case no 21-n: txt_strip_0');
1765 Test::More::is($txt_strip_1, q{[y='?', z='', d1='f', d2='g}. q{']}, 'Pod-Test case no 21-n: txt_strip_1');
1766 }
1767 }
1768  
1769 {
1770 my $line2 = q{
1771 <data>
1772 <p>
1773 <p>b1</p>
1774 <p>b2</p>
1775 </p>
1776 <p>
1777 b3
1778 </p>
1779 </data>
1780 };
1781  
1782 my $rdr = $XML_Reader_Any->new(\$line2, {filter => 5},
1783 { root => 'p', branch => '*' },
1784 );
1785  
1786 my @lines;
1787  
1788 while ($rdr->iterate) {
1789 push @lines, $rdr->value;
1790 }
1791  
1792 Test::More::is(scalar(@lines), 2, 'Pod-Test case no 22: number of lines');
1793 Test::More::is($lines[ 0], q{<p><p>b1</p><p>b2</p></p>}, 'Pod-Test case no 22: line 0');
1794 Test::More::is($lines[ 1], q{<p>b3</p>}, 'Pod-Test case no 22: line 1');
1795 }
1796 }];
1797  
1798 $TestProg{'0030_test_Module.t'} = [29, sub {
1799 my ($XML_Reader_Any) = @_;
1800  
1801 Test::More::use_ok($XML_Reader_Any);
1802  
1803 {
1804 $DebCnt::obj = 0;
1805  
1806 my $alpha = $XML_Reader_Any->new(\'<data>abc</data>', {debug => DebCnt->new});
1807 my $beta = $XML_Reader_Any->new(\'<data>abc</data>', {debug => DebCnt->new});
1808  
1809 for (1..10) {
1810 my $rdr = $XML_Reader_Any->new(\'<data>abc</data>', {debug => DebCnt->new});
1811 }
1812  
1813 Test::More::is($DebCnt::obj, 2, 'XML::Reader does not leak memory');
1814 }
1815  
1816 Test::More::is(tresult($XML_Reader_Any, {filter => 0 }), q{[Err]}, 'Case 001a: {filter => 0 }');
1817 Test::More::is(tresult($XML_Reader_Any, {filter => 1 }), q{[Err]}, 'Case 001b: {filter => 1 }');
1818 Test::More::is(tresult($XML_Reader_Any, {filter => 2 }), q{[Ok]<@p1/a><@p2/b><dummy/><sub/data><dummy/>}, 'Case 001c: {filter => 2 }');
1819 Test::More::is(tresult($XML_Reader_Any, {filter => 3 }), q{[Ok]<dummy/><sub/data><dummy/>}, 'Case 001d: {filter => 3 }');
1820 Test::More::is(tresult($XML_Reader_Any, {filter => 4 }), q{[Ok]<dummy/><@p1/a><@p2/b><sub/><sub/data><sub/><dummy/>}, 'Case 001f: {filter => 4 }');
1821 Test::More::is(tresult($XML_Reader_Any, {filter => 5 }), q{[Ok]<dummy/<dummy p1='a' p2='b'><sub>data</sub></dummy>>}, 'Case 001e: {filter => 5 }');
1822 Test::More::is(tresult($XML_Reader_Any, {filter => 888 }), q{[Err]}, 'Case 001g: {filter => 888 }');
1823  
1824 Test::More::is(tresult($XML_Reader_Any, {filter => 2, mode => 'attr-bef-start*'}), q{[Err]}, 'Case 002a: {filter => 2, mode => attr-bef-start*}');
1825 Test::More::is(tresult($XML_Reader_Any, {filter => 3, mode => 'attr-in-hash*' }), q{[Err]}, 'Case 002b: {filter => 3, mode => attr-in-hash* }');
1826 Test::More::is(tresult($XML_Reader_Any, {filter => 4, mode => 'pyx*' }), q{[Err]}, 'Case 002c: {filter => 4, mode => pyx* }');
1827 Test::More::is(tresult($XML_Reader_Any, {filter => 5, mode => 'branches*' }), q{[Err]}, 'Case 002d: {filter => 5, mode => branches* }');
1828  
1829 Test::More::is(tresult($XML_Reader_Any, {filter => 2, mode => 'attr-bef-start' }), q{[Ok]<@p1/a><@p2/b><dummy/><sub/data><dummy/>}, 'Case 003a: {filter => 2, mode => attr-bef-start }');
1830 Test::More::is(tresult($XML_Reader_Any, {filter => 3, mode => 'attr-in-hash' }), q{[Ok]<dummy/><sub/data><dummy/>}, 'Case 003b: {filter => 3, mode => attr-in-hash }');
1831 Test::More::is(tresult($XML_Reader_Any, {filter => 4, mode => 'pyx' }), q{[Ok]<dummy/><@p1/a><@p2/b><sub/><sub/data><sub/><dummy/>}, 'Case 003c: {filter => 4, mode => pyx }');
1832 Test::More::is(tresult($XML_Reader_Any, {filter => 5, mode => 'branches' }), q{[Ok]<dummy/<dummy p1='a' p2='b'><sub>data</sub></dummy>>}, 'Case 003d: {filter => 5, mode => branches }');
1833  
1834 Test::More::is(tresult($XML_Reader_Any, { mode => 'attr-bef-start' }), q{[Ok]<@p1/a><@p2/b><dummy/><sub/data><dummy/>}, 'Case 004a: { mode => attr-bef-start }');
1835 Test::More::is(tresult($XML_Reader_Any, { mode => 'attr-in-hash' }), q{[Ok]<dummy/><sub/data><dummy/>}, 'Case 004b: { mode => attr-in-hash }');
1836 Test::More::is(tresult($XML_Reader_Any, { mode => 'pyx' }), q{[Ok]<dummy/><@p1/a><@p2/b><sub/><sub/data><sub/><dummy/>}, 'Case 004c: { mode => pyx }');
1837 Test::More::is(tresult($XML_Reader_Any, { mode => 'branches' }), q{[Ok]<dummy/<dummy p1='a' p2='b'><sub>data</sub></dummy>>}, 'Case 004d: { mode => branches }');
1838  
1839 {
1840 my $data = q{<?xml version="1.0" encoding="iso-8859-1"?><init>n <?test pi?> t<page node="400">m <!-- remark --> r</page></init>};
1841  
1842 {
1843 my $rdr = $XML_Reader_Any->new(\$data, {filter => 5, parse_ct => 0, parse_pi => 0},
1844 {root => '/init', branch => '*'});
1845 $rdr->iterate;
1846  
1847 Test::More::is($rdr->value, q{<init>n t<page node='400'>m r</page></init>}, 'test-branch-001: {parse_ct => 0, parse_pi => 0}');
1848 }
1849  
1850 {
1851 my $rdr = $XML_Reader_Any->new(\$data, {filter => 5, parse_ct => 1, parse_pi => 0},
1852 {root => '/init', branch => '*'});
1853 $rdr->iterate;
1854  
1855 Test::More::is($rdr->value, q{<init>n t<page node='400'>m<!-- remark -->r</page></init>}, 'test-branch-002: {parse_ct => 1, parse_pi => 0}');
1856 }
1857  
1858 {
1859 my $rdr = $XML_Reader_Any->new(\$data, {filter => 5, parse_ct => 0, parse_pi => 1},
1860 {root => '/init', branch => '*'});
1861 $rdr->iterate;
1862  
1863 Test::More::is($rdr->value, q{<init>n<?test pi?>t<page node='400'>m r</page></init>}, 'test-branch-003: {parse_ct => 0, parse_pi => 1}');
1864 }
1865  
1866 {
1867 my $rdr = $XML_Reader_Any->new(\$data, {filter => 5, parse_ct => 1, parse_pi => 1},
1868 {root => '/init', branch => '*'});
1869 $rdr->iterate;
1870  
1871 Test::More::is($rdr->value, q{<init>n<?test pi?>t<page node='400'>m<!-- remark -->r</page></init>}, 'test-branch-004: {parse_ct => 1, parse_pi => 1}');
1872 }
1873 }
1874  
1875 {
1876 my $data = q{<?xml version="1.0" encoding="iso-8859-1"?><data/>};
1877 my $rdr = $XML_Reader_Any->new(\$data, {parse_pi => 1});
1878 my %d; while ($rdr->iterate) { %d = (%d, %{$rdr->dec_hash}); }
1879 Test::More::is(join(' ', map {"$_='$d{$_}'"} sort keys %d), q{encoding='iso-8859-1' version='1.0'}, 'test-decl-001: <?xml version="1.0" encoding="iso-8859-1"?>');
1880 }
1881  
1882 {
1883 my $data = q{<?xml version="1.0" standalone="yes"?><data/>};
1884 my $rdr = $XML_Reader_Any->new(\$data, {parse_pi => 1});
1885 my %d; while ($rdr->iterate) { %d = (%d, %{$rdr->dec_hash}); }
1886 Test::More::is(join(' ', map {"$_='$d{$_}'"} sort keys %d), q{standalone='yes' version='1.0'}, 'test-decl-002: <?xml version="1.0" standalone="yes"?>');
1887 }
1888  
1889 {
1890 my $data = q{<?xml version="1.0" standalone="no"?><data/>};
1891 my $rdr = $XML_Reader_Any->new(\$data, {parse_pi => 1});
1892 my %d; while ($rdr->iterate) { %d = (%d, %{$rdr->dec_hash}); }
1893 Test::More::is(join(' ', map {"$_='$d{$_}'"} sort keys %d), q{standalone='no' version='1.0'}, 'test-decl-003: <?xml version="1.0" standalone="no"?>');
1894 }
1895  
1896 {
1897 my $data = q{<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?><data/>};
1898 my $rdr = $XML_Reader_Any->new(\$data, {parse_pi => 1});
1899 my %d; while ($rdr->iterate) { %d = (%d, %{$rdr->dec_hash}); }
1900 Test::More::is(join(' ', map {"$_='$d{$_}'"} sort keys %d), q{encoding='iso-8859-1' standalone='yes' version='1.0'}, 'test-decl-004: <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>');
1901 }
1902 }];
1903  
1904 {
1905 package DebCnt;
1906 $DebCnt::VERSION = '0.67';
1907 sub new { our $obj++; bless {}; }
1908 sub DESTROY { our $obj--; }
1909 }
1910  
1911 sub tresult {
1912 my ($module, $opt) = @_;
1913  
1914 my $text = q{<dummy p1="a" p2="b"><sub>data</sub></dummy>};
1915  
1916 my $rdr = eval{ $module->new(\$text, $opt, {root => '/dummy', branch => '*'}) };
1917  
1918 my $output = '['.($@ ? 'Err' : 'Ok').']';
1919  
1920 if ($rdr) {
1921 while ($rdr->iterate) { $output .= '<'.$rdr->tag.'/'.$rdr->value.'>'; }
1922 }
1923  
1924 $output;
1925 }
1926  
1927 1;
1928  
1929 __END__