2014-11-26 00:52:18 +01:00
|
|
|
package Qpsmtpd::DB;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2014-12-26 07:52:17 +01:00
|
|
|
|
|
|
|
our @child_classes = qw(
|
|
|
|
Qpsmtpd::DB::Redis
|
|
|
|
Qpsmtpd::DB::File::DBM
|
|
|
|
);
|
2014-11-26 00:52:18 +01:00
|
|
|
|
|
|
|
sub new {
|
|
|
|
my ( $class, %arg ) = @_;
|
2014-12-26 07:52:17 +01:00
|
|
|
my @try_classes = @child_classes;
|
|
|
|
if ( my $manual_class = delete $arg{class} ) {
|
|
|
|
@try_classes = ( $manual_class );
|
|
|
|
}
|
2014-12-09 20:05:47 +01:00
|
|
|
my ( $child, @errors );
|
2014-12-26 07:52:17 +01:00
|
|
|
for my $child_class ( @try_classes ) {
|
|
|
|
eval "use $child_class";
|
2014-12-09 20:05:47 +01:00
|
|
|
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 );
|
2014-11-26 00:52:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# noop default method for plugins that don't require locking
|
2014-12-20 09:17:59 +01:00
|
|
|
sub lock { 1 }
|
|
|
|
sub unlock { 1 }
|
2014-11-26 00:52:18 +01:00
|
|
|
|
|
|
|
sub name {
|
|
|
|
my ( $self, $name ) = @_;
|
|
|
|
return $self->{name} = $name if $name;
|
|
|
|
return $self->{name};
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|