Perl::...rdLists(3pm)

πŸ’… Perl::...rdLists(3pm)

okay so this is a page from the User Contributed Perl Documentation, and the manual you're holding rn is Perl::...rdLists(3pm). the full policy name (because the header had to go and abbreviate it 😭) is Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists. she's a lil wordy but she's iconic. let's get into it bestie 🫢


✨ NAME ✨

Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists β€” write qw(foo bar baz) instead of ('foo', 'bar', 'baz'). that's the whole vibe. no cap. πŸ’…

πŸŽ€ AFFILIATION πŸŽ€

this policy is part of the core Perl::Critic distribution. so she ships with the main character package, she's not some random third-party plugin you gotta hunt down. periodt. πŸ‘‘

🌸 DESCRIPTION 🌸

so Conway doesn't mention this, but honestly? I think qw() is a lowkey underused feature of Perl. like, whenever you need to declare a list of one-word literals, the qw() operator is wonderfully concise, and it makes it easy to add to the list in the future. it's giving future-proofing. it's giving clean. it's giving slay. ✨

@list = ('foo', 'bar', 'baz');  #not ok
@list = qw(foo bar baz);        #ok

use Foo ('foo', 'bar', 'baz');  #not ok
use Foo qw(foo bar baz);        #ok

see how much cuter the second ones are?? the first ones are not ok β€” the policy will absolutely clock them. πŸ™ˆ

πŸ¦‹ CONFIGURATION πŸ¦‹

bestie you can tune this. this policy can be configured to only pay attention to word lists with at least a particular number of elements. by default, this value is 2, which means that lists containing zero or one elements are ignored. so a tiny lil one-word list doesn't get dragged. πŸ’–

the minimum list size to be looked at can be specified by giving a value for "min_elements" in .perlcriticrc like this:

[CodeLayout::ProhibitQuotedWordLists]
min_elements = 4

this would cause this policy to only complain about lists containing four or more words. so anything shorter than 4 skates by, no questions asked. 🧚

by default, this policy won't complain if any of the values in the list contain non-word characters. like she's gotta be reasonable. but if you want it to, set the "strict" option to a true value:

[CodeLayout::ProhibitQuotedWordLists]
strict = 1
⚠️ heads up: strict = 1 means she's gonna come for lists with non-word characters in them too. so know what you're signing up for before you flip that switch. πŸ’€

⭐ NOTES ⭐

in the PPI parlance, a "list" is almost anything with parentheses. I've tried to make this Policy smart by targeting only "lists" that could be sensibly expressed with qw(). so like, she's not out here yelling at every pair of parens she sees. but there may be some edge cases that I haven't covered. if you find one, send me a note. fr fr, I wanna know. 🫢

πŸ”₯ IMPORTANT CHANGES πŸ”₯

this policy was formerly called "RequireQuotedWords" which seemed a little counter-intuitive. honestly? yeah. the rebrand was necessary, she needed a glow-up. πŸ’…

😭 if you get lots of "Cannot load policy module" errors, then you probably need to change "RequireQuotedWords" to "ProhibitQuotedWordLists" in your .perlcriticrc file. like, go check your config babes, that's the fix.

🌈 AUTHOR 🌈

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” the icon who wrote this. give her some love. πŸ’

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 the whole page!! πŸŽ€ tysm for reading bestie, this was perl v5.42.0, dated 2024-10-23, brought to you by Perl::...rdLists(3pm) β€” now go forth and qw() responsibly. mwah! πŸ’‹πŸ’–

πŸ“¦ where this page comes from