Login
RT #61311: Subroutines::ProhibitUnusedPrivateSubroutines dies on
authorTom Wyant <harryfmudd@comcast.net>
Tue, 14 Sep 2010 05:25:14 +0000 (05:25 +0000)
committerTom Wyant <harryfmudd@comcast.net>
Tue, 14 Sep 2010 05:25:14 +0000 (05:25 +0000)
"&_name" call

The problem was that the return value of sprevious_sibling() was being
incorrectly tested.

About 12 lines into sub _find_sub_reference_in_document(), and again
about 18 lines in, the code 'defined $prior' occurs. The 'defined'
should be removed; that is, the code should just be '$prior'.

The erroneous code assumed that the PPI method sprevious_sibling()
returned undef if there was no previous sibling in the parse tree. In
fact, it is documented as returning a false value.

Changes
lib/Perl/Critic/Policy/Subroutines/ProhibitUnusedPrivateSubroutines.pm
t/Subroutines/ProhibitUnusedPrivateSubroutines.run

diff --git a/Changes b/Changes
index 010cd94..c9251d2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -59,6 +59,8 @@ Next release whenever it is
       \[$@%]) as representing a single argument.
     * Require Exporter version 5.63 (versus version 0) to get sane handling of
       export tags.  RT# 61071
+    * Prevent Subroutines::ProhibitUnusedPrivateSubroutines from failing
+    * on &_subroutine().  RT #61311
 
 [1.109] Released on 2010-08-29
 
index 27aee90..728dabb 100644 (file)
@@ -240,13 +240,13 @@ sub _find_sub_reference_in_document {
             $symbol eq $usage->content() or next;
 
             my $prior = $usage->sprevious_sibling();
-            defined $prior
+            $prior
                 and $prior->isa( 'PPI::Token::Cast' )
                 and q<\\> eq $prior->content()
                 and return $TRUE;
 
             is_function_call( $usage )
-                or defined $prior
+                or $prior
                     and $prior->isa( 'PPI::Token::Word' )
                     and 'goto' eq $prior->content()
                 or next;
index 30e806d..ae67509 100644 (file)
@@ -221,6 +221,20 @@ sub _foo {
 
 #-----------------------------------------------------------------------------
 
+## name RT 61311: dies on "&_name" call
+## failures 0
+## cut
+
+sub first {
+    &_second();
+}
+
+sub _second {
+    print "A private sub\n";
+}
+
+#-----------------------------------------------------------------------------
+
 
 ##############################################################################
 #      $URL$