1#============================================================= -*-perl-*-
2#
3# t/compile4.t
4#
5# Test the facility for the Template::Provider to maintain a persistance
6# cache of compiled templates by writing generated Perl code to files.
7# This is similar to compile1.t but defines COMPILE_DIR as well as
8# COMPILE_EXT.
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;
25use Cwd qw( abs_path );
26use File::Path;
27$^W = 1;
28
29# declare extra tests to follow test_expect();
30#$Template::Test::EXTRA = 2;
31
32# script may be being run in distribution root or 't' directory
33my @dir   = -d 't' ? qw(t test) : qw(test);
34my $dir   = abs_path( File::Spec->catfile(@dir) );
35my $tdir  = abs_path( File::Spec->catfile(@dir, 'tmp'));
36my $cdir  = File::Spec->catfile($tdir, 'cache');
37my $zero  = File::Spec->catfile($dir, qw(src divisionbyzero));
38my $ttcfg = {
39    POST_CHOMP   => 1,
40    INCLUDE_PATH => "$dir/src",
41    COMPILE_DIR  => $cdir,
42    COMPILE_EXT  => '.ttc',
43    ABSOLUTE     => 1,
44    CONSTANTS    => {
45      dir  => $dir,
46      zero => $zero,
47    },
48};
49
50# delete any existing cache files
51rmtree($cdir) if -d $cdir;
52mkpath($cdir);
53
54test_expect(\*DATA, $ttcfg, { root => abs_path($dir) } );
55
56
57__DATA__
58-- test --
59[% TRY %]
60[% INCLUDE foo %]
61[% CATCH file %]
62Error: [% error.type %] - [% error.info %]
63[% END %]
64-- expect --
65This is the foo file, a is 
66
67-- test --
68[% META author => 'abw' version => 3.14 %]
69[% INCLUDE complex %]
70-- expect --
71This is the header, title: Yet Another Template Test
72This is a more complex file which includes some BLOCK definitions
73This is the footer, author: abw, version: 3.14
74- 3 - 2 - 1 
75
76-- test --
77[% TRY %]
78[% INCLUDE bar/baz word = 'wibble' %]
79[% CATCH file %]
80Error: [% error.type %] - [% error.info %]
81[% END %]
82-- expect --
83This is file baz
84The word is 'wibble'
85
86-- test --
87[% INCLUDE "$root/src/blam" %]
88-- expect --
89This is the blam file
90-- test --
91[%- # first pass, writes the compiled code to cache -%]
92[% INCLUDE divisionbyzero -%]
93-- expect --
94-- process --
95undef error - Illegal division by zero at [% constants.zero %] line 1.
96