[Templates-cvs] cvs commit: Template2/lib/Template Stash.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/01/29 11:26:21
Modified: lib/Template Stash.pm
Log:
* fixed up split() scalar vmethod to stop generating warnings
Revision Changes Path
2.89 +20 -6 Template2/lib/Template/Stash.pm
Index: Stash.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Stash.pm,v
retrieving revision 2.88
retrieving revision 2.89
diff -u -r2.88 -r2.89
--- Stash.pm 2006/01/28 08:53:06 2.88
+++ Stash.pm 2006/01/29 11:26:21 2.89
@@ -18,7 +18,7 @@
#
#----------------------------------------------------------------------------
#
-# $Id: Stash.pm,v 2.88 2006/01/28 08:53:06 abw Exp $
+# $Id: Stash.pm,v 2.89 2006/01/29 11:26:21 abw Exp $
#
#============================================================================
@@ -29,7 +29,7 @@
use strict;
use vars qw( $VERSION $DEBUG $ROOT_OPS $SCALAR_OPS $HASH_OPS $LIST_OPS );
-$VERSION = sprintf("%d.%02d", q$Revision: 2.88 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 2.89 $ =~ /(\d+)\.(\d+)/);
#========================================================================
@@ -90,11 +90,25 @@
my @matches = ($str =~ /$search/);
return @matches ? \@matches : '';
},
- split => sub {
- my ($str, $split, @args) = @_;
+ 'split' => sub {
+ my ($str, $split, $limit) = @_;
$str = '' unless defined $str;
- return [ defined $split ? split($split, $str, $args[0])
- : split(' ', $str, $args[0]) ];
+
+ # we have to be very careful about spelling out each possible
+ # combination of arguments because split() is very sensitive
+ # to them, for example C<split(' ', ...)> behaves differently
+ # to C<$space=' '; split($space, ...)>
+
+ if (defined $limit) {
+ return [ defined $split
+ ? split($split, $str, $limit)
+ : split(' ', $str, $limit) ];
+ }
+ else {
+ return [ defined $split
+ ? split($split, $str)
+ : split(' ', $str) ];
+ }
},
'chunk' => sub {
my ($string, $size) = @_;