RollyGuy has asked for the wisdom of the Perl Monks concerning the following question:
A coworker and I are looking at an inheritance problem here at work. We have a particular class used for settings. For our parent class, we have several package variables that correspond to global settings. Children modules would then add specific settings for their instances.
The problem comes into play when we want to access the global or common settings. The functionality we would like is that of C++ static variables where any class can change the variable and it is visible to all.
Is there some way to mimic this functionality in perl?
To be specific, suppose we have a parent class A with setting "knob1". We would access this normally with:
$A::knob1
If we have a module B that inherits from A, we would like to be able to change knob1 in the following way:
$B::knob1 = 0;
And have $A::knob1 be automatically updated.
Then we get even more complex with another child of A, say, module C. Module B and Module C are at the same level and share module A as an ancestor. But a change in module C to a globally (inherited) setting should be visible in module B.
Any ideas?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Static Variables in Perl
by friedo (Prior) on Mar 30, 2006 at 20:24 UTC | |
by Tanktalus (Canon) on Mar 30, 2006 at 20:32 UTC | |
Re: Static Variables in Perl
by herveus (Prior) on Mar 30, 2006 at 20:51 UTC | |
by benizi (Hermit) on Apr 01, 2006 at 07:00 UTC | |
Re: Static Variables in Perl
by Anonymous Monk on Mar 30, 2006 at 23:03 UTC | |
Re: Static Variables in Perl
by Herkum (Parson) on Mar 31, 2006 at 00:35 UTC | |
Re: Static Variables in Perl
by benizi (Hermit) on Mar 31, 2006 at 22:36 UTC |