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

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Thu Jul  5 12:13:38 2007
New Revision: 9702

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

Log:
allow for multiple directories to be used in a template search path

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 Jul  5 12:13:38 2007
@@ -194,23 +194,32 @@
     my $theme = $context->get_user_option("theme");
     my $options = $context->{options};
 
-    my ($template_dir, $template_text);
+    my ($template_dir, $template_text, $template_file);
     local(*App::FILE);
     $template_dir = $self->{template_dir} || $options->{template_dir} || "$options->{prefix}/templates";
 
-    if ($theme && open(App::FILE,"< $template_dir/$theme/$template")) {
-        local($/) = undef;
-        $template_text = <App::FILE>;
-        close(App::FILE);
+    # check if already an array ref, may not need to split.
+    my @template_dir = (ref($template_dir) eq "ARRAY") ? @$template_dir : split(/[,; ]+/, $template_dir);
+
+    foreach my $dir (@template_dir) {
+        if (-e "$dir/$theme/$template") {
+            $template_file = "$dir/$theme/$template";
+            last;
+        }
+        elsif (-e "$dir/$template") {
+            $template_file = "$dir/$template";
+            last;
+        }
     }
-    elsif (open(App::FILE,"< $template_dir/$template")) {
+
+    if ($template_file) {
+        open(App::FILE,"< $template_file");
         local($/) = undef;
         $template_text = <App::FILE>;
         close(App::FILE);
-    }
-    else {
+    } else {
         # maybe we should throw an exception here
-        $template_text = "Template [$template_dir/$template] not found.";
+        $template_text = "Template [$template] not found in [$template_dir].";
     }
 
     &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.