lokku / Perl-Critic-Lokku

A collection of Perl::Critic policies
https://metacpan.org/pod/Perl::Critic::Lokku
0 stars 4 forks source link

TryTiny::ProhibitExitingSubroutine: method named next should not cause violations #5

Open eserte opened 5 years ago

eserte commented 5 years ago

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 a try block is causing a violation. Sample script:

#!/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)

Probably the same is true also for last etc.