-
Notifications
You must be signed in to change notification settings - Fork 94
/
domview.t
91 lines (79 loc) · 1.92 KB
/
domview.t
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
#============================================================= -*-perl-*-
#
# t/domview.t
#
# Test the XML::DOM plugin presenting via a VIEW
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================
use strict;
use lib qw( ./lib ../lib );
use Template;
use Template::Test;
use Cwd qw( abs_path );
$^W = 1;
#$Template::Test::DEBUG = 1;
#$Template::Test::PRESERVE = 1;
# I hate having to do this
my $shut_up_warnings = $XML::DOM::VERSION;
eval "use XML::DOM";
if ($@ || $XML::DOM::VERSION < 1.27) {
skip_all("XML::DOM v1.27 or later not installed");
}
test_expect(\*DATA);
__END__
-- test --
[% xmltext = BLOCK -%]
<report>
<section title="Introduction">
<p>
Blah blah.
<ul>
<li>Item 1</li>
<li>item 2</li>
</ul>
</p>
</section>
<section title="The Gory Details">
...
</section>
</report>
[% END -%]
[% USE dom = XML.DOM;
doc = dom.parse(text => xmltext);
report = doc.getElementsByTagName('report')
-%]
[% VIEW report_view notfound='xmlstring' %]
# handler block for a <report>...</report> element
[% BLOCK report; item.content(view); END %]
# handler block for a <section title="...">...</section> element
[% BLOCK section -%]
<h1>[% item.title %]</h1>
[% item.content(view) -%]
[% END -%]
# default template block converts item to string representation
[% BLOCK xmlstring; item.toString; END %]
# block to generate simple text
[% BLOCK text; item; END %]
[% END -%]
REPORT: [% report_view.print(report) | trim %]
-- expect --
REPORT: <h1>Introduction</h1>
<p>
Blah blah.
<ul>
<li>Item 1</li>
<li>item 2</li>
</ul>
</p>
<h1>The Gory Details</h1>
...