[Perl-workflow-devel] Patch - Workflow::Condition::Nested
Brought to you by:
jonasbn
From: Scott H. <sco...@hn...> - 2012-10-17 13:55:53
|
Hi Jonas, While working on designing a new workflow for OpenXPKI, we ran into the situation where we had a confusingly large number of conditions and states all tied together in a big mess. As an example, this new workflow of ours has a variable number of approvals from multiple sources: administrators manually giving their 'OK', but also things like the correct status of the device in a database counted as an "automatic" approval. The certificate is then only issued if, for example, at least 3 of the 5 possible approvals are found. What we created is the notion of "Nested" conditions. Basically, the new Workflow::Condition::Nested class can evaluate other conditions directly without having to create a complex chain of workflow states, actions and conditions. In the example above, we created two of these new conditions: The first condition, Workflow::Condition::GreedyOR, takes a list of condition names as parameters and does a logical OR test on the whole list. In contrast to a lazy-evaluation, though, it actually evaluates _all_ of the conditions and returns the count of true values. Again, the evaluation of these child conditions is done directly in this condition. The second condition, Workflow::Condition::CheckReturn, is the condition that is actually configured to be associated with a workflow activity at a particular workflow state (the other "child" conditions are merely <condition .../> entities not directly attached to activities). This CheckReturn specifies the name of the condition using the GreedyOR class and evaluates it's return value. The result is then compared with a context value to see if the policy for the number of required approvals is met. Attached is a patch that should be able to be cleanly applied with or without Oliver's patches. With best regards, Scott |