[Templates] BUG: split virtual method does not work correctly with args
Josh Rosenbaum
josh@infogears.com
Fri, 21 Oct 2005 12:12:20 -0600
Here is the standard split virtual method. It appears that @args is getting evaluated in scalar context, because I cannot use the limit argument:
'split' => sub {
my ($str, $split, @args) = @_;
$str = '' unless defined $str;
return [ defined $split ? split($split, $str, @args)
: split(' ', $str, @args) ];
},
Here is my fixed version that DOES work. I just changed the @args to be $args[0]:
$Template::Stash::SCALAR_OPS->{ split2 } =
sub {
my ($str, $split, @args) = @_;
$str = '' unless defined $str;
return [ defined $split ? split($split, $str, $args[0])
: split(' ', $str, $args[0]) ];
};
Perl v5.8.7
Template Toolkit version 2.14
-- Josh