On 2011-09-14 03:39:07, SREZIC wrote:
Show quoted text> The perl core functions rand and srand may be called without arguments.
> When using the same functions without arguments in the TT2 plugin Math,
> a warning may appear.
[...]
Attached a patch to fix the problem, together with a new test script
(the test case did not fit in the existing t/math.t).
Regards,
Slaven
diff --git c/MANIFEST w/MANIFEST
index ea00da1..1d2177b 100644
--- c/MANIFEST
+++ w/MANIFEST
@@ -126,6 +126,7 @@ t/lib/Template/Plugin/Simple.pm
t/list.t
t/macro.t
t/math.t
+t/math2.t
t/object.t
t/output.t
t/parser.t
diff --git c/lib/Template/Plugin/Math.pm w/lib/Template/Plugin/Math.pm
index ff40004..5482e91 100644
--- c/lib/Template/Plugin/Math.pm
+++ w/lib/Template/Plugin/Math.pm
@@ -52,10 +52,10 @@ sub hex { shift; CORE::hex($_[0]); }
sub int { shift; CORE::int($_[0]); }
sub log { shift; CORE::log($_[0]); }
sub oct { shift; CORE::oct($_[0]); }
-sub rand { shift; CORE::rand($_[0]); }
+sub rand { shift; @_ ? CORE::rand($_[0]) : CORE::rand(); }
sub sin { shift; CORE::sin($_[0]); }
sub sqrt { shift; CORE::sqrt($_[0]); }
-sub srand { shift; CORE::srand($_[0]); }
+sub srand { shift; @_ ? CORE::srand($_[0]) : CORE::srand(); }
# Use the Math::TrulyRandom module
# XXX This is *sloooooooowwwwwwww*
diff --git c/t/math2.t w/t/math2.t
new file mode 100644
index 0000000..9d7bfa4
--- /dev/null
+++ w/t/math2.t
@@ -0,0 +1,19 @@
+use strict;
+use Test::More;
+use Template;
+
+plan tests => 1;
+
+my @warnings;
+local $SIG{__WARN__} = sub { push @warnings, @_ };
+my $t = Template->new;
+my $out;
+$t->process(\<<EOF, {}, \$out) or die $t->error;
+[% USE Math -%]
+rand with arg: [% Math.rand(1000000) %]
+rand without arg: [% Math.rand %]
+srand with arg: [% Math.srand(1000000) %]
+srand without arg: [% Math.srand %]
+EOF
+#diag $out;
+is_deeply \@warnings, [], 'No warnings when calling rand/srand without arg';