Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found