I have since modified this fix to be:
-------------------------------
$Template::Stash::SCALAR_OPS->{ split } =
sub {
my ($str, $split, @args) = @_;
$str = '' unless defined $str;
return [ defined $split ? split($split, $str, $args[0] || 0)
: split(' ', $str, $args[0] || 0) ];
};
-------------------------------
This gets rid of an unitialized value warning.
It'd probably be better to just use:
-------------------------------
$Template::Stash::SCALAR_OPS->{ split } =
sub {
my ($str, $split, $limit) = @_;
$str = '' unless defined $str;
return [ defined $split ? split($split, $str, $limit || 0)
: split(' ', $str, $limit || 0) ];
};
-------------------------------
My guess is that the original intention of using the array was to future-proof
the split vmethod, however, there appears to be no use for it now since it
doesn't work correctly.
-- Josh
Josh Rosenbaum wrote:
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
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates