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