3 # test apparatus for Text::Template module
15 die "This is the test program for Text::Template version 1.46.
16 You are using version $Text::Template::VERSION instead.
17 That does not make sense.\n
19 unless $Text::Template::VERSION == 1.46;
25 # Test the OUT feature with safe compartments
28 This line should have a 3: {1+2}
30 This line should have several numbers:
31 { $t = ''; foreach $n (1 .. 20) { $t .= $n . ' ' } $t }
35 This line should have a 3: { $OUT = 1+2 }
37 This line should have several numbers:
38 { foreach $n (1 .. 20) { $OUT .= $n . ' ' } }
43 # Build templates from string
44 $template = new Text::Template ('type' => 'STRING', 'source' => $template,
47 $templateOUT = new Text::Template ('type' => 'STRING', 'source' => $templateOUT,
52 $text = $template->fill_in()
54 $textOUT = $templateOUT->fill_in()
57 # (1) They should be the same
58 print +($text eq $textOUT ? '' : 'not '), "ok $n\n";
61 # (2-3) "Joel Appelbaum" <joel@orbz.com> <000701c0ac2c$aed1d6e0$0201a8c0@prime>
62 # "Contrary to the documentation the $OUT variable is not always
63 # undefined at the start of each program fragment. The $OUT variable
64 # is never undefined after it is used once if you are using the SAFE
65 # option. The result is that every fragment after the fragment that
66 # $OUT was used in is replaced by the old $OUT value instead of the
67 # result of the fragment. This holds true even after the
68 # Text::Template object goes out of scope and a new one is created!"
70 # Also reported by Daini Xie.
73 my $template = q{{$OUT = 'x'}y{$OUT .= 'z'}};
76 my $o = Text::Template->new(type => 'string',
80 my $r = $o->fill_in(SAFE => $s);
81 if ($r ne $expected) {
82 print "not ok $n # <$r>\n";