Last active
August 29, 2015 14:27
-
-
Save jberger/e0779c1ab9613153a3f9 to your computer and use it in GitHub Desktop.
loop helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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