On Wed, 4 Jul 2001 12:41:06 -0400, Alex Page wrote:
> However, I'm trying to future-proof on this project, so
> I'd like some optional backend modules which can be swapped
> in by changing a single configuration line - for example,
> using an LDAP server instead of a database table for user
> password authentication and privileges.
>
> I've tried Exporter throwing
> functions all over the shop, I've tried object orienting
> until $cow->{'position'} == $home, and I still can't get it to
> work nicely. Any tips, suggestions, methodologies?
Objects are definitely what you want. Write your authentication modules as
classes with the same interface. Your configuration file tells your scripts
which one to load, like this:
sub new_auth_obj{
# $config is a hash of stuff read from your config file
my $config=shift;
my $auth_type=$config->{auth_type} || 'Database';
# Load the appropriate module, if it's not already loaded
my $pkg="MyApp::Auth::$auth_type";
if(!do{ no strict refs; ${"${pkg}::VERSION"}; }){
eval "require $pkg;"
or die "some horrible death: $@";
}
# Create the object
$pkg->new(@_);
}
--
Peter Haworth [EMAIL PROTECTED]
"Genetic engineering raises all kinds of unanswerable moral and ethical
questions. Maybe in the future we'll be able to breed super intelligent
gibbons to answer them" -- Alexei Sayle