Perl::...Pragma(3pm)
π NAME
Okay bestie, gather round β this is Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma, a policy from the Perl::Critic fam (manual page Perl::...Pragma(3pm), if you're keeping track π).
Its whole entire job? It's the policy that says don't do use constant FOO => 15. That's it. That's the vibe check it's running. β¨
πΈ AFFILIATION
This Policy is part of the core Perl::Critic distribution. So it ships with the main character, no extra install required, iykyk π«Ά
π DESCRIPTION
Named constants? Literally iconic. We love them, we support them, they're doing great sweetie. π₯°
But β and this is the part the policy is screaming about β do not use the constant pragma, because barewords don't interpolate. Like, at all. Rough, I know. π
Instead, use the Readonly module. It's the upgrade. Trust. π
use constant FOOBAR => 42; #not ok
use Readonly;
Readonly my $FOOBAR => 42; #ok
Readonly::Scalar my $FOOBAR => 42; #ok
So the constant version is a β¨ no β¨, and both Readonly forms are a yes. Noted and screenshotted. πΈ
β CONFIGURATION
Big news: this Policy is not configurable. At all. The only knobs you get are the standard options, and that's the whole menu. Periodt. π
π AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
Give the man his flowers, he wrote the policy πΈ
π COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.
And that's a wrap, bestie ππ¦β¨ This page came to you courtesy of perl v5.42.0, dated 2024-10-23, from the User Contributed Perl Documentation crew β go forth and use Readonly, not constant, fr fr π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms