|Syntactic Confectionery Delight|
Reconfiguration of classes in an "inheritable" mannerby Amblikai (Scribe)
|on Jun 23, 2022 at 20:03 UTC||Need Help??|
Amblikai has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks! I'm looking for a bit of help, as someone who codes perl in isolation. Prefacing this with the fact i'm no programmer.
I've somewhat organically arrived upon my own little OO framework which i use for most things. It has grown in complexity a bit over the years and i'm now wondering if i'm just re-inventing the wheel, especially since i'm starting to get confused by my own code!
I can't use Moose or any of the more advanced frameworks, i'm stuck with pretty basic perl unfortunately
Essentially i have a structure of classes which allows me to dictate the way attributes are handled when creating downstream objects. I can explicitly define which attributes are allowed, what are valid values, and the behaviour around unknown/undefined attributes (drop the attribute, give a warning, error out etc
The way i'm doing this is starting to seem a bit messy, and i'm sure there's a better way. In the base class i maintain a configuration singleton. The singleton keeps a map of the derived class hierarchy, and when i set configuration options on a particular "level" of the hierarchy, it only affects from that point down, rather than reconfiguring the base class and hence the whole derived tree.
I'm probably going to struggle to illustrate it but here's a pseudocode example:
In essence, i'm doing all this to replicate a sort of "inheritable class variable". Is that something thats natively possible?
In other words, if my::extended_trunk has a class variable, can i change the value of it in my::branch_A, without it affecting the value in my::branch_B?
As always, i appreciate any help or guidance! Thanks!