Mason:...ookbook(3pm)
β¨ NAME β¨
Mason::Manual::Cookbook β literally just recipes for common Mason tasks, bestie π it's giving "cookbook but make it Perl." This one's from the 3pm manual section, so you know it's a Perl module doc π«Ά
π RECIPES π
okay so these are the little copy-paste-able goodies. no cap, they're exactly what you need 99% of the time.
πΈ HTML list formed from array
want a <ul> where every <li> is a thing from your array? boom. the % lines are Perl, the plain lines are literal output. iconic. π
<ul>
% foreach $item (@list) {
<li><% $item %></li>
% }
</ul>
see how the foreach opens, then the HTML happens inside the loop, then % } closes it? the <% $item %> is where Mason drops your value in. chef's kiss π
π¦ HTML table formed from list of objects
same energy but now your array is full of objects and you're calling methods on them. main character table behavior fr fr.
<table>
<tr><th>Foo</th><th>Bar</th><th>Baz</th></tr>
% foreach my $obj (@objects) {
<tr>
<td><% $obj->foo %></td>
<td><% $obj->bar %></td>
<td><% $obj->baz %></td>
</tr>
% }
</table>
header row first, then we loop over @objects, and each object gets asked for foo, bar, and baz. so clean. so demure. π
π SEE ALSO π
Masonβ yeah bestie, go read the main one, that's the whole vibe check π
π AUTHOR π
Jonathan Swartz <swartz@pobox.com> β the legend, the icon, the moment β
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2012 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
tl;dr β it's free, it's Perl-licensed, go wild, just don't be weird about it π
and that's the whole cookbook, bestie!! this page shipped with perl v5.34.0, dated 2022-05-27, and it lives in the Mason:...ookbook(3pm) section of the manual π β¨ now go build something cute π¦π§
π¦ where this page comes from
- debian bookworm: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms