[Templates-cvs] cvs commit: Template2/lib/Template Stash.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/02/01 08:39:31
Modified: lib/Template Stash.pm
Log:
* added substr() scalar virtual method
* changed list.push and list.unshift to accept multiple arguments
Revision Changes Path
2.95 +22 -5 Template2/lib/Template/Stash.pm
Index: Stash.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Stash.pm,v
retrieving revision 2.94
retrieving revision 2.95
diff -u -r2.94 -r2.95
--- Stash.pm 2006/01/30 20:04:55 2.94
+++ Stash.pm 2006/02/01 08:39:31 2.95
@@ -18,7 +18,7 @@
#
#----------------------------------------------------------------------------
#
-# $Id: Stash.pm,v 2.94 2006/01/30 20:04:55 abw Exp $
+# $Id: Stash.pm,v 2.95 2006/02/01 08:39:31 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.94 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 2.95 $ =~ /(\d+)\.(\d+)/);
#========================================================================
@@ -128,7 +128,24 @@
}
return \@list;
},
-
+ 'substr' => sub {
+ my ($text, $offset, $length, $replacement) = @_;
+ $offset ||= 0;
+
+ if(defined $length) {
+ if (defined $replacement) {
+ my $removed = substr( $text, $offset, $length );
+ substr( $text, $offset, $length ) = $replacement;
+ return $removed;
+ }
+ else {
+ return substr( $text, $offset, $length );
+ }
+ }
+ else {
+ return substr( $text, $offset );
+ }
+ },
defined $SCALAR_OPS ? %$SCALAR_OPS : (),
};
@@ -190,9 +207,9 @@
no warnings;
return { @$list };
},
- 'push' => sub { my $list = shift; push(@$list, shift); return '' },
+ 'push' => sub { my $list = shift; push(@$list, @_); return '' },
'pop' => sub { my $list = shift; pop(@$list) },
- 'unshift' => sub { my $list = shift; unshift(@$list, shift); return '' },
+ 'unshift' => sub { my $list = shift; unshift(@$list, @_); return '' },
'shift' => sub { my $list = shift; shift(@$list) },
'max' => sub { local $^W = 0; my $list = shift; $#$list; },
'size' => sub { local $^W = 0; my $list = shift; $#$list + 1; },