Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 193 lines (174 sloc) 3.818 kB
3ebfa07 @abw Initial revision
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/evalperl.t
4 #
b4f721c @abw *** empty log message ***
authored
5 # Test the evaluation of PERL and RAWPERL blocks.
6 #
7 # Written by Andy Wardley <abw@kfs.org>
8 #
9 # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
10 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
11 #
12 # This is free software; you can redistribute it and/or modify it
13 # under the same terms as Perl itself.
14 #
15 # $Id$
3ebfa07 @abw Initial revision
authored
16 #
17 #========================================================================
18
19 use strict;
20 use lib qw( ./lib ../lib );
21 use Template::Test;
22 $^W = 1;
23
6cbf6f6 @abw *** empty log message ***
authored
24 #$Template::Parser::DEBUG = 1;
3e45060 @abw *** empty log message ***
authored
25 #$Template::Directive::PRETTY = 1;
b4f721c @abw *** empty log message ***
authored
26 #$Template::Context::DEBUG = 0;
3ebfa07 @abw Initial revision
authored
27
28 my $tt_no_perl = Template->new({
6cbf6f6 @abw *** empty log message ***
authored
29 INTERPOLATE => 1,
30 POST_CHOMP => 1,
31 EVAL_PERL => 0,
32 INCLUDE_PATH => -d 't' ? 't/test/lib' : 'test/lib',
3ebfa07 @abw Initial revision
authored
33 });
34
35 my $tt_do_perl = Template->new({
36 INTERPOLATE => 1,
37 POST_CHOMP => 1,
38 EVAL_PERL => 1,
3e45060 @abw *** empty log message ***
authored
39 INCLUDE_PATH => -d 't' ? 't/test/lib' : 'test/lib',
3ebfa07 @abw Initial revision
authored
40 });
41
42 my $ttprocs = [
43 no_perl => $tt_no_perl,
44 do_perl => $tt_do_perl,
45 ];
46
47 test_expect(\*DATA, $ttprocs, &callsign);
48
49 __DATA__
50
51 -- test --
52 [% META
53 author = 'Andy Wardley'
54 title = 'Test Template $foo #6'
55 version = 1.23
56 %]
5068caf @abw *** empty log message ***
authored
57 [% TRY %]
3ebfa07 @abw Initial revision
authored
58 [% PERL %]
59 my $output = "author: [% template.author %]\n";
60 $stash->set('a', 'The cat sat on the mat');
61 $output .= "more perl generated output\n";
0b63aae @abw *** empty log message ***
authored
62 print $output;
3ebfa07 @abw Initial revision
authored
63 [% END %]
5068caf @abw *** empty log message ***
authored
64 [% CATCH %]
3e45060 @abw *** empty log message ***
authored
65 Not allowed: [% error +%]
5068caf @abw *** empty log message ***
authored
66 [% END %]
3ebfa07 @abw Initial revision
authored
67 a: [% a +%]
68 a: $a
3e45060 @abw *** empty log message ***
authored
69 [% TRY %]
3ebfa07 @abw Initial revision
authored
70 [% RAWPERL %]
71 $output .= "The cat sat on the mouse mat\n";
72 $stash->set('b', 'The cat sat where?');
73 [% END %]
3e45060 @abw *** empty log message ***
authored
74 [% CATCH %]
75 Still not allowed: [% error +%]
76 [% END %]
3ebfa07 @abw Initial revision
authored
77 b: [% b +%]
78 b: $b
79 -- expect --
3e45060 @abw *** empty log message ***
authored
80 Not allowed: perl error - EVAL_PERL not set
3ebfa07 @abw Initial revision
authored
81 a: alpha
82 a: alpha
3e45060 @abw *** empty log message ***
authored
83 Still not allowed: perl error - EVAL_PERL not set
3ebfa07 @abw Initial revision
authored
84 b: bravo
85 b: bravo
86
6cbf6f6 @abw *** empty log message ***
authored
87 -- test --
5068caf @abw *** empty log message ***
authored
88 [% TRY %]
6cbf6f6 @abw *** empty log message ***
authored
89 nothing
90 [% PERL %]
91 We don't care about correct syntax within PERL blocks if EVAL_PERL isn't set.
92 They're simply ignored.
93 [% END %]
5068caf @abw *** empty log message ***
authored
94 [% CATCH %]
95 ERROR: [% error.type %]: [% error.info %]
96 [% END %]
6cbf6f6 @abw *** empty log message ***
authored
97 -- expect --
98 nothing
5068caf @abw *** empty log message ***
authored
99 ERROR: perl: EVAL_PERL not set
6cbf6f6 @abw *** empty log message ***
authored
100
101 -- test --
102 some stuff
103 [% TRY %]
104 [% INCLUDE badrawperl %]
105 [% CATCH %]
106 ERROR: [[% error.type %]] [% error.info %]
107 [% END %]
108 -- expect --
109 some stuff
3e45060 @abw *** empty log message ***
authored
110 This is some text
111 ERROR: [perl] EVAL_PERL not set
112
113 -- test --
114 -- use do_perl --
115 some stuff
116 [% TRY %]
117 [% INCLUDE badrawperl %]
118 [% CATCH +%]
119 ERROR: [[% error.type %]]
120 [% END %]
121 -- expect --
122 some stuff
123 This is some text
124 more stuff goes here
125 ERROR: [undef]
126
127 -- test --
128 -- use do_perl --
129 [% META author = 'Andy Wardley' %]
130 [% PERL %]
131 my $output = "author: [% template.author %]\n";
132 $stash->set('a', 'The cat sat on the mat');
133 $output .= "more perl generated output\n";
0b63aae @abw *** empty log message ***
authored
134 print $output;
3e45060 @abw *** empty log message ***
authored
135 [% END %]
136 -- expect --
137 author: Andy Wardley
138 more perl generated output
3ebfa07 @abw Initial revision
authored
139
140 -- test --
141 -- use do_perl --
142 [% META
143 author = 'Andy Wardley'
144 title = 'Test Template $foo #6'
145 version = 3.14
146 %]
147 [% PERL %]
148 my $output = "author: [% template.author %]\n";
149 $stash->set('a', 'The cat sat on the mat');
150 $output .= "more perl generated output\n";
0b63aae @abw *** empty log message ***
authored
151 print $output;
3ebfa07 @abw Initial revision
authored
152 [% END %]
153 a: [% a +%]
154 a: $a
155 [% RAWPERL %]
156 $output .= "The cat sat on the mouse mat\n";
157 $stash->set('b', 'The cat sat where?');
158 [% END %]
159 b: [% b +%]
160 b: $b
161 -- expect --
162 author: Andy Wardley
163 more perl generated output
164 a: The cat sat on the mat
165 a: The cat sat on the mat
166 The cat sat on the mouse mat
167 b: The cat sat where?
168 b: The cat sat where?
169
0b63aae @abw *** empty log message ***
authored
170 -- test --
171 [% BLOCK foo %]This is block foo[% END %]
172 [% PERL %]
173 print $context->include('foo');
174 print PERLOUT "\nbar\n";
175 [% END %]
176 The end
177 -- expect --
178 This is block foo
179 bar
180 The end
181
182 -- test --
183 [% TRY %]
184 [%- PERL %] die "nothing to live for\n" [% END %]
185 [% CATCH %]
186 error: [% error %]
187 [% END %]
188 -- expect --
189 error: undef error - nothing to live for
3ebfa07 @abw Initial revision
authored
190
5068caf @abw *** empty log message ***
authored
191
192
Something went wrong with that request. Please try again.