Mason:...larDot(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

πŸ’… Mason::Plugin::DollarDot β€” the perl docs, but make it cute

okay bestie, gather round, because this is a 3pm page from the User Contributed Perl Documentation and it is genuinely a little gem. it's called Mason::Plugin::DollarDot and it exists so you can write $. instead of $self-> β€” and also inside attribute names. that's the whole vibe. πŸŽ€


✨ NAME ✨

Mason::Plugin::DollarDot β€” Allow $. as substitution for $self-> and in attribute names


πŸ¦‹ SYNOPSIS πŸ¦‹

<%class>
has 'name';
has 'date';
</%class>

<%method greet>
Hello, <% $.name %>. Today is <% $.date %>.
</%method>

...
% $.greet();

<%init>
# Set the date
$.date(scalar(localtime));
# or, if combined with LvalueAttributes
$.date = scalar(localtime);
</%init>

🌸 DESCRIPTION 🌸

so here's the tea, bestie: this plugin swaps $.identifier in for $self->identifier in every single bit of Perl code inside your components. that means you can just write $. whenever you're referring to attributes or calling methods. no cap, that's it. πŸ’–

the actual regex doing the work is literally this, character for character:

s/ \$\.([^\W\d]\w*) / \$self->$1 /gx;

πŸ‘‘ RATIONALE πŸ‘‘

okay so why does this exist? because in Mason 2, components have to write $self-> a lot just to refer to attributes that were plain simple scalars back in Mason 1. this plugin eases that transition pain. 🫢 and $. was picked because Perl 6 uses it in a similar way. iconic choice, honestly.

now for the honesty hour: this plugin falls under the heading of gratuitous source filtering, which the author generally agrees is Evil. πŸ’€ but β€” and this is the important part β€” it's a very limited filter, and it seems unlikely to break any legitimate Perl syntax, other than use of the $. special variable (which is the input line number). so like. keep that in mind. πŸ™ˆ


😭 BUGS 😭

it will not interpolate the way you expect inside double quotes:

"My name is $.name"   # nope

instead you have to do:

"My name is " . $.name

that's the whole bug list. short, sweet, devastating. πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

  • Mason

🧚 AUTHOR 🧚

Jonathan Swartz <swartz@pobox.com>


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.


and that's the page, bestie β€” perl v5.34.0, dated 2022-05-27, straight from the User Contributed Perl Documentation. go forth and $. responsibly. slay. βœ¨πŸ‘‘πŸ’…

πŸ“¦ where this page comes from