Perl::...tements(3pm)
π NAME π
Okay so this is Perl::...tements(3pm), from the User Contributed Perl Documentation, bestie. The policy is Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements, and its whole thing is: avoid putting conditional logic around compile-time includes. Periodt. β¨
πΈ AFFILIATION πΈ
This Policy is part of the core Perl::Critic distribution. Iconic behavior, no cap. π
π¦ DESCRIPTION π¦
Modules included via use are loaded at compile-time. Placing conditional logic around the use statement has no effect on whether the module will be loaded. Doing so can also serve to confuse the reader as to the author's original intent.
If you need to conditionally load a module you should be using require instead.
bestie, this is the whole plot twist:useis doing its compile-time thing whether you wrap it in anifor not. The conditional vibe is giving nothing but confusion. π
This policy will catch the following forms of conditional use statements:
# if-elsif-else
if ($a == 1) { use Module; }
if ($a == 1) { } elsif ($a == 2) { use Module; }
if ($a == 1) { } else { use Module; }
# for/foreach
for (1..$a) { use Module; }
foreach (@a) { use Module; }
# while
while ($a == 1) { use Module; }
# unless
unless ($a == 1) { use Module; }
# until
until ($a == 1) { use Module; }
# do-condition
do { use Module; } if $a == 1;
do { use Module; } while $a == 1;
do { use Module; } unless $a == 1;
do { use Module; } until $a == 1;
# operator-do
$a == 1 || do { use Module; };
$a == 1 && do { use Module; };
$a == 1 or do { use Module; };
$a == 1 and do { use Module; };
# non-string eval
eval { use Module; };
Including a module via use in bare blocks, standalone do blocks, or string evals is allowed. Slay, those get a pass. π«Ά
# bare block
{ use Module; }
# do
do { use Module; }
# string eval
eval "use Module";
π CONFIGURATION π
This Policy is not configurable except for the standard options. That's it, bestie β no secret extra knobs, no hidden settings, just the standard options. π
π AUTHOR π
Peter Guzis <pguzis@cpan.org> β actual legend. β
π COPYRIGHT π
Copyright (c) 2010-2011 Peter Guzis. 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.
Source/version/date check, bestie: perl v5.42.0, 2024-10-23, and yes β Perl::...tements(3pm). Byeee, ily π«Άπ
π¦ 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