From d788674e22471df024e06837f1c8d6c06d0ea20f Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Tue, 5 Sep 2017 18:34:46 +0000 Subject: [PATCH] Warn if a route is redefined (#595) --- .../lib/Lemonldap/NG/Common/PSGI/Router.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm index 1225590a1..95de7612a 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm @@ -59,21 +59,28 @@ sub genRoute { $dest = $transform->($dest); } if ( my $t = ref $dest ) { - if ( $t eq 'CODE' ) { - $routes->{$word} = $dest; - } - elsif ( $t eq 'HASH' ) { + if ( $t eq 'HASH' ) { $routes->{$word} ||= {}; foreach my $w ( keys %$dest ) { $self->genRoute( $routes->{$word}, $w, $dest->{$w}, $transform ); } + return; } elsif ( $t eq 'ARRAY' ) { $routes->{$word} ||= {}; foreach my $w ( @{$dest} ) { $self->genRoute( $routes->{$word}, $w, $transform ); } + return; + } + } + if ( $routes->{$word} ) { + eval { $self->logger->warn(qq'Route "$word" redefined'); }; + } + if ( my $t = ref $dest ) { + if ( $t eq 'CODE' ) { + $routes->{$word} = $dest; } else { die "Type $t unauthorizated in routes";