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