Avoid test failure when Redis.pm is unavailable

This commit is contained in:
Jared Johnson 2014-12-30 15:10:32 -06:00
parent 89b942b634
commit 6e3e605c66

View File

@ -1,7 +1,6 @@
package Qpsmtpd::DB::Redis; package Qpsmtpd::DB::Redis;
use strict; use strict;
use warnings; use warnings;
use Redis;
use parent 'Qpsmtpd::DB'; use parent 'Qpsmtpd::DB';
@ -16,6 +15,10 @@ sub new {
sub init_redis { sub init_redis {
my ( $self ) = @_; my ( $self ) = @_;
# Stringy eval needed to allow 'use Qpmstpd::DB::Redis' to succeed
# even when Redis module is unavailable; mainly for testing
eval 'use Redis';
die $@ if $@;
my $redis = $self->{redis} = MyRedis->new( %{ $self->{redis_args} } ); my $redis = $self->{redis} = MyRedis->new( %{ $self->{redis_args} } );
$redis->selected(0); $redis->selected(0);
return $redis; return $redis;