#!/usr/bin/perl
use strict;
use warnings;
use Try::Tiny;
{
package Foo;
sub new { bless { i => 0}, shift }
sub next { $_[0]->{i}++ }
}
my $foo = Foo->new;
try {
$foo->next();
} catch {
warn "something failed";
}
__END__
$ perlcritic --single-policy TryTiny::ProhibitExitingSubroutine try-tiny-perlcritic-method-next.pl
Using next/last/redo/return in a Try::Tiny block is ambiguous at line 15, column 11. Using next/last/redo without a label or using return in a Try::Tiny block is ambiguous, did you intend to exit out of the try/catch/finally block or the surrounding block?. (Severity: 4)
A called method
next
(which is not that uncommon, see for example https://metacpan.org/pod/release/MONGODB/MongoDB-v2.0.1/lib/MongoDB/Cursor.pm#next ) within atry
block is causing a violation. Sample script:Probably the same is true also for
last
etc.