Hi Perl Monks, I have some existing code which carries out some special tasks. These tasks have different set of combinations available and on top of that API user (another coder/normal user) may want to customize it let say by doing some actions between consecutive tasks. I would need your suggestions to write good code to do the job. Below is an example of issue above and couple of solutions in my mind.
Issue in detail: Let say we have 4 major tasks: A, B, C, D such that following combinat +ions are considered valid: 1) A->B->C->D 2) A->C->D 3) A->B->C 4) A->D and so on. On top of that, we would like to allow users to customize the flow of +tasks as following: 1) A->myOperations->D 2) A->preTaskDoperations->D->postTaskDoperations. Currently, I have support for user flow without this customization lik +e 1) A->B->C->D 2) A->C->D 3) A->B->C 4) A->D and so on. Note: same was mentioned above earlier.
To support user customization for flows of tasks, I am wondering following: Approach one:
<!--Make an xml file something like below--> <xmlFile> <action name="A" execute="true"> </action> <action name="B" execute="true"> <arguments> <arg name="endToEnd" value="true"/> </arguments> <preTasks> <!--thinking of making this as text--> $ENV{skipActions}='true'; makeAServerdown(); <!--this can be later executed with exec function--> </preTasks> <postTasks> checkBServer(); </postTasks> </action> </xmlFile>
Approach two:
Object Oriented approach. 1) make code file which has such customized details. (derived class) 2) provide override mechanism to end user. 3) support flow of tasks like mentioned in xml but remove perl code fr +om there. There are several alternatives to do this which maybe as si +mple as reading properties file.
So after having read above, could you please suggest any improvements/alternate mechanism to handle the use case? Also, are there any existing apis which support mix of xml/perl? Thanks in advance.

Ps: Based on queries from perl monks, sharing real life example below:

let say you are in automobile factory: buildFrame->addSeats->addMechanicalParts->addDoors->paintCar->touchUp

Today let say we have following flow: 1) buildFrame->addSeats->addMechanicalParts->addDoors->paintCar->touchUp 2) buildFrame->addSeats->addMechanicalParts->paintCar->touchUp

Tomorrow, I want to expand my factory to handle following: (can be on request basis also):

new cases: 1) buildFrame->addSeats->postAddSeatsTask->addMechanicalParts->paintCar->touchUp this postAddSeatsTask maybe like replacing existing seats with leather seats. Note: only few people want it and changing whole assembly line for few people is expensive. few customers may want this and some may want something different like more leg space shorter seats. So customization is different for both and can not be predicted in advance that we provide them an API. some may want to fit couch from some company. so we may provide plug and play feature too.

I hope this gives a sense that customizations are many and with plug and play more or less things should be fine.

Above was for customization but yes tomorrow flow can change, company decides we wont paint car during production phase. but only before delivering to customer. So they remove that step and add it later changing flow of steps as below: buildFrame->addSeats->postAddSeatsTask->addMechanicalParts->touchUp->paintCar.

I hope this covers that flow needs to be flexible and steps may be added or removed as product changes.


In reply to handling tasks and customizing flow of tasks using perl by asham

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.