Here is a mini-cgi to show how to install it into the Template list operations.
use strict;
use CGI qw( header start_html );
use Template;
use List::Util;
$Template::Stash::LIST_OPS->{shuffle} =
sub {
List::Util::shuffle @{ +shift || [] };
};
my $tt2 = Template->new();
print
header(),
start_html(-title => "Template::Toolkit Shuffle");
my @cards = ( 2 .. 10, qw( A K Q J ) );
my @deck;
for my $suit ( qw( S H C D ) ) {
push @deck, map { "$_$suit" } @cards;
}
$tt2->process(\*DATA, { deck => \@deck })
or warn $Template::ERROR;
__DATA__
<h1>Template::Toolkit Shuffle</h1>
[% FOR i IN deck.shuffle %]
[% i %]
[% '<br />' UNLESS loop.count % 5 %]
[% END %]