NAME
Perl::Critic::Policy::TryTiny::ProhibitExitingSubroutine - Ban next/last/return in Try::Tiny blocks
VERSION
version 0.003
DESCRIPTION
Take this code:
use Try::Tiny;
for my $item (@array) {
try {
next if $item == 2;
# other code
}
catch {
warn $_;
};
# other code
}
The next statement will not go to the next iteration of the for-loop, rather, it will exit the try block, emitting a warning if warnings are enabled.
This is probably not what the developer had intended, so this policy prohibits it.
One way to fix this is to use labels:
use Try::Tiny;
ITEM:
for my $item (@array) {
try {
if ($item == 2) {
no warnings 'exiting';
next ITEM;
}
# other code
}
catch {
warn $_;
};
# other code
}
This policy assumes that Try::Tiny is being used, and it doesn't run if it can't find it being imported.
CONFIGURATION
This Policy is not configurable except for the standard options.
AUTHOR
David D Lowe <flimm@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Lokku <cpan@lokku.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.