Mason:...ookbook(3pm)

πŸ“¦
version 2.24 Β· 2 versions
  • 2.24 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.24 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 ⭐


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