Subject: | RequireBriefOpen vs sub |
Date: | Mon, 13 Jun 2011 09:11:39 +1000 |
To: | bug-Perl-Critic [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
The code below tickles RequireBriefOpen where I believe the close() is
within 5 lines of the open() and so should not.
Sticking in some printfs suggests _get_scope() has decided the whole
file is the scope and then _find_close_invocations_or_return() excludes
the "sub foo" from its search,
return undef if $candidate->isa('PPI::Statement::Sub');
I expect that's meant to skip nested subrs in a block etc. Has
_get_scope() gone too far out? Or _find_close_invocations_or_return()
meant to know to include the sub which contains the open()?
Index: RequireBriefOpen.run
===================================================================
--- RequireBriefOpen.run (revision 4082)
+++ RequireBriefOpen.run (working copy)
@@ -389,7 +389,22 @@
}
#-----------------------------------------------------------------------------
+## name close within same sub
+## failures 0
+## TODO something wrong on subr scope
+## cut
+sub foo {
+ my $fh;
+ (open $fh, '>', $filename
+ and binmode($fh)
+ and print $fh "hello"
+ and close $fh)
+ or die;
+}
+
+#-----------------------------------------------------------------------------
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4