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:

my::base # base class my::extended_trunk # extends base my::branch_A # extends "extended_trunk" my::branch_B # Also extends "extended_trunk" my::base->configure(options); # Options change in all Classe +s my::extended_trunk->configure(options); # Options only change in exten +ded_trunk and both branches my::branch_A->configure(options); # Options only change in branc +h_A

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!


In reply to Reconfiguration of classes in an "inheritable" manner by Amblikai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.