3 # test apparatus for Text::Template module
16 die "This is the test program for Text::Template version 1.46.
17 You are using version $Text::Template::VERSION instead.
18 That does not make sense.\n
20 unless $Text::Template::VERSION == 1.46;
27 # Test handling of packages and importing.
28 $c->reval('$P = "safe root"');
32 # How to effectively test the gensymming?
34 $t = new Text::Template TYPE => 'STRING', SOURCE => 'package is {$P}'
37 # (1) Default behavior: Inherit from calling package, `main' in this case.
38 $text = $t->fill_in();
39 print +($text eq 'package is main' ? '' : 'not '), "ok $n\n";
42 # (2) When a package is specified, we should use that package instead.
43 $text = $t->fill_in(PACKAGE => 'Q');
44 print +($text eq 'package is Q' ? '' : 'not '), "ok $n\n";
47 # (3) When no package is specified in safe mode, we should use the
49 $text = $t->fill_in(SAFE => $c);
50 print +($text eq 'package is safe root' ? '' : 'not '), "ok $n\n";
53 # (4) When a package is specified in safe mode, we should use the
54 # default safe root, after aliasing to the specified package
55 $text = $t->fill_in(SAFE => $c, PACKAGE => Q);
56 print +($text eq 'package is Q' ? '' : 'not '), "ok $n\n";
59 # Now let's see if hash vars are installed properly into safe templates
60 $t = new Text::Template TYPE => 'STRING', SOURCE => 'hash is {$H}'
63 # (5) First in default mode
64 $text = $t->fill_in(HASH => {H => 'good5'} );
65 print +($text eq 'hash is good5' ? '' : 'not '), "ok $n\n";
69 $text = $t->fill_in(HASH => {H => 'good6'}, PACKAGE => 'Q' );
70 print +($text eq 'hash is good6' ? '' : 'not '), "ok $n\n";
73 # (7) Now in the default root of the safe compartment
74 $text = $t->fill_in(HASH => {H => 'good7'}, SAFE => $c );
75 print +($text eq 'hash is good7' ? '' : 'not '), "ok $n\n";
78 # (8) Now in the default root after aliasing to a package that
79 # got the hash stuffed in
80 $text = $t->fill_in(HASH => {H => 'good8'}, SAFE => $c, PACKAGE => 'Q2' );
81 print +($text eq 'hash is good8' ? '' : 'not '), "ok $n\n";
84 # Now let's make sure that none of the packages leaked on each other.
85 # (9) This var should NOT have been installed into the main package
86 print +(defined $H ? 'not ' : ''), "ok $n\n";
90 # (10) good6 was overwritten in test 7, so there's nothing to test for here.
94 # (11) this value overwrote the one from test 6.
95 print +($Q::H eq 'good7' ? '' : 'not '), "ok $n\n";
100 print +($Q2::H eq 'good8' ? '' : 'not '), "ok $n\n";