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 (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