1#!perl 2# 3# Tests for PREPEND features 4# These tests first appeared in version 1.22. 5 6use Text::Template; 7 8die "This is the test program for Text::Template version 1.46 9You are using version $Text::Template::VERSION instead. 10That does not make sense.\n 11Aborting" 12 unless $Text::Template::VERSION == 1.46; 13 14print "1..9\n"; 15my $n = 1; 16 17@Emptyclass1::ISA = 'Text::Template'; 18@Emptyclass2::ISA = 'Text::Template'; 19 20my $tin = q{The value of $foo is: {$foo}}; 21 22Text::Template->always_prepend(q{$foo = "global"}); 23 24$tmpl1 = Text::Template->new(TYPE => 'STRING', 25 SOURCE => $tin, 26 ); 27 28$tmpl2 = Text::Template->new(TYPE => 'STRING', 29 SOURCE => $tin, 30 PREPEND => q{$foo = "template"}, 31 ); 32 33$tmpl1->compile; 34$tmpl2->compile; 35 36$t1 = $tmpl1->fill_in(PACKAGE => 'T1'); 37$t2 = $tmpl2->fill_in(PACKAGE => 'T2'); 38$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T3'); 39 40($t1 eq 'The value of $foo is: global') or print "not "; 41print "ok $n\n"; $n++; 42($t2 eq 'The value of $foo is: template') or print "not "; 43print "ok $n\n"; $n++; 44($t3 eq 'The value of $foo is: fillin') or print "not "; 45print "ok $n\n"; $n++; 46 47Emptyclass1->always_prepend(q{$foo = 'Emptyclass global';}); 48$tmpl1 = Emptyclass1->new(TYPE => 'STRING', 49 SOURCE => $tin, 50 ); 51 52$tmpl2 = Emptyclass1->new(TYPE => 'STRING', 53 SOURCE => $tin, 54 PREPEND => q{$foo = "template"}, 55 ); 56 57$tmpl1->compile; 58$tmpl2->compile; 59 60$t1 = $tmpl1->fill_in(PACKAGE => 'T4'); 61$t2 = $tmpl2->fill_in(PACKAGE => 'T5'); 62$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6'); 63 64($t1 eq 'The value of $foo is: Emptyclass global') or print "not "; 65print "ok $n\n"; $n++; 66($t2 eq 'The value of $foo is: template') or print "not "; 67print "ok $n\n"; $n++; 68($t3 eq 'The value of $foo is: fillin') or print "not "; 69print "ok $n\n"; $n++; 70 71$tmpl1 = Emptyclass2->new(TYPE => 'STRING', 72 SOURCE => $tin, 73 ); 74 75$tmpl2 = Emptyclass2->new(TYPE => 'STRING', 76 SOURCE => $tin, 77 PREPEND => q{$foo = "template"}, 78 ); 79 80$tmpl1->compile; 81$tmpl2->compile; 82 83$t1 = $tmpl1->fill_in(PACKAGE => 'T4'); 84$t2 = $tmpl2->fill_in(PACKAGE => 'T5'); 85$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6'); 86 87($t1 eq 'The value of $foo is: global') or print "not "; 88print "ok $n\n"; $n++; 89($t2 eq 'The value of $foo is: template') or print "not "; 90print "ok $n\n"; $n++; 91($t3 eq 'The value of $foo is: fillin') or print "not "; 92print "ok $n\n"; $n++; 93 94 95