File: cascade.pl

package info (click to toggle)
libtext-xslate-perl 3.5.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,108 kB
  • sloc: perl: 19,756; ansic: 214; pascal: 182; makefile: 9; cs: 8
file content (77 lines) | stat: -rw-r--r-- 1,820 bytes parent folder | download | duplicates (5)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!perl -w
use strict;

use Text::Xslate;
use Text::MicroTemplate::Extended;

use Benchmark qw(:all);
use FindBin qw($Bin);
use Test::More;

use Config; printf "Perl/%vd %s\n", $^V, $Config{archname};
foreach my $mod(qw(Text::Xslate Text::MicroTemplate Text::MicroTemplate::Extended)){
    print $mod, '/', $mod->VERSION, "\n";
}

my %args = @ARGV;

my $cache = defined($args{'--cache'}) ? $args{'--cache'} : 2;

{
    package BlogEntry;
    use Mouse;
    has title => (is => 'rw');
    has body  => (is => 'rw');
}
my $n = $args{'--size'} || 2;
my @blog_entries = map{ BlogEntry->new($_) } (
    {
        title => 'Entry one',
        body  => "This is my first entry.\n" x $n,
    },
    {
        title => 'Entry two',
        body  => "This is my second entry.\n" x $n,
    },
    {
        title => 'Entry three',
        body  => "This is my thrid entry.\n" x $n,
    },
    {
        title => 'Entry four',
        body  => "This is my forth entry.\n" x $n,
    },
    {
        title => 'Entry five',
        body  => "This is my fifth entry.\n" x $n,
    },
);

my $path = "$Bin/template";

my $tx = Text::Xslate->new(
    path      => [$path],
    cache_dir =>  '.xslate_cache',
    cache     =>  $cache,
);
my $mt = Text::MicroTemplate::Extended->new(
    include_path  => [$path],
    template_args => { blog_entries => \@blog_entries },
    use_cache     => $cache,
);

{
    plan tests => 1;
    my $x = $tx->render('child.tx', { blog_entries => \@blog_entries });
    my $y = $mt->render('child');
    $x =~ s/\n//g;
    $y =~ s/\n//g;

    is $x, $y, "Xslate eq T::MT::Ex" or exit 1;
}

print "Benchmarks for template cascading\n";
cmpthese -1 => {
    MTEx => sub{ my $body = [ $mt->render('child') ] },
    TX   => sub{ my $body = [ $tx->render('child.tx', { blog_entries => \@blog_entries }) ] },
};