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
In reply to Re: Loading a different Module depending on the Configuration
by tachyon
in thread Loading a different Module depending on the Configuration
by skazat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |