2
0

prepend.t 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!perl
  2. #
  3. # Tests for PREPEND features
  4. # These tests first appeared in version 1.22.
  5. use strict;
  6. use warnings;
  7. use Test::More tests => 10;
  8. use_ok 'Text::Template' or exit 1;
  9. @Emptyclass1::ISA = 'Text::Template';
  10. @Emptyclass2::ISA = 'Text::Template';
  11. my $tin = q{The value of $foo is: {$foo}};
  12. Text::Template->always_prepend(q{$foo = "global"});
  13. my $tmpl1 = Text::Template->new(
  14. TYPE => 'STRING',
  15. SOURCE => $tin);
  16. my $tmpl2 = Text::Template->new(
  17. TYPE => 'STRING',
  18. SOURCE => $tin,
  19. PREPEND => q{$foo = "template"});
  20. $tmpl1->compile;
  21. $tmpl2->compile;
  22. my $t1 = $tmpl1->fill_in(PACKAGE => 'T1');
  23. my $t2 = $tmpl2->fill_in(PACKAGE => 'T2');
  24. my $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T3');
  25. is $t1, 'The value of $foo is: global';
  26. is $t2, 'The value of $foo is: template';
  27. is $t3, 'The value of $foo is: fillin';
  28. Emptyclass1->always_prepend(q{$foo = 'Emptyclass global';});
  29. $tmpl1 = Emptyclass1->new(
  30. TYPE => 'STRING',
  31. SOURCE => $tin);
  32. $tmpl2 = Emptyclass1->new(
  33. TYPE => 'STRING',
  34. SOURCE => $tin,
  35. PREPEND => q{$foo = "template"});
  36. $tmpl1->compile;
  37. $tmpl2->compile;
  38. $t1 = $tmpl1->fill_in(PACKAGE => 'T4');
  39. $t2 = $tmpl2->fill_in(PACKAGE => 'T5');
  40. $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
  41. is $t1, 'The value of $foo is: Emptyclass global';
  42. is $t2, 'The value of $foo is: template';
  43. is $t3, 'The value of $foo is: fillin';
  44. $tmpl1 = Emptyclass2->new(
  45. TYPE => 'STRING',
  46. SOURCE => $tin);
  47. $tmpl2 = Emptyclass2->new(
  48. TYPE => 'STRING',
  49. SOURCE => $tin,
  50. PREPEND => q{$foo = "template"});
  51. $tmpl1->compile;
  52. $tmpl2->compile;
  53. $t1 = $tmpl1->fill_in(PACKAGE => 'T4');
  54. $t2 = $tmpl2->fill_in(PACKAGE => 'T5');
  55. $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
  56. is $t1, 'The value of $foo is: global';
  57. is $t2, 'The value of $foo is: template';
  58. is $t3, 'The value of $foo is: fillin';