Since constants are routines, and you can get inheritance by calling them as a method, the bit has already been covered to death, there is a different attitude to things.
If you know that you work in only one file, you can use lexical constants to combine packages:
package Parent; our ($NO_LEVEL, $MY_LEVEL, $YOUR_LEVEL); *NO_LEVEL = \0;
If you don't need perl for die when assigning a constant, our
declaration gets a little easier (and maybe my
):
our ($NO_LEVEL, $MY_LEVEL, $YOUR_LEVEL) = (0, 1, 2);
You can return a permanent nature while still using a brief syntax with a little magic:
my $constant = sub {Internals::SvREADONLY($_[$_], 1) for 0 .. $#_}; package Parent; $constant->(our ($NO_LEVEL, $MY_LEVEL, $YOUR_LEVEL) = (0, 1, 2)); package Child;
You can, of course, omit $constant
coderef and embed magic:
package Parent; Internals::SvREADONLY($_, 1) for our ($NO_LEVEL, $MY_LEVEL, $YOUR_LEVEL) = (0, 1, 2);