metaperl has asked for the wisdom of the Perl Monks concerning the following question:

if you have a child class whose (Moose) constructor takes a constant, and you want the child and parent class to use the same set of constants, where do you put them so that both can use them, e.g:
package X; use X::Child; my $object = X::Child->new(mode => BETA); my $object2 = X::Child->new(mode => PROD);
but where and how would I package up the 'BETA' and 'PROD' constants for re-use in child and parent classes?

Replies are listed 'Best First'.
Re: sharing constants between base and derived classes
by merlyn (Sage) on Apr 20, 2009 at 17:12 UTC
    Magic constants should be provided by the class-side method call:
    my $object = X::Child->new(mode => X::Child->BETA);
    That way, if a child class needs to override it, it can.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.