Perl::...ltiline(3pm)
π NAME π
Okay so bestie, this is Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline β it's a Perl::Critic policy, and it says: use { and } to delimit your multi-line regexps. Periodt.
π AFFILIATION π
This Policy is part of the core Perl::Critic distribution. She's not a random add-on, she's core, she belongs there. π
β¨ DESCRIPTION β¨
So like, long regular expressions? Genuinely hard to read. No cap. π A really good practice is to use the x modifier and break the regex up into multiple lines with comments explaining what each part does β very demure, very mindful.
But here's the thing: with the usual // delimiters, the beginning and end can be hard to match up, especially in a s/// regexp. It's giving "where does this even end." π
Instead, try using {} characters to delimit your expressions. Slay.
Compare these:
s/
<a \s+ href="([^"]+)">
(.*?)
</a>
/link=$1, text=$2/xms;
vs.
s{
<a \s+ href="([^"]+)">
(.*?)
</a>
}
{link=$1, text=$2}xms;
Is that an improvement? Marginally, but yes. π The curly braces lead the eye better. The vibe check passes. The { and } are literally the main characters here.
πΈ CONFIGURATION πΈ
There is one option for this policy, and it's called allow_all_brackets.
allow_all_bracketsβ if this is true, then, in addition to allowing{}, the other matched pairs of(),[], and<>are allowed too. Very generous of her. π«Ά
β CREDITS β
Initial development of this policy was supported by a grant from the Perl Foundation. Shoutout to them fr fr. π
π¦ AUTHOR π¦
Chris Dolan <cdolan@cpan.org> β icon, legend, the moment. π
π COPYRIGHT π
Copyright (c) 2007-2023 Chris Dolan
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.
π Real talk though: if you're redistributing, actually read that LICENSE file. It's literally right there, bestie. Don't skip it.
And that's the whole page, bestie β this one's from perl v5.42.0, dated 2024-10-23, and it's the User Contributed Perl Documentation for Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline(3pm). Go forth and brace your multiline regexps. π
β¨π
π¦ 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