Ovid has asked for the wisdom of the Perl Monks concerning the following question:
Let's say I'm using some module, Foo (which I did not write). At the top of the module, we see stuff like the following:
package Foo; $Foo::VERSION='3.02'; sub set_globals { $DEBUGGING = 0; $LOG_ERROR = 0; $ERR_MIN = 20; $DEFAULT_XFR = 'G0023'; } set_globals(); #... more code ...
This is actually an OO module that I need to use as a base class, but I want to make sure that I safely override those globals with my own values.
################################ package Bar; ################################ $VERSION = 1.0; use strict; use Foo; use vars qw/ @ISA /; @ISA = qw/ Foo /; INIT { $Foo::LOG_ERROR = 1; $Foo::ERR_MIN = 20; $Foo::DEFAULT_XFR = 'H00293'; } sub new { my ( $class, $args ) = @_; # etc...
Naturally, in my own code, I have:
use strict; use Foo::Bar; my $obj = Foo::Bar->new;
What I was wondering is whether or not I could alter the contents of those globals at the time that I use Foo::Bar. For instance, perhaps I want to set $Foo::LOG_ERROR to 0, I might want a statement like this:
use Foo::Bar qw/noLog/;
The above would ideally be able to change several globles to match whatever configuration is needed at run-time. To compound things, the base class, Foo, has subs that can be called as OO methods or functions, so I can't try any trickery in the new constructor as I cannot guarantee that it will be called.
I know this sounds a bit strange, but the author of Foo has requested that my subclass have a way to set those globals at load time. Any ideas welcome.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Setting Globals in a Base Class
by dragonchild (Archbishop) on Nov 07, 2001 at 00:58 UTC | |
by Ovid (Cardinal) on Nov 07, 2001 at 02:36 UTC | |
by tilly (Archbishop) on Nov 07, 2001 at 20:33 UTC | |
by Ovid (Cardinal) on Nov 07, 2001 at 20:54 UTC | |
|
Re: Setting Globals in a Base Class
by perrin (Chancellor) on Nov 07, 2001 at 01:50 UTC | |
by Ovid (Cardinal) on Nov 07, 2001 at 03:14 UTC | |
by Aristotle (Chancellor) on Nov 07, 2001 at 15:14 UTC | |
|
Re: Setting Globals in a Base Class
by alien_life_form (Pilgrim) on Nov 07, 2001 at 15:14 UTC |