/home/.cpanm/work/1759492321.34807/Template-Toolkit-3.102/t
#============================================================= -*-perl-*- # # t/evalperl.t # # Test the evaluation of PERL and RAWPERL blocks. # # Written by Andy Wardley <abw@wardley.org> # # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. # # This is free software; you can redistribute it and/or modify it # under the same terms as Perl itself. # # $Id$ # #======================================================================== use strict; use lib qw( ./lib ../lib ); use Template::Test; $^W = 1; #$Template::Parser::DEBUG = 1; #$Template::Directive::PRETTY = 1; #$Template::Context::DEBUG = 0; my $tt_no_perl = Template->new({ INTERPOLATE => 1, POST_CHOMP => 1, EVAL_PERL => 0, INCLUDE_PATH => -d 't' ? 't/test/lib' : 'test/lib', }); my $tt_do_perl = Template->new({ INTERPOLATE => 1, POST_CHOMP => 1, EVAL_PERL => 1, INCLUDE_PATH => -d 't' ? 't/test/lib' : 'test/lib', }); my $ttprocs = [ no_perl => $tt_no_perl, do_perl => $tt_do_perl, ]; test_expect(\*DATA, $ttprocs, &callsign); __DATA__ -- test -- [% META author = 'Andy Wardley' title = 'Test Template $foo #6' version = 1.23 %] [% TRY %] [% PERL %] my $output = "author: [% template.author %]\n"; $stash->set('a', 'The cat sat on the mat'); $output .= "more perl generated output\n"; print $output; [% END %] [% CATCH %] Not allowed: [% error +%] [% END %] a: [% a +%] a: $a [% TRY %] [% RAWPERL %] $output .= "The cat sat on the mouse mat\n"; $stash->set('b', 'The cat sat where?'); [% END %] [% CATCH %] Still not allowed: [% error +%] [% END %] b: [% b +%] b: $b -- expect -- Not allowed: perl error - EVAL_PERL not set a: alpha a: alpha Still not allowed: perl error - EVAL_PERL not set b: bravo b: bravo -- test -- [% TRY %] nothing [% PERL %] We don't care about correct syntax within PERL blocks if EVAL_PERL isn't set. They're simply ignored. [% END %] [% CATCH %] ERROR: [% error.type %]: [% error.info %] [% END %] -- expect -- nothing ERROR: perl: EVAL_PERL not set -- test -- some stuff [% TRY %] [% INCLUDE badrawperl %] [% CATCH %] ERROR: [[% error.type %]] [% error.info %] [% END %] -- expect -- some stuff This is some text ERROR: [perl] EVAL_PERL not set -- test -- -- use do_perl -- some stuff [% TRY %] [% INCLUDE badrawperl %] [% CATCH +%] ERROR: [[% error.type %]] [% END %] -- expect -- some stuff This is some text more stuff goes here ERROR: [undef] -- test -- -- use do_perl -- [% META author = 'Andy Wardley' %] [% PERL %] my $output = "author: [% template.author %]\n"; $stash->set('a', 'The cat sat on the mat'); $output .= "more perl generated output\n"; print $output; [% END %] -- expect -- author: Andy Wardley more perl generated output -- test -- -- use do_perl -- [% META author = 'Andy Wardley' title = 'Test Template $foo #6' version = 3.14 %] [% PERL %] my $output = "author: [% template.author %]\n"; $stash->set('a', 'The cat sat on the mat'); $output .= "more perl generated output\n"; print $output; [% END %] a: [% a +%] a: $a [% RAWPERL %] $output .= "The cat sat on the mouse mat\n"; $stash->set('b', 'The cat sat where?'); [% END %] b: [% b +%] b: $b -- expect -- author: Andy Wardley more perl generated output a: The cat sat on the mat a: The cat sat on the mat The cat sat on the mouse mat b: The cat sat where? b: The cat sat where? -- test -- [% BLOCK foo %]This is block foo[% END %] [% PERL %] print $context->include('foo'); print PERLOUT "\nbar\n"; [% END %] The end -- expect -- This is block foo bar The end -- test -- [% TRY %] [%- PERL %] die "nothing to live for\n" [% END %] [% CATCH %] error: [% error %] [% END %] -- expect -- error: undef error - nothing to live for
.
Edit
..
Edit
README
Edit
anycase.t
Edit
args.t
Edit
assert.t
Edit
base.t
Edit
binop.t
Edit
block.t
Edit
block_duplicate.t
Edit
blocks.t
Edit
capture.t
Edit
case.t
Edit
chomp.t
Edit
compile1.t
Edit
compile2.t
Edit
compile3.t
Edit
compile4.t
Edit
compile5.t
Edit
config.t
Edit
constants.t
Edit
context.t
Edit
datafile.t
Edit
date.t
Edit
date_offset.t
Edit
date_utf8.t
Edit
debug.t
Edit
directive.t
Edit
directry.t
Edit
document.t
Edit
dumper.t
Edit
error.t
Edit
evalperl.t
Edit
exception.t
Edit
factory.t
Edit
file.t
Edit
fileline.t
Edit
filter.t
Edit
foreach.t
Edit
format.t
Edit
html.t
Edit
image.t
Edit
include.t
Edit
iterator.t
Edit
leak.t
Edit
lib
Edit
list.t
Edit
load_order_vmethods_stash.t
Edit
macro.t
Edit
math.t
Edit
math_rand.t
Edit
meta.t
Edit
mtime-zero.t
Edit
object.t
Edit
outline.t
Edit
outline_line.t
Edit
output.t
Edit
parser.t
Edit
parser2.t
Edit
plugins.t
Edit
plusfile.t
Edit
pod.t
Edit
prefix.t
Edit
proc.t
Edit
process-relative.t
Edit
process.t
Edit
process_dir.t
Edit
provider.t
Edit
ref.t
Edit
scalar.t
Edit
service.t
Edit
skel.t
Edit
stash-xs-unicode.t
Edit
stash-xs.t
Edit
stash.t
Edit
stashc.t
Edit
stop.t
Edit
strcat.t
Edit
strict.t
Edit
string.t
Edit
switch.t
Edit
table.t
Edit
tags.t
Edit
template.t
Edit
test
Edit
text.t
Edit
throw.t
Edit
tiedhash.t
Edit
trace_vars.t
Edit
try.t
Edit
unicode.t
Edit
url.t
Edit
vars.t
Edit
varsv1.t
Edit
view.t
Edit
vmethods
Edit
while.t
Edit
wrap.t
Edit
wrapper.t
Edit
zz-plugin-cycle.t
Edit
zz-plugin-leak-gh-213.t
Edit
zz-plugin-leak-rt-46691.t
Edit
zz-plugin-leak.t
Edit
zz-pmv.t
Edit
zz-pod-coverage.t
Edit
zz-pod-kwalitee.t
Edit
zz-stash-xs-leak.t
Edit
zz-url2.t
Edit