in reply to Loading a different Module depending on the Configuration
Here is a different way to do it
my $DB; $DB = new TheDB('SQL'); $DB->fetch(); $DB = new TheDB('Text'); $DB->fetch(); $DB->{'DB'} = 'SQL'; $DB->fetch(); $DB = $DB->new('Text'); $DB->fetch(); $DB = new TheDB('Oracle'); $DB->fetch(); package TheDB; use strict; sub new { my ($proto, $DB) = @_; my $class = ref($proto) || $proto; my $self = {'DB' => $DB}; bless $self, $class; return $self; } sub fetch { if ($_[0]->{'DB'} eq 'SQL') { &_SQL_fetch(@_); } elsif ($_[0]->{'DB'} eq 'Text') { &_Text_fetch(@_); } else { die "Unknown class ".$_[0]->{'DB'}; } } sub _SQL_fetch { print "Using SQL method\n"; } sub _Text_fetch { print "Using Text method\n"; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Loading a different Module depending on the Configuration
by skazat (Chaplain) on Sep 27, 2001 at 09:04 UTC |