[Rt-commit] rt branch, 4.0/not-scalar-variables-in-templates, created. rt-4.0.6-256-g027bc25

Ruslan Zakirov ruz at bestpractical.com
Wed Jul 18 11:03:18 EDT 2012


The branch, 4.0/not-scalar-variables-in-templates has been created
        at  027bc25b33118df38cc15c069ffa5a81322d305c (commit)

- Log -----------------------------------------------------------------
commit 421e35d1419adc9868d6d288b2c46f862cd42e3a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jul 18 18:53:19 2012 +0400

    show how hash/array/code arguments passing fails

diff --git a/t/api/template-parsing.t b/t/api/template-parsing.t
index 4991111..455b84d 100644
--- a/t/api/template-parsing.t
+++ b/t/api/template-parsing.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 245;
+use RT::Test tests => 266;
 use Test::Warn;
 
 my $queue = RT::Queue->new(RT->SystemUser);
@@ -183,6 +183,22 @@ note "test arguments passing";
         Arguments => { Nonexistent => 'foo' },
         Output    => "test foo",
     );
+
+    PerlTemplateTest(
+        Content   => "\n".'array: { join ", ", @array }',
+        Arguments => { array => [qw(foo bar)] },
+        Output    => "array: foo, bar",
+    );
+    PerlTemplateTest(
+        Content   => "\n".'hash: { join ", ", map "$_ => $hash{$_}", sort keys %hash }',
+        Arguments => { hash => {1 => 2, a => 'b'} },
+        Output    => "hash: 1 => 2, a => b",
+    );
+    PerlTemplateTest(
+        Content   => "\n".'code: { code() }',
+        Arguments => { code => sub { "baz" } },
+        Output    => "code: baz",
+    );
 }
 
 # Make sure changing the template's type works

commit 027bc25b33118df38cc15c069ffa5a81322d305c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jul 18 18:54:57 2012 +0400

    fix passing arrays, hashes and code into templates
    
    It was always intention to make XXX => [...] arguments
    to $template->Parse method to be available in template's
    code as @XXX, but it was broken.
    
    This is a fix, not a backwards incompatible change, as we
    have GnuPG errors notification templates that rely on
    such behavior.

diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index 117cc3f..c0e99b3 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -457,7 +457,7 @@ sub _ParseContentPerl {
     foreach my $key ( keys %{ $args{TemplateArgs} } ) {
         my $val = $args{TemplateArgs}{ $key };
         next unless ref $val;
-        next if ref $val =~ /^(ARRAY|HASH|SCALAR|CODE)$/;
+        next if ref($val) =~ /^(ARRAY|HASH|SCALAR|CODE)$/;
         $args{TemplateArgs}{ $key } = \$val;
     }
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list