1e1051a39Sopenharmony_ci#!perl
2e1051a39Sopenharmony_ci#
3e1051a39Sopenharmony_ci# Tests for STRICT features
4e1051a39Sopenharmony_ci# These tests first appeared in version 1.48.
5e1051a39Sopenharmony_ci
6e1051a39Sopenharmony_ciuse strict;
7e1051a39Sopenharmony_ciuse warnings;
8e1051a39Sopenharmony_ciuse Test::More tests => 4;
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ciuse_ok 'Text::Template' or exit 1;
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_ci@Emptyclass1::ISA = 'Text::Template';
13e1051a39Sopenharmony_ci@Emptyclass2::ISA = 'Text::Template';
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_cimy $tin = q{The value of $foo is: {$foo}};
16e1051a39Sopenharmony_ci
17e1051a39Sopenharmony_ciText::Template->always_prepend(q{$foo = "global"});
18e1051a39Sopenharmony_ci
19e1051a39Sopenharmony_cimy $tmpl1 = Text::Template->new(
20e1051a39Sopenharmony_ci    TYPE   => 'STRING',
21e1051a39Sopenharmony_ci    SOURCE => $tin);
22e1051a39Sopenharmony_ci
23e1051a39Sopenharmony_cimy $tmpl2 = Text::Template->new(
24e1051a39Sopenharmony_ci    TYPE    => 'STRING',
25e1051a39Sopenharmony_ci    SOURCE  => $tin,
26e1051a39Sopenharmony_ci    PREPEND => q{$foo = "template"});
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_ci$tmpl1->compile;
29e1051a39Sopenharmony_ci$tmpl2->compile;
30e1051a39Sopenharmony_ci
31e1051a39Sopenharmony_ci# strict should cause t1 to contain an error message if wrong variable is used in template
32e1051a39Sopenharmony_cimy $t1 = $tmpl1->fill_in(PACKAGE => 'T1', STRICT => 1, HASH => { bar => 'baz' });
33e1051a39Sopenharmony_ci
34e1051a39Sopenharmony_ci# non-strict still works
35e1051a39Sopenharmony_cimy $t2 = $tmpl2->fill_in(PACKAGE => 'T2', HASH => { bar => 'baz' });
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ci# prepend overrides the hash values
38e1051a39Sopenharmony_cimy $t3 = $tmpl2->fill_in(
39e1051a39Sopenharmony_ci    PREPEND => q{$foo = "fillin"},
40e1051a39Sopenharmony_ci    PACKAGE => 'T3',
41e1051a39Sopenharmony_ci    STRICT  => 1,
42e1051a39Sopenharmony_ci    HASH    => { foo => 'hashval2' });
43e1051a39Sopenharmony_ci
44e1051a39Sopenharmony_cilike $t1, qr/Global symbol "\$foo" requires explicit package/;
45e1051a39Sopenharmony_ciis $t2, 'The value of $foo is: template', "non-strict hash still works";
46e1051a39Sopenharmony_ciis $t3, "The value of \$foo is: fillin", "hash values with prepend, prepend wins, even under strict.";
47