From 59c8adde04df9cf418a70eaf0413ac82633821ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudot?= Date: Sun, 9 Sep 2012 21:37:49 +0000 Subject: [PATCH] Allow to get display type in Multi backend (#529) --- .../lib/Lemonldap/NG/Portal/AuthMulti.pm | 8 ++++++-- .../lib/Lemonldap/NG/Portal/_Multi.pm | 6 ++++++ .../t/25-Lemonldap-NG-Portal-Multi.t | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/AuthMulti.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/AuthMulti.pm index ceb660bec..a3bc4b96c 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/AuthMulti.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/AuthMulti.pm @@ -7,7 +7,7 @@ package Lemonldap::NG::Portal::AuthMulti; use Lemonldap::NG::Portal::_Multi; #inherits -our $VERSION = '1.2.0'; +our $VERSION = '1.2.2'; sub authInit { my $self = shift; @@ -46,7 +46,11 @@ sub authForce { sub getDisplayType { my $self = shift; - return $self->_multi->try( 'getDisplayType', 0 ); + my $s = + "Lemonldap::NG::Portal::Auth" + . $self->{_multi}->{last}->[0] + . "::getDisplayType"; + return &{$s}; } 1; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Multi.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Multi.pm index 454d94716..070bcfa1a 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Multi.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Multi.pm @@ -68,6 +68,9 @@ sub try { my $old = $self->{stack}->[$type]->[0]->{n}; my $ci; + # Store last module used + $self->{last}->[$type] = $old; + if ( $ci = $self->{p}->safe->reval( $self->{stack}->[$type]->[0]->{c} ) ) { # Log used module @@ -113,7 +116,10 @@ sub next { shift @{ $self->{stack}->[ 1 - $type ] }; } shift @{ $self->{stack}->[$type] }; + + # Manage end of the stack return 0 unless ( @{ $self->{stack}->[$type] } ); + %{ $self->{p} } = ( %{ $self->{p} }, %{ $self->{p}->{multi}->{ $self->{stack}->[$type]->[0]->{n} } } diff --git a/lemonldap-ng-portal/t/25-Lemonldap-NG-Portal-Multi.t b/lemonldap-ng-portal/t/25-Lemonldap-NG-Portal-Multi.t index 4978d8d6c..50a2e1ba9 100644 --- a/lemonldap-ng-portal/t/25-Lemonldap-NG-Portal-Multi.t +++ b/lemonldap-ng-portal/t/25-Lemonldap-NG-Portal-Multi.t @@ -6,7 +6,7 @@ # change 'tests => 1' to 'tests => last_test_to_print'; package My::Portal; -use Test::More tests => 13; +use Test::More tests => 14; use IO::String; use strict; @@ -102,6 +102,11 @@ my ( $test, $testU ); ok( ( $p->process() == 1 and $p->{error} == PE_OK and $test == 1 ), 'Second module was called' ); + ok( + ( $p->getDisplayType() eq "display2" ), + 'Display type from module 2 was found' + ); + ok( $p = My::Portal->new( { @@ -222,6 +227,10 @@ sub authenticate { Lemonldap::NG::Portal::Simple::PE_ERROR; } +sub getDisplayType { + return "display1"; +} + package Lemonldap::NG::Portal::Auth2; sub authInit { @@ -240,6 +249,10 @@ sub authenticate { Lemonldap::NG::Portal::Simple::PE_OK; } +sub getDisplayType { + return "display2"; +} + package Lemonldap::NG::Portal::UserDB1; sub userDBInit {