Is it possible to change @EXPORT during runtime?


I'm trying to import subroutines in the following manner:

- I have a file called DBLib.pm which imports a file "DefaultLib.pm" via a
"use".


DBLib.pm
###############
package DBLib.pm

use strict ;
require Exporter ;
use DefaultLib  ;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter) ;


- DefaultLib.pm  explicitly sets @EXPORT = to a list of functions I want to
export into DBLib.pm

DefaultLib.pm
###############
package DefaultLib ;

use strict ;
require Exporter ;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter) ;
@EXPORT     = qw(&default_code) ;


- SybaseLib.pm, OracleLib.pm are set up the same way that DefaultLib.pm is
set up.


The overall question is that I want to be able to write a separate perl
script that makes a call to "use DBLib ;".
The DBLib.pm  file will have a section of code to test for an environment
variable of DBTYPE and determine which additional library to "use"
(SybaseLib.pm, OracleLib.pm, etc)...

When the database specific library gets imported (SybaseLib.pm) any
subroutine with the same name as a subroutine in DefaultLib.pm should get
redefined and use the one in SybaseLib.pm.  Additionally, to reference any
subroutine regardles of which pm file it actually exists in should be able
to be called from an outside script  by

use DBLib ;

# default code here would be (same for all db's)
&DBLib::default_code ;

# db specific code here (main script doesn't know  which db its connected
through)
&DBLib::add_user ;


This I hope can be accomplished by using the AUTOLOAD subroutine to check
for the existence of the subroutine being called and decide where to branch
to using the following sequence.

-look first in DBLib::
-next look in SybaseLib::   # (or whatever DBTYPE was set to)
-last look in DefaultLib::
-error and exit if the subroutine hasn't been found


The part that doesn't seem to work is that the functions from SybaseLib.pm
don't overlay any subroutines with the same name in DefaultLib.

So to simplify my question,  is what I'm trying to do possible?

I have tried many different approaches to accomplish this so, I have much
of the code written allready.  This is all very stripped down in hopes that
it would make more sense without too much detail at first.  Hope someone
out there can help.

Thanks,

Jeff

Reply via email to