Perl-Critic-Policy-ControlStructures-ProhibitBareBlockLoopControls
view release on metacpan or search on metacpan
lib/Perl/Critic/Policy/ControlStructures/ProhibitBareBlockLoopControls.pm view on Meta::CPAN
=head2 Real loops (always safe)
while (1) {
next; # ok
}
for my $x (@items) {
last if $x eq 'foo'; # ok
}
foreach my $k (keys %h) {
next; # ok
}
=head1 CONFIGURATION
=for Pod::Coverage supported_parameters
Each keyword C<next>, C<last>, C<redo> can be set to one of:
=over
=item C<forbid> -- always flag this keyword in non-loop blocks (default for
C<next> and C<redo>)
=item C<require_label> -- flag unless the keyword has an explicit label
(default for C<last>)
=item C<allow> -- do not check this keyword at all in non-loop blocks
These per-keyword defaults apply when no block-type override is in effect
(or the override is set to C<follow>; see below).
=back
Block-type overrides (C<do_block>, C<bare_block>) can modify the behaviour
for specific block types:
=over
=item C<bare_block>: C<forbid>, C<require_label>, or C<follow> (default)
per-keyword settings
=item C<do_block>: C<forbid> (default), C<require_label>, or C<follow>
per-keyword settings
=back
Bare blocks are real loops (they execute once), so labeled controls
work correctly. The default is C<follow>, which defers to the per-keyword
setting for each keyword: C<last> requires a label, C<next> and C<redo>
are always flagged. C<do> blocks are not loops at all, so controls are
forbidden entirely by default; C<require_label> allows them when an outer
loop is the intended target.
Example F<perlcriticrc>:
[ControlStructures::ProhibitBareBlockLoopControls]
next = forbid
last = require_label
redo = forbid
do_block = forbid
bare_block = follow
Note: This is the default configuration.
=head1 SEE ALSO
L<perlfunc/last>, L<perlfunc/next>, L<perlfunc/redo>,
L<Perl::Critic::Policy::ControlStructures::ProhibitReturnInDoBlock>
=head1 AUTHOR
Dean Hamstead <dean@fragfest.com.au>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Dean Hamstead.
This is free software, licensed under:
The MIT (X11) License
=cut
( run in 1.371 second using v1.01-cache-2.11-cpan-6aa56a78535 )