3 # Tests for STRICT features
4 # These tests first appeared in version 1.48.
8 use Test::More tests => 4;
10 use_ok 'Text::Template' or exit 1;
12 @Emptyclass1::ISA = 'Text::Template';
13 @Emptyclass2::ISA = 'Text::Template';
15 my $tin = q{The value of $foo is: {$foo}};
17 Text::Template->always_prepend(q{$foo = "global"});
19 my $tmpl1 = Text::Template->new(
23 my $tmpl2 = Text::Template->new(
26 PREPEND => q{$foo = "template"});
31 # strict should cause t1 to contain an error message if wrong variable is used in template
32 my $t1 = $tmpl1->fill_in(PACKAGE => 'T1', STRICT => 1, HASH => { bar => 'baz' });
34 # non-strict still works
35 my $t2 = $tmpl2->fill_in(PACKAGE => 'T2', HASH => { bar => 'baz' });
37 # prepend overrides the hash values
38 my $t3 = $tmpl2->fill_in(
39 PREPEND => q{$foo = "fillin"},
42 HASH => { foo => 'hashval2' });
44 like $t1, qr/Global symbol "\$foo" requires explicit package/;
45 is $t2, 'The value of $foo is: template', "non-strict hash still works";
46 is $t3, "The value of \$foo is: fillin", "hash values with prepend, prepend wins, even under strict.";