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

OK. So I'm trying to take an OO approach to a problem that I have been unable to solve well in a procedural way. It is a scheduling system and I am trying to create an appointment object which will have many different sub classes.

The way I see it, the best way to approach it, since it will be a web driven system and information will come at it it many different ways and forms and in different order, I need to make it smart enough to complete itself. What I mean is that it will need to be able to determine its own state across instantiations and figure out where it has been and where it is going. So what I thought of (I have written no code yet - just in basic design stage) is having the constructor populate a hash. Lacking some very basic info (an ID from a DB sequence which would only not be there if there was an error and the type of appointment this is which is determined by what starting point the user has chosen and would also determine the objects sub-class) the constructor would fail. If it has the most basic info it attempts to shift off a whole bunch of other pieces of info. It then would look at this hash, see what it is missing, (here's the part I really need help on) determine what it needs based on what it has through some meta-data construct and then set a $state. I could then use that $appt->state as a guide for what form to throw up to the user to get the next piece of info it needs to be complete. I would then spit out the info the object already has to be put into hidden fields in the HTML and suck it all back up and do it again when the user fills out the form and submits the next piece of info.

I'm pretty sure I can do all of that. My questions are:

I thank everyone in advance for helping me sort this out. I know I should read Damian Conway's book, but I really wont have a chance until after this crunch. I have read perltoot and that rocks.

"A man's maturity -- consists in having found again the seriousness one had as a child, at play." --Nietzsche

Replies are listed 'Best First'.
Re: storing meta-data for an object
by ichimunki (Priest) on Dec 20, 2000 at 02:34 UTC
    Hopefully the following advice will be sensible regarding the information in hidden fields. If you already have this information on your server, you might consider schemes for keeping it there, and simply matching the two halves back up once you get more information from the client. This prevents tampering and accidents. It also means you only need to parse it once.

    As to the data point tracking:
    $hash{'nodes'} = { "test_one" => [ "state_one", "foo", "bar" ], "test_two" => [ "state_two", "phu", "bah" ] }; foreach $nodekey ( keys %{$hash{'nodes'}} ) { $checkstate = $hash{'nodes'}{$nodekey}[0]; print "state of $nodekey = $checkstate\n"; }
    (with nods to page 13, The Camel, 3rd Edition).

    I'm sure you could also pack an anonymous hash reference instead of those list refs, if you had enough elements that it made sense to be able to call them by name instead of [x].