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