Here's a patch that sets TMPL_PATH using the HTML::Template path option
rather than prepending it using a string.  This removes the restriction
that all paths must end in $ENV{IFS}.  Also, it allows the TMPL_PATH
setting to coexist with other potential search paths for templates
(i.e. $ENV{HTML_TEMPLATE_ROOT} and any path settings provided to
load_tmpl()).

I don't think this will break any existing code but it does constitute a
change in functionality.  Can anyone think of a case where this would be
the wrong behavior?

The patch can be applied with "patch -p1 < path.diff" in the
CGI-Application directory.

-sam

diff -Naur CGI-Application-2.3/Application.pm CGI-Application-2.3.new/Application.pm
--- CGI-Application-2.3/Application.pm  Mon May  6 07:15:35 2002
+++ CGI-Application-2.3.new/Application.pm      Mon May  6 15:31:29 2002
@@ -306,10 +306,23 @@
        my $self = shift;
        my ($tmpl_file, @extra_params) = @_;
 
-       my $fq_tmpl_file = $self->tmpl_path() . $tmpl_file;
+       # add tmpl_path to path array of one is set, otherwise add a path arg
+       if (my $tmpl_path = $self->tmpl_path) {
+               my $found = 0;
+               for( my $x = 0; $x < @extra_params; $x += 2 ) {
+                       if ($extra_params[$x] eq 'path' and 
+                           ref $extra_params[$x+1]     and
+                           ref $extra_params[$x+1] eq 'ARRAY') {
+                               unshift @{$extra_params[$x+1]}, $tmpl_path;
+                               $found = 1;
+                               last;
+                       }
+               }
+           push(@extra_params, path => [ $tmpl_path ]) unless $found;
+       }
 
        require HTML::Template;
-       my $t = HTML::Template->new_file($fq_tmpl_file, @extra_params);
+       my $t = HTML::Template->new_file($tmpl_file, @extra_params);
 
        return $t;
 }
@@ -773,12 +786,11 @@
 
 This method may take some specific parameters:
 
-TMPL_PATH     - This optional parameter adds value to the load_tmpl() 
-method (specified below).  This sets a path which is prepended to 
-all the filenames specified when you call load_tmpl() to get your 
-HTML::Template object.  This run-time parameter allows you to 
-further encapsulate instantiating templates, providing potential 
-for more reusability.
+TMPL_PATH - This optional parameter adds value to the load_tmpl()
+method (specified below).  This sets a path using HTML::Template's
+C<path> option when you call load_tmpl() to get your HTML::Template
+object.  This run-time parameter allows you to further encapsulate
+instantiating templates, providing potential for more reusability.
 
 PARAMS        - This parameter, if used, allows you to set a number 
 of custom parameters at run-time.  By passing in different 
@@ -1020,9 +1032,9 @@
 is used for create the object.  Refer to L<HTML::Template> for specific usage
 of HTML::Template.
 
-If tmpl_path() has been specified, load_tmpl() will prepend the tmpl_path()
-property to the filename provided.  This further assists in encapsulating 
-template usage.
+If tmpl_path() has been specified, load_tmpl() will set the
+HTML::Template C<path> option to the path provided.  This further
+assists in encapsulating template usage.
 
 The load_tmpl() method will pass any extra paramaters sent to it directly to 
 HTML::Template->new_file().  This will allow the HTML::Template object to be 
@@ -1224,14 +1236,9 @@
 
     $webapp->tmpl_path('/path/to/some/templates/');
 
-This access/mutator method sets the file path to the directory where the templates 
-are stored.  It is used by load_tmpl() to find the template files.
-
-It is important to make sure your tmpl_path() ends with your operating system's
-directory delimiter ('/' for UNIX, '\' for windows, ':' for Macintosh, etc).  The 
-load_tmpl() method does not try to make sense of the various OS particularities -- 
-it simply prepends tmpl_path() to the file name passed to load_tmpl().
-
+This access/mutator method sets the file path to the directory where
+the templates are stored.  It is used by load_tmpl() to find the
+template files, using HTML::Template's C<path> option.
 
 =back
 
diff -Naur CGI-Application-2.3/t/01cgiapp.t CGI-Application-2.3.new/t/01cgiapp.t
--- CGI-Application-2.3/t/01cgiapp.t    Mon May  6 07:52:13 2002
+++ CGI-Application-2.3.new/t/01cgiapp.t        Mon May  6 15:26:23 2002
@@ -7,7 +7,7 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 
-BEGIN { $| = 1; print "1..20\n"; }
+BEGIN { $| = 1; print "1..21\n"; }
 END {print "not ok 1\n" unless $loaded;}
 use CGI::Application;
 $loaded = 1;
@@ -430,6 +430,16 @@
 }
 
 
-
+# Test 21: test use of TMPL_PATH without trailing slash
+{
+       my $t21_ta_obj = TestApp->new(TMPL_PATH=>'test/templates');
+       $t21_ta_obj->query(CGI->new({'test_rm' => 'tmpl_badparam_test'}));
+       my $t21_output = $t21_ta_obj->run();
+       if (($t21_output =~ /^Content\-Type\:\ text\/html/) && ($t21_output =~ 
+/\-\-\-\-\>Hello\ World\:\ tmpl\_badparam\_test\<\-\-\-\-/)) {
+               print "ok 21\n";
+       } else {
+               print "not ok 21\n";
+       }
+}
 
 # All done!
---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to