1#============================================================= -*-perl-*- 2# 3# t/ref.t 4# 5# Template script testing variable references. 6# 7# Written by Andy Wardley <abw@kfs.org> 8# 9# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. 10# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. 11# 12# This is free software; you can redistribute it and/or modify it 13# under the same terms as Perl itself. 14# 15# $Id$ 16# 17#======================================================================== 18 19use strict; 20use lib qw( ../lib ); 21use Template::Constants qw( :status ); 22use Template; 23use Template::Test; 24$^W = 1; 25 26#$Template::Test::DEBUG = 0; 27#$Template::Context::DEBUG = 0; 28#$Template::Parser::DEBUG = 1; 29#$Template::Directive::PRETTY= 1; 30 31local $" = ', '; 32my $replace = { 33 a => sub { return "a sub [@_]" }, 34 j => { k => 3, l => 5, m => { n => sub { "nsub [@_]" } } }, 35 z => sub { my $sub = shift; return "z called " . &$sub(10, 20, 30) }, 36}; 37 38test_expect(\*DATA, undef, $replace); 39 40__DATA__ 41-- test -- 42a: [% a %] 43a(5): [% a(5) %] 44a(5,10): [% a(5,10) %] 45-- expect -- 46a: a sub [] 47a(5): a sub [5] 48a(5,10): a sub [5, 10] 49 50-- test -- 51[% b = \a -%] 52b: [% b %] 53b(5): [% b(5) %] 54b(5,10): [% b(5,10) %] 55-- expect -- 56b: a sub [] 57b(5): a sub [5] 58b(5,10): a sub [5, 10] 59 60-- test -- 61[% c = \a(10,20) -%] 62c: [% c %] 63c(30): [% c(30) %] 64c(30,40): [% c(30,40) %] 65-- expect -- 66c: a sub [10, 20] 67c(30): a sub [10, 20, 30] 68c(30,40): a sub [10, 20, 30, 40] 69 70-- test -- 71[% z(\a) %] 72-- expect -- 73z called a sub [10, 20, 30] 74 75-- test -- 76[% f = \j.k -%] 77f: [% f %] 78-- expect -- 79f: 3 80 81-- test -- 82[% f = \j.m.n -%] 83f: [% f %] 84f(11): [% f(11) %] 85-- expect -- 86f: nsub [] 87f(11): nsub [11] 88 89 90