Here's an example taken from Maplat::Web::MemCache.pm:
my $memd;
my $memd_loaded = 0;
# Decide which Memcached module we want to use
# First, we try the festest one, then the standard
# one and if everything fails we use our own
my $memdtype;
{
## no critic (BuiltinFunctions::ProhibitStringyEval)
if(eval('require Cache::Memcached::Fast')) {
print " Cache::Memcached::Fast available.\n";
$memdtype = "Cache::Memcached::Fast";
$memd = Cache::Memcached::Fast->new ({
servers => [ $self->{service} ],
namespace => $self->{namespace} . "::",
connect_timeout => 0,
});
$memd_loaded = 1;
$self->{mctype} = "fast";
} elsif(eval('require Cache::Memcached')) {
print " No Cache::Memcached::Fast ... falling back to C
+ache::Memcached\n";
$memdtype = "Cache::Memcached";
$memd = Cache::Memcached->new ({
servers => [ $self->{service} ],
namespace => $self->{namespace} . "::",
connect_timeout => 0,
});
$memd_loaded = 1;
$self->{mctype} = "slow";
} else {
print " No Cache::Memcached* available ... will try to
+use Maplat::Helpers::Cache::Memcached\n";
}
}
This just looks up which Memcached modules are available and tries to load one of those.
Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.