Perl::...Literal(3pm)

πŸ“¦
version 0.19 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 (1 vs "1") are considered to be the same. So adding "42" to the allowlist is the same as adding 42. 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