Perl::...Newline(3pm)
π Perl::...Newline(3pm) π
okay bestie, welcome to another episode of User Contributed Perl Documentation, and today's main character is Perl::...Newline(3pm) β the page about keeping your fat comma glued to its quoted word. no cap, this one's a bop. π
β¨ NAME β¨
Perl::Critic::Policy::CodeLayout::ProhibitFatCommaNewline β keep a fat comma on the same line as its quoted word π«Ά
πΈ DESCRIPTION πΈ
so this policy lives inside the Perl::Critic::Pulp add-on, right, and what it does is it snitches on you when there's a newline chilling between a fat comma and the bareword in front of it. for Perl builtins, it's giving π¨:
my %h = (caller # bad, builtin called as a function
=> 'abc');
and for all words when you're targeting Perl 5.6 and earlier π¦:
use 5.006;
my %h = (foo # bad, all words in perl 5.6 and earlier
=> 'def');
why do we care, you ask? because when there's a newline between the word and the fat comma like that, the word executes as a function call β builtins always do this, and user-defined ones do it in Perl 5.6 and earlier too β so you get its return value instead of a word string. it's giving chaos energy honestly π
and that return value is probably not what you intended, which is why this policy is filed under the "bugs" theme with medium severity (peep "POLICY THEMES" in Perl::Critic).
π₯ Builtins
Perl builtin functions with a newline always execute and hand you back their return value instead of the quoted word. periodt.
my %h = (print # bad, builtin print() executes
=> "abc");
# %h is key "1" value "abc"
the builtin gets called with no arguments, and yeah that might throw a warning from some of them, but others like print will just quietly run like it owns the place π
dashed builtin names such as -print are also function calls, just with a negate operator riding along π
my %h = (-print # bad, print() call and negate
=> "123");
# h is key "-1" value "123"
for the purposes of this policy, the builtins are is_perl_builtin() from Perl::Critic::Utils. it's possible that's more builtins than the particular Perl you're actually running, but guarding against all of them will help you out if you ever go to a newer Perl in the future. future-proofing, we love to see it π
π¦ Non-Builtins
in Perl 5.6 and earlier, all words foo execute as a function call when there's a newline before the fat comma.
sub foo {
return 123
}
my %h = (foo
=> "def");
# in Perl 5.6 and earlier %h is key "123" value "def"
under use strict, an error gets thrown if no such function exists, the usual way. a word builtin is a function call if it exists (with a warning about being interpreted that way), or a bareword if it doesn't.
this policy prohibits all words with a newline before the fat comma when you're targeting Perl 5.6 or earlier. that means either an explicit use 5.006 or smaller, or no such minimum use at all. iykyk π
one subtle way an executing word with a newline before the fat comma can go undetected (still in 5.6 and earlier) is an accidental redefinition of a constant, and she's sneaky:
use constant FOO => "blah";
use constant FOO
=> "some value";
# makes a constant subr called blah (in Perl 5.6)
constant.pm might reject some return values from FOO(), like a number, but a string such as "blah" here quietly expands and creates a constant blah(). not me losing my mind over a silently-created sub π
the difference between Perl 5.6 and later Perl is that in 5.6 the parser only looked as far as a newline for a possible quoting => fat comma. in Perl 5.8 and later, for non-builtins, the lookahead keeps going beyond any newlines and comments. for Perl builtins the behaviour is the same across all versions β the lookahead stops at the newline. ok that's the lore, bestie, we know it now π
β¨ Avoiding Problems β¨
putting the fat comma on the same line as the word ensures it quotes in all cases. simple as that π
my %h = (-print => # ok, fat comma on same line quotes
"123");
if for layout purposes you genuinely want a newline, the suggestion is to give a string or maybe a parenthesized expression, because that doesn't rely on the => fat comma doing the quoting. a fat comma can still emphasize a key/value pair, she still serves π
my %h = ('print' # ok, string
=>
123);
alternately, if a function call is really what's intended (builtin or otherwise), then parens can be used in the normal way to make sure it's a call β as per perltrap, the rule being "if it looks like a function, it is a function" π
my %h = (foo() # ok, function call
=>
123);
π Disabling
as always, if you don't care about any of this, you can disable "ProhibitFatCommaNewline" from your .perlcriticrc in the usual way (see "CONFIGURATION" in Perl::Critic):
[-CodeLayout::ProhibitFatCommaNewline]
slay, do what you want π
π SEE ALSO π
Perl::Critic::PulpPerl::Criticperlop
π HOME PAGE π
<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
π COPYRIGHT π
Copyright 2011, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
and that's the whole thing, bestie π«Ά this was perl v5.40.1, dated 2025-10-21, served to you with love from Perl::...Newline(3pm). go keep your fat commas cozy and stay iconic β¨π
π¦ where this page comes from
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms