Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/e0779c1ab9613153a3f9 to your computer and use it in GitHub Desktop.
Save jberger/e0779c1ab9613153a3f9 to your computer and use it in GitHub Desktop.
loop helper
use Mojolicious::Lite;
use Mojo::Collection 'c';
helper loop => sub {
my ($c, $aref, $block) = @_;
$aref = ($c->stash($aref) || []) unless ref $aref;
c(@$aref)->map($block)->join;
};
any '/' => 'index';
app->start;
__DATA__
@@ index.html.ep
%= loop [qw/a b c/] => begin
From array ref: <%= $_ %>
% end
% stash x => [qw/d e f/];
%= loop x => begin
From stash 'x': <%= $_ %>
% end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment