Mason:...larDot(3pm)
π
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>
π 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.
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
- 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