Perl::...arnings(3pm)

✨ NAME ✨

Okay bestie, so the actual policy name is a whole mouthful: Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings β€” and what it does is literally just always use warnings. That's it. That's the whole vibe. πŸ’…

(Also, this whole page is from Perl::...arnings(3pm) in the User Contributed Perl Documentation, so you know exactly where you are 🫢)


πŸ¦‹ AFFILIATION πŸ¦‹

This policy is part of the core Perl::Critic distribution, no cap. It ships with the gang already. ✨


πŸ’– DESCRIPTION πŸ’–

Bestie, listen. Using warnings β€” and actually paying attention to what they say β€” is probably the single most effective way to improve the quality of your code. Like, not even close. It's giving "glow-up for your entire codebase." πŸ”₯

So this policy requires that the use warnings statement must come before any other statements, except:

  • package
  • require
  • and other use statements

That way, all the code in the entire package will be affected. Every last line. Main character energy for your whole file. πŸ‘‘

🧚 Special exemptions (iykyk)

There are special exemptions for Moose, Moose::Role, and Moose::Util::TypeConstraints, because they enforce warnings themselves. So like, use Moose is treated as equivalent to use warnings. Slay. 🌸

🌈 Also, the old-perl escape hatch

This policy will not complain if the file explicitly states that it is compatible with a version of perl prior to 5.6 via an include statement β€” for example, by having require 5.005 in it. Respect the elders, periodt. πŸ’œ

⭐ The default cap

The maximum number of violations per document for this policy defaults to 1. So you get one warning about warnings, and then it shuts up. Iconic, honestly. πŸŽ€


πŸ› οΈ CONFIGURATION πŸ› οΈ

So if you make use of things like Moose::Exporter, you can create your own modules that import the warnings pragma into the code that is useing them. Very meta, very demure. πŸ¦‹

There's an option to add to the default set of pragmata and modules in your .perlcriticrc file β€” it's called equivalent_modules, and it goes a lil something like this:

[TestingAndDebugging::RequireUseWarnings]
equivalent_modules = MooseX::My::Sugar

Add your faves, tell the policy they count as warnings-enablers, and you're golden. ✨


πŸ’€ BUGS πŸ’€

Genuinely, it needs to check for -w on the shebang line. Like, that's the whole bug report. Not me pointing out the gap πŸ™ˆ β€” it's literally in the docs.


πŸ‘€ SEE ALSO πŸ‘€

  • Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings β€” the sibling policy, go read it too, bestie 🫢

πŸŽ€ AUTHOR πŸŽ€

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” legend behaviour only. πŸ‘‘


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


fr fr, that's the whole page. Every flag, every exemption, every detail β€” nothing skipped, nothing invented. πŸ’–

And that's the tea from perl v5.42.0, dated 2024-10-23 β€” mwah, go use warnings and text me later πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from