From addc11f696be07a562f26ecdb602d5cb3c919dd8 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Wed, 27 Apr 2016 19:59:33 +0200 Subject: [PATCH] prevent PPI::Normal->register from registering duplicates --- lib/PPI/Normal.pm | 2 +- t/09_normal.t | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/PPI/Normal.pm b/lib/PPI/Normal.pm index fd01413d..920dc533 100644 --- a/lib/PPI/Normal.pm +++ b/lib/PPI/Normal.pm @@ -86,7 +86,7 @@ sub register { } # Has it already been added? - if ( List::Util::any { $_ eq $function } ) { + if ( List::Util::any { $_ eq $function } map @{$_}, values %LAYER ) { return 1; } diff --git a/t/09_normal.t b/t/09_normal.t index 11404ecf..bcd22963 100644 --- a/t/09_normal.t +++ b/t/09_normal.t @@ -58,6 +58,5 @@ NO_DOUBLE_REG: { is $PPI::Normal::LAYER{2}[-1], "main::just_a_test_sub", "and find subs at right layer"; my $size = @{ $PPI::Normal::LAYER{2} }; ok( PPI::Normal->register( "main::just_a_test_sub", 2 ), "can add subs again" ); - local $TODO = 'prevent duplicate registrations of normals'; is scalar @{ $PPI::Normal::LAYER{2} }, $size, "but sub isn't added twice"; }