xref: /freebsd-src/crypto/openssl/external/perl/Text-Template-1.56/t/prepend.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#!perl
2*e0c4386eSCy Schubert#
3*e0c4386eSCy Schubert# Tests for PREPEND features
4*e0c4386eSCy Schubert# These tests first appeared in version 1.22.
5*e0c4386eSCy Schubert
6*e0c4386eSCy Schubertuse strict;
7*e0c4386eSCy Schubertuse warnings;
8*e0c4386eSCy Schubertuse Test::More tests => 10;
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 Schubertmy $t1 = $tmpl1->fill_in(PACKAGE => 'T1');
32*e0c4386eSCy Schubertmy $t2 = $tmpl2->fill_in(PACKAGE => 'T2');
33*e0c4386eSCy Schubertmy $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T3');
34*e0c4386eSCy Schubert
35*e0c4386eSCy Schubertis $t1, 'The value of $foo is: global';
36*e0c4386eSCy Schubertis $t2, 'The value of $foo is: template';
37*e0c4386eSCy Schubertis $t3, 'The value of $foo is: fillin';
38*e0c4386eSCy Schubert
39*e0c4386eSCy SchubertEmptyclass1->always_prepend(q{$foo = 'Emptyclass global';});
40*e0c4386eSCy Schubert$tmpl1 = Emptyclass1->new(
41*e0c4386eSCy Schubert    TYPE   => 'STRING',
42*e0c4386eSCy Schubert    SOURCE => $tin);
43*e0c4386eSCy Schubert
44*e0c4386eSCy Schubert$tmpl2 = Emptyclass1->new(
45*e0c4386eSCy Schubert    TYPE    => 'STRING',
46*e0c4386eSCy Schubert    SOURCE  => $tin,
47*e0c4386eSCy Schubert    PREPEND => q{$foo = "template"});
48*e0c4386eSCy Schubert
49*e0c4386eSCy Schubert$tmpl1->compile;
50*e0c4386eSCy Schubert$tmpl2->compile;
51*e0c4386eSCy Schubert
52*e0c4386eSCy Schubert$t1 = $tmpl1->fill_in(PACKAGE => 'T4');
53*e0c4386eSCy Schubert$t2 = $tmpl2->fill_in(PACKAGE => 'T5');
54*e0c4386eSCy Schubert$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
55*e0c4386eSCy Schubert
56*e0c4386eSCy Schubertis $t1, 'The value of $foo is: Emptyclass global';
57*e0c4386eSCy Schubertis $t2, 'The value of $foo is: template';
58*e0c4386eSCy Schubertis $t3, 'The value of $foo is: fillin';
59*e0c4386eSCy Schubert
60*e0c4386eSCy Schubert$tmpl1 = Emptyclass2->new(
61*e0c4386eSCy Schubert    TYPE   => 'STRING',
62*e0c4386eSCy Schubert    SOURCE => $tin);
63*e0c4386eSCy Schubert
64*e0c4386eSCy Schubert$tmpl2 = Emptyclass2->new(
65*e0c4386eSCy Schubert    TYPE    => 'STRING',
66*e0c4386eSCy Schubert    SOURCE  => $tin,
67*e0c4386eSCy Schubert    PREPEND => q{$foo = "template"});
68*e0c4386eSCy Schubert
69*e0c4386eSCy Schubert$tmpl1->compile;
70*e0c4386eSCy Schubert$tmpl2->compile;
71*e0c4386eSCy Schubert
72*e0c4386eSCy Schubert$t1 = $tmpl1->fill_in(PACKAGE => 'T4');
73*e0c4386eSCy Schubert$t2 = $tmpl2->fill_in(PACKAGE => 'T5');
74*e0c4386eSCy Schubert$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
75*e0c4386eSCy Schubert
76*e0c4386eSCy Schubertis $t1, 'The value of $foo is: global';
77*e0c4386eSCy Schubertis $t2, 'The value of $foo is: template';
78*e0c4386eSCy Schubertis $t3, 'The value of $foo is: fillin';
79