in reply to Re^2: Inheritable configuration options.... but with default values?
in thread Inheritable configuration options.... but with default values?

You are using package variables (what other languages call static) and in your update you have the right syntax. If you had an object, the way to access its parent's package variable is stated in perlobj, at the place you quoted it: for a static method: $self->SUPER::save(); and for a package variable %{$self->SUPER::cfg};

But package variables are not "object variables" or member variables (?whatever?). It would be better to store %cfg into $self's hash for at least one reason: inheritance is taken care by Perl for free. Whereas in your case, Perl takes care of the inheritance of Class1 into Class2 and YOU MUST (not forget to) take care of the inheritance of Class1's package variables. That's a lot of boiler work (for me ;) ).

related: https://stackoverflow.com/questions/3109672/how-to-make-a-hash-available-in-another-module and Perl Inheritance & module variables . The latter in particular is similar to what you have shown.

Replies are listed 'Best First'.
Re^4: Inheritable configuration options.... but with default values?
by LanX (Saint) on Feb 21, 2020 at 00:24 UTC
    > But package variables are not "object variables" or member variables (?whatever?)

    yeah, but I tought that's what the OP asked for !?!

    > > > Basically i have a series of classes and subclasses, each level adding a bit more functionality to its parent and in each class i have behaviour which can be modified by configuration options which are specific to that class

    see? Class not Object.

    > That's a lot of boiler work (for me ;) ).

    Well my code was shorter than yours. ;)

    (...and I'm sure this could be even shortened further with some sugar)

    > and for a package variable %{$self->SUPER::cfg};

    I doubt it, according to the docs cfg here - i.e. the part after SUPER:: - must be a sub in the super class.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery