From 07cd2bb8df7e870582a02860187f4fd1b88ec334 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sun, 12 Jan 2014 17:25:47 +0100 Subject: [PATCH] fix check of return value of firstidx (-1 on not found, instead of undef) --- lib/PPI/Node.pm | 2 +- t/ppi_node.t | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/PPI/Node.pm b/lib/PPI/Node.pm index 2b4f5ebe..bb4f76b7 100644 --- a/lib/PPI/Node.pm +++ b/lib/PPI/Node.pm @@ -512,7 +512,7 @@ sub remove_child { my $p = List::MoreUtils::firstidx { refaddr $_ == $key } @{$self->{children}}; - return undef unless defined $p; + return undef if $p == -1; # Splice it out, and remove the child's parent entry splice( @{$self->{children}}, $p, 1 ); diff --git a/t/ppi_node.t b/t/ppi_node.t index 12f26f23..cc14c6b6 100644 --- a/t/ppi_node.t +++ b/t/ppi_node.t @@ -42,6 +42,5 @@ REMOVE_CHILD: { my $del1 = $node->child(7); is $node->remove_child($del1), $del1; my $fake = bless { content => 3 }, "PPI::Token::Number"; - local $TODO = "firstidx is mis-used here"; is $node->remove_child($fake), undef; }