[svn:p5ee] r6829 - p5ee/trunk/App-Widget/lib/App

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Thu Aug 31 09:39:39 2006
New Revision: 6829

Modified:
   p5ee/trunk/App-Widget/lib/App/TemplateEngine.pm

Log:
do the {xyz} subs before the [%xyz%] subs. strict disallows {xyz} syntax

Modified: p5ee/trunk/App-Widget/lib/App/TemplateEngine.pm
==============================================================================
--- p5ee/trunk/App-Widget/lib/App/TemplateEngine.pm	(original)
+++ p5ee/trunk/App-Widget/lib/App/TemplateEngine.pm	Thu Aug 31 09:39:39 2006
@@ -281,28 +281,31 @@
     $values = {} if (! defined $values);
     my $options = $context->{options};
 
-    while ( $template_text =~ /\[%(\+?)([^%]+)%\]/ ) {  # vars of the form [%var%] or [%+var%]
-        $expand = $1;
-        $var    = $2;
-        if ($expand) {
-            eval {
-                $value = $context->widget($var)->html();
-            };
-            $value = "[$var: $@]" if ($@);
-        }
-        elsif (defined $values->{$var}) {
-            $value = $values->{$var};
-        }
-        elsif (defined $options->{$var}) {
-            $value = $options->{$var};
-        }
-        else {
-            $value = "";
+    # strict syntax usage is [%var%] rather than {var} which can get you in trouble
+    if (! $self->{strict}) {
+        while ( $template_text =~ /\{(\+?)([a-zA-Z][a-zA-Z0-9_.-]*)\}/ ) {  # vars of the form {var} or {+var}
+            $expand = $1;
+            $var    = $2;
+            if ($expand) {
+                eval {
+                    $value = $context->widget($var)->html();
+                };
+                $value = "[$var: $@]" if ($@);
+            }
+            elsif (defined $values->{$var}) {
+                $value = $values->{$var};
+            }
+            elsif (defined $options->{$var}) {
+                $value = $options->{$var};
+            }
+            else {
+                $value = "";
+            }
+            $template_text =~ s/\{$var\}/$value/g;
         }
-        $template_text =~ s/\[%\+$var%\]/$value/g;
     }
 
-    while ( $template_text =~ /\{(\+?)([a-zA-Z][a-zA-Z0-9_.-]*)\}/ ) {  # vars of the form {var} or {+var}
+    while ( $template_text =~ /\[%(\+?)([^%]+)%\]/ ) {  # vars of the form [%var%] or [%+var%]
         $expand = $1;
         $var    = $2;
         if ($expand) {
@@ -320,7 +323,7 @@
         else {
             $value = "";
         }
-        $template_text =~ s/\{$var\}/$value/g;
+        $template_text =~ s/\[%\+$var%\]/$value/g;
     }
 
     &App::sub_exit($template_text) if ($App::trace);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.