Perl::...Literal(3pm)
β¨ NAME β¨
TooMuchCode::ProhibitDuplicateLiteral β bestie, don't repeat yourself with identical literals π
It lives in the Perl::...Literal(3pm) manual, if you were wondering where to find her.
π¦ DESCRIPTION π¦
Okay so picture this: this policy is doing a little vibe check on your perl code, and what it's looking for is string/number literals that have the exact same value chilling in the same piece of perl code. π
When it finds them? Honestly it's usually just a tiny little signal that you're repeating yourself β and maybe, maybe, a small chance that a lil refactor is calling your name. Lowkey a hint, not a scandal. β¨
π CONFIGURATION π
Some strings/numbers can be allowed to have duplicates, and the way you do that is by listing them in the allowlist parameter in the configs, like so:
[TooMuchCode::ProhibitDuplicateLiteral]
allowlist = 'present' "forty two" 42
The values are a space-separated list of numbers or quoted strings. π«Ά
The default values in the allowlist are: "0 1". These two numbers are always part of the allowlist and cannot be removed. Not negotiable, they're permanent residents. π
β οΈ Please be aware that a string literal and its numerical literal counterpart (1vs"1") are considered to be the same. So adding"42"to the allowlist is the same as adding42. Same energy, same entry, no cap. π
πΈ That's the whole page, bestie β sending you off with the receipts: this is from perl v5.36.0, dated 2023-10-05, and it's part of the Perl::...Literal(3pm) manual. Slay, go refactor something. ππ
π¦ where this page comes from
- debian trixie: libperl-critic-toomuchcode-perl 0.19-1 Β· MIT
- ubuntu noble: libperl-critic-toomuchcode-perl 0.19-1 Β· MIT
- ubuntu resolute: libperl-critic-toomuchcode-perl 0.19-1 Β· MIT
- ubuntu stonking: libperl-critic-toomuchcode-perl 0.19-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms