Commit | Line | Data |
540289da |
1 | #!/usr/local/bin/perl |
2 | |
3 | use strict ; |
4 | use warnings ; |
5 | |
6 | use Template::Simple ; |
7 | use Data::Dumper ; |
8 | |
9 | my $data = generate_data( 3, 6 ) ; |
10 | #print Dumper $data ; |
11 | |
12 | my $tmpl = Template::Simple->new() ; |
13 | |
14 | $tmpl->add_templates( { bench => <<TMPL } ) ; |
15 | Header |
16 | Val 1: [%val_1%] |
17 | Val 2: [%val_2%] |
18 | Footer |
19 | TMPL |
20 | |
21 | my $x = <<XXX ; |
22 | [%START nest%] |
23 | Level: [%level%] |
24 | [%END nest%] |
25 | [%START opt%] |
26 | Optional Level: [%level%] |
27 | [%END opt%] |
28 | XXX |
29 | |
30 | |
31 | |
32 | my $rendered = $tmpl->render( 'bench', $data ) ; |
33 | |
34 | $tmpl->compile( 'bench', $data ) ; |
35 | print $tmpl->get_source( 'bench' ) ; |
36 | |
37 | my $comp_rendered = $tmpl->render( 'bench', $data ) ; |
38 | |
39 | my $ok = $$rendered eq $$comp_rendered ; |
40 | |
41 | print "OK [$ok]\n" ; |
42 | |
43 | print $$rendered ; |
44 | print $$comp_rendered ; |
45 | |
46 | exit ; |
47 | |
48 | |
49 | |
50 | |
51 | no warnings ; |
52 | |
53 | |
54 | sub rendered { |
55 | |
56 | } |
57 | |
58 | sub map_join { |
59 | |
60 | } |
61 | |
62 | sub append { |
63 | |
64 | } |
65 | |
66 | |
67 | sub 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 | |
105 | sub 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 | } |