[Templates] Unexpected errors with COMPILE_DIR and TOLERANT

[prev] [thread] [next] [Date index for 2004/12/21]

From: Simon Flack
Subject: [Templates] Unexpected errors with COMPILE_DIR and TOLERANT
Date: 16:58 on 21 Dec 2004
Hello,

I've been working on making TT2 configuration options configurable in 
Maypole. And I thought it would be possible to enable template 
compilation by default by setting COMPILE_DIR to a sensible default. But 
I'm seeing what I consider to be unexpected errors when the COMPILE_DIR 
directory isn't writable, even if the TOLERANT flag is enabled. Here's a 
small test case to demonstrate:

#!/usr/local/bin/perl -w
use strict;
use Test::More tests => 3;
use Template 2.14;

my $compile_dir = './compiled';

mkdir $compile_dir unless -e $compile_dir;
test_template(0777, $compile_dir, 'test.tt2');
unlink ($compile_dir . '/test.tt2');
test_template(0555, $compile_dir, 'test.tt2');
test_template(0555, $compile_dir, 'subdir/test.tt2');

sub test_template {
     my ($mode, $dir, $template) = @_;
     chmod $mode, $dir;

     my $output = '';
     my $tt = Template->new({COMPILE_DIR => $dir, TOLERANT => 1});
     $tt->process($template, { data => 'Hello World' }, \$output);
     like($output, qr/Hello World/,
          sprintf "template processed, compile_dir:%04o 
(template:$template)",
          $mode);
     diag($tt->error) if $tt->error;
}
__DATA__
# test.tt2 & subdir/test.tt2
[% data %]


And the output:

1..3
ok 1 - template processed, compile_dir:0777 (template:test.tt2)
not ok 2 - template processed, compile_dir:0555 (template:test.tt2)
#     Failed test (template_compile_dir.t at line 22)
#                   ''
#     doesn't match '(?-xism:Hello World)'
# file error - test.tt2: not found
not ok 3 - template processed, compile_dir:0555 (template:subdir/test.tt2)
#     Failed test (template_compile_dir.t at line 22)
#                   ''
#     doesn't match '(?-xism:Hello World)'
# mkdir compiled/subdir: Permission denied at 
/usr/local/lib/perl/5.8.4/Template/Provider.pm line 877
# Looks like you failed 2 tests of 3.

The wording of the error for the second test is a suprise - the template 
exists, it's just not able to cache the compiled version.

But I expected all three tests to pass, and for TT to silently skip the 
caching errors with TOLERANT => 1.

Am I misguided or TT doing the wrong thing here? I can provide more 
information on request.

--simonflk

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

(message missing)

[Templates] Unexpected errors with COMPILE_DIR and TOLERANT
Simon Flack 16:58 on 21 Dec 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52