--

Oh, that didn't work. How do you downvote an email?

But seriously. Consciously done or not, this is trolling, Konrad. If  
you don't like it, don't use it and don't participate in the  
community expecting favorable results. If you really think you have  
something better, package it up and release it on the CPAN and let  
the end-users decide.

-Ashley

PS: many, maybe even most, Perl hackers write their own templating  
systems early in the game. It's sort of a right of passage, I guess.  
And like the Zen stories, if you write just one, you aren't serious  
enough but if you write more than three you'll never be able to  
achieve enlightenment.

On Jun 21, 2008, at 1:02 PM, Konrad Eisele wrote:

> Hi,
> Searching for template libraries I found some examples in the net.  
> Including
> the template toolkit library. When thinking about it I came up with  
> a own version that I'd
> like to post here. Instead of creating a own language on top of  
> perl my version is a transformation
> into perl. Creating a function that is then evaled into the current  
> namespace. The template
> creating is therefore a simple function call. The syntax elements  
> are :
>
> {* ... perl code *}  => copy as is
> [* ... perl subblock *}  => $out .= &{sub {... }}();
> {* ... perl forloop start *-}  ...  {-* ... forloop end  ... *} =>  
> transformed into a loop (real code yourself)
>
> All other parts are transformed into a $out .= "..."; At the end  
> $out is the functions return.
>
> I'd like to ask: isnt everything else too much. All the library  
> overhead you get
> with all the different template libraries. There seem to exist even  
> a "template toolkit
> book"! I never understood the sense of some computer books anyway.  
> It's such a waste
> of paper. Especially the 900 pages "Windows for Experts" books...  
> O'Reilly is making a
> fortune with polluting the enviroment.
>
> -- Greetings Konrad
>
> --------------- template.pl ----------------
>
> $RE_template_b_squarebrackets =    qr'(?:[\[]((?:(?>[^\[\]]+)|(?? 
> {$RE_template_b_squarebrackets}))*)[\]])';
> $RE_template_balanced_squarebrackets =    qr'(?:\[\*((?:(?>(?:(?:(?! 
> \[\*)(?!\*\])[\s\S]))+)|(??{$RE_template_balanced_squarebrackets})) 
> *)\*\])';
> $RE_template_balanced_brackets       =    qr'(?:\{\*((?:(?>(?:(?:(?! 
> \{\*)(?!\*\})[\s\S]))+)|(??{$RE_template_balanced_brackets}))*)\*\})';
> $RE_template_balanced_brackets_inner =    qr'(?:\*-\}((?:(?>(?:(?: 
> (?!\{-\*)(?!\*-\})[\s\S]))+)|(?? 
> {$RE_template_balanced_brackets_inner}))*)\{-\*)';
>
>  $a = "x
>       {
>       {* my [EMAIL PROTECTED] = (1,2,3);
>             foreach my \$a ([EMAIL PROTECTED]) {  *-}  y [* \$a *]  {-*  }  *}
>       }
>  ";
>
>  print (convert_template('::func',$a));
>  eval(convert_template('::func',$a));
>  print $@ if ($@);
>
>  print "'".func()."'";
>
>
>
> sub convert_template {
>     my ($n,$a) = @_;
>     my $c = "";
>     while(length($a)) {
>         if ($a =~ /^$RE_template_balanced_squarebrackets/s ) {
>             my ($all,$b) = ($&,$1);
>             print ("Found '$all'\n");
>             $a = substr($a,length($all));
>             $c .= "\$out .= &{sub { $b }}();\n";
>         } elsif ($a =~ /^$RE_template_balanced_brackets/s ) {
>             my ($all,$b) = ($&,$1);
>             print ("Found '$all'\n");
>             $a = substr($a,length($all));
>             if ($b =~ /$RE_template_balanced_brackets_inner/) {
>                 my ($pre,$b2,$post) = ($`,$1,substr($b,length($`. 
> $&)));
>                 $c .= "my [EMAIL PROTECTED] = (); $pre";
>                 $c .= "push([EMAIL PROTECTED],&{".convert_template('',$b2)."} 
> ([EMAIL PROTECTED]));\n";
>                 $c .= $post;
>                 $c .= "\$out .= join_template(\$out,[EMAIL PROTECTED]);\n";
>                 $a =~ s/^\s*\n//;
>             } else {
>                 $c .= $b;
>             }
>         } elsif ($a =~ /^.+?(?=\{\*|\[\*|$)/s)  {
>             my ($all,$b) = ($&,$1);
>             print ("Found '$all'\n");
>             $a = substr($a,length($all));
>             $c .= "\$out .= \"$all\";\n";
>         } else {
>             die("Cant decode '$a'");
>         }
>     }
>     return "sub $n { my (\$out,\$self) = ('',[EMAIL PROTECTED]); $c; return \ 
> $out; }";
> }
>
> sub join_template {
>     my ($out,@a) = @_;
>     my $post = 0;
>     $post = length($1) if ($out =~ /([^\n]*)$/);
>     $pre = sprintf('%*s',$post,"");
>     my $c = join("\n", map { $_=~ s/^\s*\n//; $_=~ s/\s*\n\s*$//;  
> $_ } @a);
>     $c .= "\n" if (scalar(@a));
>     return $c;
> }
>
> -- 
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates


_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to