Mason:...andard(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::Filters::Standard β€” it's giving standard filters, bestie ✨

(this is from the User Contributed Perl Documentation, section 3pm, and it's a Perl module page, so perl is the manual name here 🫢)


🌸 DESCRIPTION 🌸

Okay so listen. These filters? They get automatically composed into Mason::Component. You don't have to go fetch them, you don't have to import them, they just show up in every component like a bestie who already knows the group chat drama. No cap. πŸ’…


✨ FILTERS ✨

πŸŽ€ Capture ($ref)

Uses $m->capture to capture the content into $ref instead of outputting it. So it's like β€” the content goes into the variable, not onto the page. Sneaky. Iconic.

% $.Capture(\my $content) {{
  <!-- this will end up in $content -->
% }}

... do something with $content

πŸ¦‹ CompCall ($path, @args...)

Calls the component at path with @args, exactly like $m->scomp would β€” but with one extra lil' coderef argument called yield that you can invoke to generate the content. Anything you pass to yield? You can grab it inside the content via @_. 🌈

This is the glow-up replacement for Mason 1's Components With Content β€” you can find that at http://search.cpan.org/perldoc?HTML::Mason::Devel#Component_Calls_with_Content.

In index.mc:

% $.CompCall ('list_items.mi', items => \@items) {{
<li><% $_[0] %></li>
% }}

In list_items.mi:

<%class>
has 'items';
has 'yield';
</%class>

% foreach my $item (@{$.items}) {
<% $.yield->($item) %>
% }

πŸ’œ NoBlankLines

Removes lines that have nothing but whitespace in them from the content. Bye bye ghost lines πŸ‘»

This:

% $.NoBlankLines {{

hello

world
% }}

yields:

hello
world

πŸ”₯ Repeat ($count)

Repeats the content block $count times. ⚠️ Heads up bestie: the block is re-executed each time, so you might get different content each go-round. It's not a copy-paste situation, it's a rerun situation.

<!-- Prints 1 to 5 -->
% my $i = 1;
% $.Repeat(5) {{
   <% $i++ %><br>
% }}

πŸ’… Tee ($ref)

Uses $m->capture to capture the content into $ref, and also output it. Like, both. Greedy in the best way. It said "why not both" and honestly? Slay.

% $.Tee(\my $content) {{
  <!-- this will end up in $content and also be output -->
% }}

...

<!-- output content again down here -->
<% $content %>

⭐ Trim

Removes whitespace from the beginning and the end of the content. Clean edges only. Periodt.


πŸ‘€ SEE ALSO πŸ‘€

  • Mason::Manual::Filters
  • Mason

πŸ‘‘ AUTHOR πŸ‘‘

Jonathan Swartz <swartz@pobox.com> β€” the main character who wrote all this πŸ’–


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.


okay and that's the whole page bestie, ty for coming to my ted talk πŸŽ€βœ¨

this was perl v5.34.0, dated 2022-05-27 β€” the Mason::Filters::Standard 3pm page, and yes we read the entire thing, no skimming, no skipping, we ate and left no crumbs πŸ«ΆπŸ’–

πŸ“¦ where this page comes from