1 | #!perl
|
---|
2 | #
|
---|
3 | # Tests for STRICT features
|
---|
4 | # These tests first appeared in version 1.48.
|
---|
5 |
|
---|
6 | use strict;
|
---|
7 | use warnings;
|
---|
8 | use Test::More tests => 4;
|
---|
9 |
|
---|
10 | use_ok 'Text::Template' or exit 1;
|
---|
11 |
|
---|
12 | @Emptyclass1::ISA = 'Text::Template';
|
---|
13 | @Emptyclass2::ISA = 'Text::Template';
|
---|
14 |
|
---|
15 | my $tin = q{The value of $foo is: {$foo}};
|
---|
16 |
|
---|
17 | Text::Template->always_prepend(q{$foo = "global"});
|
---|
18 |
|
---|
19 | my $tmpl1 = Text::Template->new(
|
---|
20 | TYPE => 'STRING',
|
---|
21 | SOURCE => $tin);
|
---|
22 |
|
---|
23 | my $tmpl2 = Text::Template->new(
|
---|
24 | TYPE => 'STRING',
|
---|
25 | SOURCE => $tin,
|
---|
26 | PREPEND => q{$foo = "template"});
|
---|
27 |
|
---|
28 | $tmpl1->compile;
|
---|
29 | $tmpl2->compile;
|
---|
30 |
|
---|
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' });
|
---|
33 |
|
---|
34 | # non-strict still works
|
---|
35 | my $t2 = $tmpl2->fill_in(PACKAGE => 'T2', HASH => { bar => 'baz' });
|
---|
36 |
|
---|
37 | # prepend overrides the hash values
|
---|
38 | my $t3 = $tmpl2->fill_in(
|
---|
39 | PREPEND => q{$foo = "fillin"},
|
---|
40 | PACKAGE => 'T3',
|
---|
41 | STRICT => 1,
|
---|
42 | HASH => { foo => 'hashval2' });
|
---|
43 |
|
---|
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.";
|
---|