added bench.pl
Uri Guttman [Thu, 18 Dec 2008 18:49:46 +0000 (13:49 -0500)]
bench.pl [new file with mode: 0644]
comp.pl [new file with mode: 0644]

diff --git a/bench.pl b/bench.pl
new file mode 100644 (file)
index 0000000..2583947
--- /dev/null
+++ b/bench.pl
@@ -0,0 +1,137 @@
+#!/usr/local/bin/perl
+
+use strict ;
+use warnings ;
+
+use Template::Simple ;
+use Data::Dumper ;
+
+my $data = generate_data( 3, 6 ) ;
+#print Dumper $data ;
+
+my $tmpl = Template::Simple->new() ;
+
+$tmpl->add_templates( { bench => <<TMPL } ) ;
+Header
+Val 1: [%val_1%]
+Val 2: [%val_2%]
+Footer
+TMPL
+
+my $x = <<XXX ;
+[%START nest%]
+       Level: [%level%]
+[%END nest%]
+[%START opt%]
+       Optional Level: [%level%]
+[%END opt%]
+XXX
+
+
+
+my $rendered = $tmpl->render( 'bench', $data ) ;
+
+$tmpl->compile( 'bench', $data ) ;
+print $tmpl->get_source( 'bench' ) ;
+
+my $comp_rendered = $tmpl->render( 'bench', $data ) ;
+
+my $ok = $$rendered eq $$comp_rendered ;
+
+print "OK [$ok]\n" ;
+
+print $$rendered ;
+print $$comp_rendered ;
+
+exit ;
+
+
+
+
+no warnings ;
+
+
+sub rendered {
+
+}
+
+sub map_join {
+
+}
+
+sub append {
+
+}
+
+
+sub concat {
+
+       my( $data ) = @_ ;
+
+       my $out = do {
+               my $out ;
+               foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) {
+
+                       $out .= ref $data ne 'HASH' ? $data :
+                       "text1\n"
+                       .
+                       do {
+                               my $data = $data->{nest} ;
+
+                               my $out ;
+                               foreach my $data ( ref $data eq 'ARRAY' ? @{$data} : $data ) {
+
+                                       $out .= ref $data ne 'HASH' ? $data :
+                                       "\n\tBAR is "
+                                       .
+                                       $data->{bar}
+                                       .
+                                       "\n" ;
+                               }
+
+
+                               $out ;
+                       }
+                       .
+                       "\n" ;
+               }
+               $out ;
+       } ;
+
+       return \$out ;
+}
+
+
+sub generate_data {
+
+       my( $outer_size, $inner_size ) = @_ ;
+
+       my @outer_data ;
+
+       for my $outer ( 1 .. $outer_size ) {
+
+               my @inner_data ;
+
+               for my $inner ( 1 .. $inner_size ) {
+
+                       push @inner_data, {
+
+                               val_1   => ($outer x 2),
+                               val_2   => ($inner x 3),
+                               nest    => {
+                                       level => "$outer-$inner",
+                               },
+                               $inner % 2 ? () : (
+                       
+                                       opt     => {
+                                               level => "$outer-$inner",
+                                       },
+                               ),
+                       } ;
+               }
+
+               push @outer_data, [@inner_data] ;
+       }
+
+       return \@outer_data ;
+}
diff --git a/comp.pl b/comp.pl
new file mode 100644 (file)
index 0000000..c1281c0
--- /dev/null
+++ b/comp.pl
@@ -0,0 +1,51 @@
+#!/usr/local/bin/perl
+
+use strict ;
+use warnings ;
+
+use Template::Simple ;
+
+my $tmpl = Template::Simple->new() ;
+
+$tmpl->add_templates( { ddd => <<DDD } ) ;
+text1
+[%START nest%]
+       BAR is [%bar%]
+[%END nest%]
+DDD
+
+my %data = (
+       ddd     => [
+               {
+                       nest    => {
+                               bar => 'xxx',
+                       },
+               },
+               {
+                       nest    => {
+                               bar => 'yyy',
+                       },
+               },
+               {
+                       nest    => {
+                               bar => 'zzz',
+                       },
+               },
+       ],
+) ;
+
+$tmpl->compile('foo') ;
+#$tmpl->compile('fooz') ;
+
+#my $rendered = $tmpl->render('foo', { foo => 2, bar => 'xxx' } ) ;
+
+#print "REND [$$rendered]\n" ;
+
+$tmpl->compile('ddd') ;
+my $rendered = $tmpl->render( 'ddd', $data{ddd} ) ;
+
+print "REND [$$rendered]\n" ;
+
+print $tmpl->get_source( 'ddd' ) ;
+
+exit ;