Factor loadPlugin override (#1500)

This commit is contained in:
Xavier Guimard 2018-10-03 21:48:57 +02:00
parent 107b0386b9
commit 29d00823e5
3 changed files with 33 additions and 26 deletions

View File

@ -62,6 +62,7 @@ lib/Lemonldap/NG/Portal/Lib/OpenID/Server.pm
lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm
lib/Lemonldap/NG/Portal/Lib/OpenIDConnect.pm
lib/Lemonldap/NG/Portal/Lib/OtherSessions.pm
lib/Lemonldap/NG/Portal/Lib/OverConf.pm
lib/Lemonldap/NG/Portal/Lib/Remote.pm
lib/Lemonldap/NG/Portal/Lib/REST.pm
lib/Lemonldap/NG/Portal/Lib/RESTProxy.pm

View File

@ -4,12 +4,12 @@ use strict;
use Mouse;
use Lemonldap::NG::Common::Combination::Parser;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR);
use Scalar::Util 'weaken';
our $VERSION = '2.0.0';
# TODO: See Lib::Wrapper
extends 'Lemonldap::NG::Portal::Main::Auth';
with 'Lemonldap::NG::Portal::Lib::OverConf';
# PROPERTIES
@ -205,31 +205,6 @@ sub name {
|| 'Combination';
}
# To avoid "tied" destroy, tied configurations are kept here
our %overC;
# Override portal loadPlugin() to use a wrapped configuration
sub loadPlugin {
my ( $self, $plugin, $over ) = @_;
my $obj;
my $nc;
if ($over) {
require Lemonldap::NG::Common::Conf::Wrapper;
tie %$nc, 'Lemonldap::NG::Common::Conf::Wrapper', $self->conf, $over;
$overC{$plugin} = $nc;
}
else {
$nc = $self->conf;
}
return 0
unless ( $obj = $self->p->loadModule( "$plugin", $nc ) );
return 0
unless $obj = $self->p->findEP( $plugin, $obj );
$obj->{userLogger} = $self->wrapUserLogger;
weaken $obj->{userLogger};
return $obj;
}
package Lemonldap::NG::Portal::Lib::Combination::UserLogger;
# This logger rewrite "warn" to "notice"

View File

@ -0,0 +1,31 @@
package Lemonldap::NG::Portal::Lib::OverConf;
use Mouse::Role;
use Scalar::Util 'weaken';
# To avoid "tied" destroy, tied configurations are kept here
our @overC;
# Override portal loadPlugin() to use a wrapped configuration
sub loadPlugin {
my ( $self, $plugin, $over ) = @_;
my $obj;
my $nc;
if ($over) {
require Lemonldap::NG::Common::Conf::Wrapper;
tie %$nc, 'Lemonldap::NG::Common::Conf::Wrapper', $self->conf, $over;
push @overC, $nc;
}
else {
$nc = $self->conf;
}
return 0
unless ( $obj = $self->p->loadModule( "$plugin", $nc ) );
return 0
unless $obj = $self->p->findEP( $plugin, $obj );
$obj->{userLogger} = $self->wrapUserLogger;
weaken $obj->{userLogger};
return $obj;
}
1;