From 642e98e1802ceabc2f1cb63d1a12afee9e6520ef Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 16 Nov 2018 17:30:57 +0100 Subject: [PATCH] Fix some missing "lazy" (#1545) --- lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm | 5 +++-- .../lib/Lemonldap/NG/Common/Notifications/DBI.pm | 6 +++++- .../lib/Lemonldap/NG/Common/Notifications/LDAP.pm | 1 + .../lib/Lemonldap/NG/Portal/2F/Engines/Default.pm | 1 + .../lib/Lemonldap/NG/Portal/Auth/Combination.pm | 2 +- .../lib/Lemonldap/NG/Portal/Main/SecondFactor.pm | 1 + lemonldap-ng-portal/t/test-lib.pm | 11 ++++++----- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm index 1c26b5d98..ce71bea42 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm @@ -11,8 +11,9 @@ has p => ( is => 'rw', weak_ref => 1 ); # Lemonldap::NG configuration hash ref has conf => ( is => 'rw', weak_ref => 1 ); -has logger => ( is => 'rw', default => sub { $_[0]->{p}->logger } ); -has userLogger => ( is => 'rw', default => sub { $_[0]->{p}->userLogger } ); +has logger => ( is => 'rw', lazy => 1, default => sub { $_[0]->{p}->logger } ); +has userLogger => + ( is => 'rw', lazy => 1, default => sub { $_[0]->{p}->userLogger } ); sub error { my $self = shift; diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/DBI.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/DBI.pm index a926592e9..f94b277b7 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/DBI.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/DBI.pm @@ -22,6 +22,7 @@ sub import { has dbiTable => ( is => 'ro', + lazy => 1, default => sub { $_[0]->{table} || 'notifications' } ); @@ -32,6 +33,7 @@ has dbiChain => ( has dbiUser => ( is => 'ro', + lazy => 1, default => sub { $_[0]->{p}->logger->warn('Warning: "dbiUser" parameter is not set'); return ''; @@ -64,7 +66,9 @@ sub get { my ( $self, $uid, $ref ) = @_; return () unless ($uid); $self->_execute( - "SELECT * FROM $self->{dbiTable} WHERE done IS NULL AND uid=?" + "SELECT * FROM " + . $self->dbiTable + . " WHERE done IS NULL AND uid=?" . ( $ref ? " AND ref=?" : '' ) . "ORDER BY date", $uid, diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/LDAP.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/LDAP.pm index ad407d995..b8fb1713b 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/LDAP.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/LDAP.pm @@ -38,6 +38,7 @@ has ldapConfBase => ( has ldapBindDN => ( is => 'ro', + lazy => 1, default => sub { $_[0]->p->logger->warn('Warning: "ldapBindDN" parameter is not set'); return ''; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Engines/Default.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Engines/Default.pm index eee46901c..317cc9ecc 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Engines/Default.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Engines/Default.pm @@ -34,6 +34,7 @@ has sfReq => ( is => 'rw' ); has ott => ( is => 'rw', + lazy => 1, default => sub { my $ott = $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Combination.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Combination.pm index 64ca9cdfe..5b6448d94 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Combination.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Combination.pm @@ -21,7 +21,7 @@ has wrapUserLogger => ( lazy => 1, default => sub { Lemonldap::NG::Portal::Lib::Combination::UserLogger->new( - $_[0]->{userLogger} ); + $_[0]->userLogger ); } ); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/SecondFactor.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/SecondFactor.pm index 93bd47cb7..946435d6a 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/SecondFactor.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/SecondFactor.pm @@ -18,6 +18,7 @@ extends 'Lemonldap::NG::Portal::Main::Plugin'; has ott => ( is => 'rw', + lazy => 1, default => sub { my $ott = $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm index 42eaa6041..028daf199 100644 --- a/lemonldap-ng-portal/t/test-lib.pm +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -498,6 +498,7 @@ has p => ( is => 'rw' ); has ini => ( is => 'rw', + lazy => 1, default => sub { $defaultIni; }, trigger => sub { my ( $self, $ini ) = @_; @@ -626,7 +627,7 @@ sub _get { : () ), 'REQUEST_METHOD' => $args{method} || 'GET', - 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), + 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), ( $args{query} ? ( QUERY_STRING => $args{query} ) : () ), 'SCRIPT_NAME' => '', 'SERVER_NAME' => 'auth.example.com', @@ -678,10 +679,10 @@ sub _post { : () ), 'REQUEST_METHOD' => $args{method} || 'POST', - 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), - 'SCRIPT_NAME' => '', - 'SERVER_NAME' => 'auth.example.com', - 'SERVER_PORT' => '80', + 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), + 'SCRIPT_NAME' => '', + 'SERVER_NAME' => 'auth.example.com', + 'SERVER_PORT' => '80', 'SERVER_PROTOCOL' => 'HTTP/1.1', ( $args{custom} ? %{ $args{custom} } : () ), 'psgix.input.buffered' => 0,