removing old trexy files
[urisagit/Template-Simple.git] / bench.pl
CommitLineData
540289da 1#!/usr/local/bin/perl
2
3use strict ;
4use warnings ;
5
6use Template::Simple ;
7use Data::Dumper ;
8
9my $data = generate_data( 3, 6 ) ;
10#print Dumper $data ;
11
12my $tmpl = Template::Simple->new() ;
13
14$tmpl->add_templates( { bench => <<TMPL } ) ;
15Header
16Val 1: [%val_1%]
17Val 2: [%val_2%]
18Footer
19TMPL
20
21my $x = <<XXX ;
22[%START nest%]
23 Level: [%level%]
24[%END nest%]
25[%START opt%]
26 Optional Level: [%level%]
27[%END opt%]
28XXX
29
30
31
32my $rendered = $tmpl->render( 'bench', $data ) ;
33
34$tmpl->compile( 'bench', $data ) ;
35print $tmpl->get_source( 'bench' ) ;
36
37my $comp_rendered = $tmpl->render( 'bench', $data ) ;
38
39my $ok = $$rendered eq $$comp_rendered ;
40
41print "OK [$ok]\n" ;
42
43print $$rendered ;
44print $$comp_rendered ;
45
46exit ;
47
48
49
50
51no warnings ;
52
53
54sub rendered {
55
56}
57
58sub map_join {
59
60}
61
62sub append {
63
64}
65
66
67sub concat {
68
69 my( $data ) = @_ ;
70
71 my $out = do {
72 my $out ;
73 foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) {
74
75 $out .= ref $data ne 'HASH' ? $data :
76 "text1\n"
77 .
78 do {
79 my $data = $data->{nest} ;
80
81 my $out ;
82 foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) {
83
84 $out .= ref $data ne 'HASH' ? $data :
85 "\n\tBAR is "
86 .
87 $data->{bar}
88 .
89 "\n" ;
90 }
91
92
93 $out ;
94 }
95 .
96 "\n" ;
97 }
98 $out ;
99 } ;
100
101 return \$out ;
102}
103
104
105sub generate_data {
106
107 my( $outer_size, $inner_size ) = @_ ;
108
109 my @outer_data ;
110
111 for my $outer ( 1 .. $outer_size ) {
112
113 my @inner_data ;
114
115 for my $inner ( 1 .. $inner_size ) {
116
117 push @inner_data, {
118
119 val_1 => ($outer x 2),
120 val_2 => ($inner x 3),
121 nest => {
122 level => "$outer-$inner",
123 },
124 $inner % 2 ? () : (
125
126 opt => {
127 level => "$outer-$inner",
128 },
129 ),
130 } ;
131 }
132
133 push @outer_data, [@inner_data] ;
134 }
135
136 return \@outer_data ;
137}