3 # test apparatus for Text::Template module
9 unless (eval { require Safe; 1 }) {
10 plan skip_all => 'Safe.pm is required for this test';
16 use_ok 'Text::Template' or exit 1;
18 # Test the OUT feature with safe compartments
21 This line should have a 3: {1+2}
23 This line should have several numbers:
24 { $t = ''; foreach $n (1 .. 20) { $t .= $n . ' ' } $t }
28 This line should have a 3: { $OUT = 1+2 }
30 This line should have several numbers:
31 { foreach $n (1 .. 20) { $OUT .= $n . ' ' } }
36 # Build templates from string
37 $template = Text::Template->new(
42 $templateOUT = Text::Template->new(
44 source => $templateOUT,
48 my $text = $template->fill_in()
50 my $textOUT = $templateOUT->fill_in()
53 # (1) They should be the same
56 # (2-3) "Joel Appelbaum" <joel@orbz.com> <000701c0ac2c$aed1d6e0$0201a8c0@prime>
57 # "Contrary to the documentation the $OUT variable is not always
58 # undefined at the start of each program fragment. The $OUT variable
59 # is never undefined after it is used once if you are using the SAFE
60 # option. The result is that every fragment after the fragment that
61 # $OUT was used in is replaced by the old $OUT value instead of the
62 # result of the fragment. This holds true even after the
63 # Text::Template object goes out of scope and a new one is created!"
65 # Also reported by Daini Xie.
68 my $template = q{{$OUT = 'x'}y{$OUT .= 'z'}};
71 my $o = Text::Template->new(
76 my $r = $o->fill_in(SAFE => $s);