Update Qpsmtpd::DB to work with multiple stores

This commit is contained in:
Jared Johnson 2014-12-09 13:05:47 -06:00
parent b335e26078
commit ecb6d2c1d5
2 changed files with 22 additions and 3 deletions

View File

@ -5,12 +5,26 @@ use Qpsmtpd::DB::File::DBM;
sub new {
my ( $class, %arg ) = @_;
# The only supported class just now
return bless { %arg }, 'Qpsmtpd::DB::File::DBM';
# Qpsmtpd::DB::File::DBM is the only supported class just now
my @child_classes = qw(
Qpsmtpd::DB::File::DBM
);
my $manual_class = delete $arg{class};
return $manual_class->new(%arg) if $manual_class;
my ( $child, @errors );
for my $child_class ( @child_classes ) {
eval {
$child = $child_class->new(%arg);
};
last if ! $@;
push @errors, "Couldn't load $child_class: $@";
}
return $child if $child;
die join( "\n", "Couldn't load any storage modules", @errors );
}
# noop default method for plugins that don't require locking
sub get_lock { 1 }
sub lock { 1 }
sub name {
my ( $self, $name ) = @_;

View File

@ -3,6 +3,11 @@ use strict;
use warnings;
use parent 'Qpsmtpd::DB';
sub new {
my ( $class, %arg ) = @_;
return bless { %arg }, $class;
}
sub dir {
my ( $self, @candidate_dirs ) = @_;
return $self->{dir} if $self->{dir} and ! @candidate_dirs;