Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eserte opened this issue Nov 30, 2018 · 0 comments

Comments

@eserte
Copy link

eserte commented Nov 30, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant