1#!/usr/bin/env perl -w 2use strict; 3use warnings; 4use Test::More qw( no_plan ); 5use File::Temp qw( tempdir ); 6use constant PERL_55 => $] < 5.006; 7use constant PERL_56 => ! PERL_55 && $] < 5.007; 8use constant PERL_LEGACY => PERL_55 || PERL_56; 9use constant IS_TAINT => __PACKAGE__->can('TAINTMODE'); 10use constant TEMPLATE => q(Time now: <%=scalar localtime 1219952008 %>); 11 12use Text::Template::Simple; 13 14# ref: http://rt.cpan.org/Public/Bug/Display.html?id=45885 15for my $path ( qw( TEMP TMP ) ) { 16 last if ! IS_TAINT || ! PERL_LEGACY; 17 next if ! $ENV{ $path }; # this is just a test you know :p 18 $ENV{ $path } = $1 if $ENV{ $path } =~ m{\A (.*) \z}xms; 19} 20 21SKIP: { 22 23 #if ( PERL_LEGACY && IS_TAINT && $^O eq 'freebsd' ) { 24 # skip "This version of perl in this platform seems to have a bug in " 25 # ."it that causes failures under taint mode. See this bug report " 26 # ."for the details on this issue: " 27 # ."http://rt.cpan.org/Public/Bug/Display.html?id=45885"; 28 #} 29 30 my $TEMPDIR = tempdir( CLEANUP => PERL_LEGACY ? 0 : 1 ); 31 32 my @args = (cache => 1, cache_dir => $TEMPDIR ); 33 ok(my $t = Text::Template::Simple->new( @args ), 'object'); 34 35 ok(my $raw1 = $t->compile( TEMPLATE ), 'compile raw1'); 36 37 ok( $t->cache->has( data => TEMPLATE ), 'Run 1: Cache has DATA' ); 38 ok( $t->cache->has( id => $t->cache->id ), 'Run 1: Cache has ID' ); 39 40 ok(my $raw2 = $t->compile( TEMPLATE ), 'compile raw2'); 41 42 ok( $t->cache->has( data => TEMPLATE ), 'Run 2: Cache has DATA' ); 43 ok( $t->cache->has( id => $t->cache->id ), 'Run 2: Cache has ID' ); 44 45 ok(my $raw3 = $t->compile( TEMPLATE, 0, { id => '12_cache_disk_t', chkmt => 1 } ), 'compile raw3'); 46 47 ok( $t->cache->has( data => TEMPLATE ), 'Run 3: Cache has DATA' ); 48 ok( $t->cache->has( id => '12_cache_disk_t' ), 'Run 3: Cache has ID' ); 49 is( $t->cache->id, '12_cache_disk_t' , 'Cache ID OK' ); 50 51 is( $raw1, $raw2, 'RAW1 EQ RAW2' ); 52 is( $raw2, $raw3, 'RAW2 EQ RAW3' ); 53 54 is( $t->cache->type, 'DISK', 'Correct cache type is set' ); 55} 56