1#============================================================= -*-perl-*- 2# 3# t/block.t 4# 5# Template script testing BLOCK definitions. A BLOCK defined in a 6# template incorporated via INCLUDE should not be visible (i.e. 7# exported) to the calling template. In the same case for PROCESS, 8# the block should become visible. 9# 10# Written by Andy Wardley <abw@kfs.org> 11# 12# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. 13# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. 14# 15# This is free software; you can redistribute it and/or modify it 16# under the same terms as Perl itself. 17# 18# $Id$ 19# 20#======================================================================== 21 22use strict; 23use lib qw( ./lib ../lib ); 24use Template::Test; 25$^W = 1; 26 27$Template::Test::DEBUG = 0; 28#$Template::Parser::DEBUG = 1; 29#$Template::Directive::PRETTY = 1; 30 31my $ttcfg = { 32 INCLUDE_PATH => [ qw( t/test/lib test/lib ) ], 33 POST_CHOMP => 1, 34 BLOCKS => { 35 header => '<html><head><title>[% title %]</title></head><body>', 36 footer => '</body></html>', 37 block_a => sub { return 'this is block a' }, 38 block_b => sub { return 'this is block b' }, 39 }, 40}; 41 42test_expect(\*DATA, $ttcfg, &callsign); 43 44__DATA__ 45 46-- test -- 47[% BLOCK block1 %] 48This is the original block1 49[% END %] 50[% INCLUDE block1 %] 51[% INCLUDE blockdef %] 52[% INCLUDE block1 %] 53 54-- expect -- 55This is the original block1 56start of blockdef 57end of blockdef 58This is the original block1 59 60-- test -- 61[% BLOCK block1 %] 62This is the original block1 63[% END %] 64[% INCLUDE block1 %] 65[% PROCESS blockdef %] 66[% INCLUDE block1 %] 67 68-- expect -- 69This is the original block1 70start of blockdef 71end of blockdef 72This is block 1, defined in blockdef, a is alpha 73 74-- test -- 75[% INCLUDE block_a +%] 76[% INCLUDE block_b %] 77-- expect -- 78this is block a 79this is block b 80 81-- test -- 82[% INCLUDE header 83 title = 'A New Beginning' 84+%] 85A long time ago in a galaxy far, far away... 86[% PROCESS footer %] 87 88-- expect -- 89<html><head><title>A New Beginning</title></head><body> 90A long time ago in a galaxy far, far away... 91</body></html> 92 93-- test -- 94[% BLOCK foo:bar %] 95blah 96[% END %] 97[% PROCESS foo:bar %] 98-- expect -- 99blah 100 101-- test -- 102[% BLOCK 'hello html' -%] 103Hello World! 104[% END -%] 105[% PROCESS 'hello html' %] 106-- expect -- 107Hello World! 108 109-- test -- 110<[% INCLUDE foo %]> 111[% BLOCK foo %][% END %] 112-- expect -- 113<> 114 115-- stop -- 116# these test the experimental BLOCK args feature which will hopefully allow 117# parser/eval options to be set for different blocks 118 119-- test -- 120[% BLOCK foo eval_perl=0 tags="star" -%] 121This is the foo block 122[% END -%] 123foo: [% INCLUDE foo %] 124-- expect -- 125foo: This is the foo block 126 127-- test -- 128[% BLOCK eval_perl=0 tags="star" -%] 129This is an anonymous block 130[% END -%] 131-- expect -- 132This is an anonymous block 133 134