[Templates] Template::Service Bug?

Jason Galea j@eightdegrees.com.au
Mon, 28 Apr 2003 15:16:47 +1000


This is a multi-part message in MIME format.
--------------080401090506040905010402
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

First up - Template Toolkit: luv it, luv, luv it!

Second - this is my first ever bug report, so I've tried to include 
everything I think is relevant. If I've overlooked or missed anything please 
let me know.

The problem arises with the way I've implemented my config for the creation 
of the template object, so maybe there is a reason I shouldn't be doing this, 
if so, again, please let me know.

Below is a test script which replicates the problem usage and useage that 
works as it should and the patch I came up with that fixes the problem for 
me. I'm pretty sure the patch could be cleaned up somewhat also, but I've 
decided to stop mucking around with it while it's working. 8)

cheers,

J


file: test.tt2
-----------------
Target Template
-----------------

file: test2.tt2
-----------------
Shell Template

[% PROCESS $template %]
-----------------

file: template.t
-----------------
#!/usr/bin/perl

use warnings;
use strict;
use Test::More tests => 13;
BEGIN { use_ok('Template'); }

my ($output,$config,$template);

# PROCESS not set at all - works ok with orig & patched
undef $output;
ok($template = Template->new(), 'create template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS not set');

# PROCESS set - works ok with orig & patched
undef $output;
$config = { Process => 'test2.tt2' };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create 
template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set');

# PROCESS set but empty - works ok with patched
undef $output;
$config = { Process => '' };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create 
template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set but empty');

# PROCESS set but undef - works ok with patched
undef $output;
$config = { };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create 
template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set but undef');
----------------

file: service.patch
----------------
--- Service.pm	Mon Apr 28 12:43:06 2003
+++ Service_patched.pm	Mon Apr 28 12:43:55 2003
@@ -86,7 +86,8 @@

  	# PROCESS
  	eval {
-	    foreach $name (@{ $self->{ PROCESS } || [ $template ] }) {
+	    my @process = @{ $self->{ PROCESS } || [] } ? @{ $self->{ PROCESS } } : 
$template;
+	    foreach $name ( @process ) {
  		$procout .= $context->process($name);
  	    }
  	};
----------------

--------------080401090506040905010402
Content-Type: text/plain;
 name="service.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="service.patch"

--- Service.pm	Mon Apr 28 12:43:06 2003
+++ Service_patched.pm	Mon Apr 28 12:43:55 2003
@@ -86,7 +86,8 @@
 
 	# PROCESS
 	eval {
-	    foreach $name (@{ $self->{ PROCESS } || [ $template ] }) {
+	    my @process = @{ $self->{ PROCESS } || [] } ? @{ $self->{ PROCESS } } : $template;
+	    foreach $name ( @process ) {
 		$procout .= $context->process($name);
 	    }
 	};

--------------080401090506040905010402
Content-Type: application/x-troff;
 name="template.t"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="template.t"

#!/usr/bin/perl

use warnings;
use strict;
use Test::More tests => 13;
BEGIN { use_ok('Template'); }

my ($output,$config,$template);

# PROCESS not set at all - works ok with orig & patched
undef $output;
ok($template = Template->new(), 'create template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS not set');

# PROCESS set - works ok with orig & patched
undef $output;
$config = { Process => 'test2.tt2' };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set');

# PROCESS set but empty - works ok with patched
undef $output;
$config = { Process => '' };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set but empty');

# PROCESS set but undef - works ok with patched
undef $output;
$config = { };
ok($template = Template->new({ PROCESS => $config->{Process} }), 'create template object');
ok($template->process( 'test.tt2', $config, \$output ),'Process template');
ok($output, 'PROCESS set but undef');


--------------080401090506040905010402
Content-Type: text/plain;
 name="test.tt2"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="test.tt2"


Target Template

--------------080401090506040905010402
Content-Type: text/plain;
 name="test2.tt2"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="test2.tt2"

Shell Template

[% PROCESS $template %]

--------------080401090506040905010402--