Lemonldap-NG-Common
view release on metacpan or search on metacpan
t/60-Hashed-Session.t
t/60-Session-Cache.t
t/60-Session-Cli.t
t/60-U2F-Migrate.t
t/70-User-Agent.t
t/71-Util-Crypto.t
t/99-pod.t
t/data/preview-all-test-metadata.xml
t/lemonldap-ng.ini
t/log4perl.ini
t/overlay_test/lmConf-1.json
t/overlay_test/overlay/globalStorage
t/overlay_test/overlay/globalStorageOptions
t/TestAuditLogger.pm
t/TestConfBackend.pm
t/TestLogger.pm
t/TestPsgi.pm
tools/config.my.sql
tools/config.pg.sql
tools/notifications.my.sql
tools/notifications.pg.sql
tools/sessions.my.sql
tools/sessions.pg.sql
lib/Lemonldap/NG/Common/Conf/Backends/Overlay.pm view on Meta::CPAN
our $VERSION = '2.19.0';
sub load {
my ( $self, $cfgNum, $fields ) = @_;
my @files = eval { overList($self) };
if ($@) {
$Lemonldap::NG::Common::Conf::msg .= $@;
return undef;
}
my $conf =
&{"Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}::load"}
(@_);
my @errors;
foreach my $file (@files) {
if ( open my $f, '<', "$self->{overlayDirectory}/$file" ) {
local $/ = undef;
my $content = <$f>;
close $f;
if ( $file =~ $hashParameters ) {
eval { $content = JSON::from_json($content) };
if ($@) {
push @errors, "Bad over file $file: $@";
}
else {
$conf->{$file} = $content;
lib/Lemonldap/NG/Common/Conf/Backends/Overlay.pm view on Meta::CPAN
return $conf;
}
sub store {
my ( $self, $fields ) = @_;
my @files = eval { overList($self) };
my @errors;
foreach my $file (@files) {
my $data = delete $fields->{$file};
if ( $self->{overlayWrite} ) {
if ( open my $f, '>', "$self->{overlayDirectory}/$file" ) {
print $f (
$file =~ $hashParameters ? JSON::to_json($data) : $data );
close $f;
}
else {
push @errors, "Unable to write over file $file: $@";
}
}
}
die join( "\n", @errors ) if $@;
return &{
"Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}::store"
}( $self, $fields );
}
sub overList {
my ($self) = @_;
my $overDir = $self->{overlayDirectory} or die 'Missing overlayDirectory';
die "$overDir directory doesn't exist" unless -d $overDir and -r $overDir;
opendir my $dir, $overDir or die $!;
my @files = grep /^[^\.]/, readdir $dir;
closedir $dir;
my @errors;
foreach my $file (@files) {
if ( open my $f, '<', "$overDir/$file" ) {
local $/ = undef;
my $content = <$f>;
lib/Lemonldap/NG/Common/Conf/Backends/Overlay.pm view on Meta::CPAN
$conf->{$file} = $content;
}
}
}
die join "\n", @errors if @errors;
return @files;
}
sub AUTOLOAD {
my ($self) = @_;
die 'Missing overlayRealtype'
unless $self->{overlayRealtype};
eval
"require Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}";
die $@ if $@;
$AUTOLOAD =~ s/::Overlay::/::$self->{overlayRealtype}::/;
my @res = &{$AUTOLOAD}(@_);
return wantarray ? (@res) : $res;
}
1;
t/02-Common-Conf-Overlay.t view on Meta::CPAN
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
my $confAcc;
ok(
$confAcc = new Lemonldap::NG::Common::Conf( {
type => 'Overlay',
dirName => 't/overlay_test',
overlayRealtype => 'File',
overlayDirectory => 't/overlay_test/overlay',
overlayWrite => 1,
}
),
'type => Overlay',
);
my $cfg;
unlink 't/overlay_test/lmConf-2.json', 't/overlay_test/lmConf-3.json';
# READ
ok( $cfg = $confAcc->load(1), 'Load conf' )
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
my $count = 2;
ok( ( $cfg->{a} eq 'string' && $cfg->{b} == 1 ), 'Normal parameters' );
ok( $cfg->{globalStorage} eq 'Test::GlobalStorage', 'Scalar override' );
ok(
t/02-Common-Conf-Overlay.t view on Meta::CPAN
ok( $cfg = $confAcc->load(3), 'Load conf' )
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
ok(
ref $cfg->{globalStorageOptions} eq 'HASH'
&& $cfg->{globalStorageOptions}->{param} eq 'parameter',
'Hash override'
);
$count += 3;
done_testing($count);
unlink 't/overlay_test/lmConf-2.json', 't/overlay_test/lmConf-3.json';
( run in 0.743 second using v1.01-cache-2.11-cpan-49f99fa48dc )