File: 20_precompile.t

package info (click to toggle)
libhtml-template-compiled-perl 0.97-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 756 kB
  • sloc: perl: 4,504; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# $Id: 20_precompile.t 952 2007-07-30 20:42:25Z tinita $
use warnings;
use strict;
use lib qw(blib/lib t);
use Test::More tests => 4;
use_ok('HTML::Template::Compiled');
use HTC_Utils qw($cache $tdir &cdir);


HTML::Template::Compiled->clear_filecache('t/cache');
{
    my $pre = 'precompiled1.tmpl';
    my $scalar = <<'EOM';
Precompiled scalarref!
EOM
    my $templates = HTML::Template::Compiled->precompile(
        path     => $tdir,
        file_cache_dir => $cache,
        file_cache => 1,
        filenames => [$pre, \$scalar],
    );
    #warn Data::Dumper->Dump([\$templates], ['templates']);
    my $out = $templates->[0]->output;
    #print "out: '$out'\n";
    my $out2 = $templates->[1]->output;
    #print "out2: '$out2'\n";
    my $exp = do {
        open my $fh, '<', File::Spec->catfile($tdir, $pre) or die $!;
        local $/;
        <$fh>;
    };
    tr/\r\n//d for $exp, $out, $out2, $scalar;
    cmp_ok(scalar @$templates, "==", 2, "precompile count");
    cmp_ok($out, "eq", $exp, "precompiled output");
    cmp_ok($out2, "eq", $scalar, "precompiled scalarref");
    #print `ls t/cache/`;

}
HTML::Template::Compiled->clear_filecache('t/cache');