Perl::...leColon(3pm)
π NAME π
Perl::Critic::Policy::ValuesAndExpressions::ProhibitBarewordDoubleColon β bestie, this is from User Contributed Perl Documentation, and it's here to tell you: don't use Foo:: style barewords, okay? periodt.
β¨ DESCRIPTION β¨
Okay so this policy is part of the Perl::Critic::Pulp add-on π«Ά and it's literally begging you not to use the double-colon bareword like this:
$class = Foo::Bar::; # bad
and instead write a plain string, like so:
$class = 'Foo::Bar'; # ok
Why tho? Because it's meant as a building block for a restricted coding style, OR it's just a personal preference thing β if you think the "::" is a bit obscure and it's genuinely clearer to write a string when you mean a string, this policy is your girl. On that basis it's the lowest severity and lives under the "cosmetic" theme (see "POLICY THEMES" in Perl::Critic).
π¦ Indirect Object Syntax π¦
By default a double-colon is allowed in the indirect object syntax (see "Indirect Object Syntax" in perlobj).
my $obj = new Foo::Bar:: $arg1,$arg2; # ok
And why? Because "::" in there is important, fr fr β it disambiguates a class name "Foo::Bar" from a function Foo::Bar(), i.e. function Bar() in package "Foo". iykyk.
Whether you actually want indirect object syntax is a whole other matter handled by other policies, like "ProhibitIndirectSyntax". If you don't want the double-colon bareword, just switch to arrow style: Foo::Bar->new($arg,...). slay.
π Double-Colon Advantages π
The "::" bareword is for use on package names, not general bareword quoting. If there's no such package at compile time, a warning gets thrown (see "Bareword "%s" refers to nonexistent package" in perldiag):
my $class = No::Such::Package::; # Perl warning
This warning can help pick up typos π β though ngl it relies on the relevant packages being loaded at compile-time (i.e. "BEGIN"). If the package gets loaded by a "require" at runtime, then the warning fires even though the code runs correctly π. For reference, a warning isn't given for the indirect object syntax, which rather limits its benefit. π
πΈ Disabling πΈ
If you don't care about any of this, you can always disable ProhibitBarewordDoubleColon from your .perlcriticrc in the usual way (see "CONFIGURATION" in Perl::Critic):
[-ValuesAndExpressions::ProhibitBarewordDoubleColon]
π CONFIGURATION π
"allow_indirect_syntax"(boolean, default true) β If true, then allow double-colon in the indirect object syntax as shown above. If false, then report double-colons everywhere as violations:
# bad under allow_indirect_syntax=false
my $obj = new Foo::Bar:: $arg1,$arg2;
This can be controlled from your ~/.perlcriticrc in the usual way. For example:
[ValuesAndExpressions::ProhibitBarewordDoubleColon]
allow_indirect_syntax=no
π SEE ALSO π
Perl::Critic::Pulp,Perl::Critic,Perl::Critic::Policy::Objects::ProhibitIndirectSyntax- ""Foo::" can be used as implicitly quoted package name" in perl5005delta
π HOME PAGE π
http://user42.tuxfamily.org/perl-critic-pulp/index.html
π COPYRIGHT π
Copyright 2010, 2011, 2012, 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 a wrap bestie π«Ά this was perl v5.40.1, dated 2025-10-21, and it's Perl::Critic::Policy::ValuesAndExpressions::ProhibitBarewordDoubleColon(3pm) signing off π β¨ go forth and quote your strings, mwah
π¦ 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