Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Best way to dynamically use a .pm?

by cavac (Parson)
on Nov 28, 2011 at 21:47 UTC ( [id://940476]=note: print w/replies, xml ) Need Help??


in reply to Best way to dynamically use a .pm?

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://940476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found