12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- use strict;
- use warnings;
- use Test::More;
- unless (eval { require Safe; 1 }) {
- plan skip_all => 'Safe.pm is required for this test';
- }
- else {
- plan tests => 12;
- }
- use_ok 'Text::Template' or exit 1;
- my $c = Safe->new or die;
- $c->reval('$P = "safe root"');
- our $P = 'main';
- $Q::P = $Q::P = 'Q';
- my $t = Text::Template->new(
- TYPE => 'STRING',
- SOURCE => 'package is {$P}') or die;
- my $text = $t->fill_in();
- is $text, 'package is main';
- $text = $t->fill_in(PACKAGE => 'Q');
- is $text, 'package is Q';
- $text = $t->fill_in(SAFE => $c);
- is $text, 'package is safe root';
- TODO: {
- local $TODO = "test fails when tested with TAP/Devel::Cover" if defined $Devel::Cover::VERSION;
- $text = $t->fill_in(SAFE => $c, PACKAGE => 'Q');
- is $text, 'package is Q';
- }
- $t = Text::Template->new(
- TYPE => 'STRING',
- SOURCE => 'hash is {$H}') or die;
- $text = $t->fill_in(HASH => { H => 'good5' });
- is $text, 'hash is good5';
- $Q::H = $Q2::H = undef;
- $text = $t->fill_in(HASH => { H => 'good6' }, PACKAGE => 'Q');
- is $text, 'hash is good6';
- TODO: {
- local $TODO = "test fails when tested with TAP/Devel::Cover" if defined $Devel::Cover::VERSION;
- $text = $t->fill_in(HASH => { H => 'good7' }, SAFE => $c);
- is $text, 'hash is good7';
- }
- our $H;
- TODO: {
- local $TODO = "test fails when tested with TAP/Devel::Cover" if defined $Devel::Cover::VERSION;
- $text = $t->fill_in(HASH => { H => 'good8' }, SAFE => $c, PACKAGE => 'Q2');
- is $text, 'hash is good8';
- }
- ok !defined $H;
- $H = $H;
- is $Q::H, 'good7';
- is $Q2::H, 'good8';
|