I'd like to add a couple of new virtual methods to Template::Stash: merge,
which takes several lists and (non-destructively) merges them into one
list, and commify, a scalar op, stolen from perlfaq 5.

  [% big_number = 187439493280; big_number.commify %]
  187,439,493,280

  [% list_one   = [ 1 2 3 4 5 ];
     list_two   = [ 6 7 8 9 10 ];
     list_three = [ a b c d e ];
     FOREACH l  = list_one.merge(list_two);
        "$l ";
     END;
  %]
  1 2 3 4 5 6 7 8 9 10 a b c d e

Opinions?

(darren)

-- 
Hell is other people.
    -- Jean-Paul Sartre
--- Stash.pm.orig       Tue Jul  9 10:42:48 2002
+++ Stash.pm    Thu Jul 18 13:56:38 2002
@@ -89,6 +89,7 @@
         return [ defined $split ? split($split, $str, @args)
                                 : split(' ', $str, @args) ];
     },
+    'commify' => \&commify,
     defined $SCALAR_OPS ? %$SCALAR_OPS : (),
 };
 
@@ -180,6 +181,12 @@
                @$list
     },
     'unique'  => sub { my %u; [ grep { ++$u{$_} == 1 } @{$_[0]} ] },
+    'merge'   => sub {
+       my $list = shift;
+       return [ @$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_ ];
+
+    },
+
     defined $LIST_OPS ? %$LIST_OPS : (),
 };
 
@@ -191,6 +198,14 @@
 }
 
 
+# stolen from perlfaq 5
+sub commify {
+    local $_  = shift;
+    1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
+    return $_;
+}
+
+
 #========================================================================
 #                      -----  CLASS METHODS -----
 #========================================================================
@@ -891,4 +906,4 @@
 
 =head1 SEE ALSO
 
-L<Template|Template>, L<Template::Context|Template::Context>
\ No newline at end of file
+L<Template|Template>, L<Template::Context|Template::Context>

Reply via email to