File Coverage

lib/Workflow/Condition/Nested.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Workflow::Condition::Nested;
2              
3 1     1   7 use strict;
  1         2  
  1         29  
4 1     1   5 use warnings;
  1         8  
  1         40  
5              
6             our $VERSION = '1.62';
7              
8 1     1   6 use base qw( Workflow::Condition );
  1         6  
  1         158  
9              
10             1;
11              
12             __END__
13              
14             =pod
15              
16             =head1 NAME
17              
18             Workflow::Condition::Nested - Evaluate nested workflow conditions
19              
20             =head1 VERSION
21              
22             This documentation describes version 1.62 of this package
23              
24             =head1 DESCRIPTION
25              
26             Typically, the workflow conditions are evaluated directly by the framework
27             in Workflow::State when the action is evaluated. This module allows
28             a workflow condition to contain nested conditions that are evaluated
29             directly rather than via separate workflow actions.
30              
31             This allows the workflow to be designed to group multiple conditions
32             and perform advanced operations like an OR comparision of multiple
33             conditions with "greedy" evaluation (as opposed to "lazy" evaluation).
34              
35             A usage example might be a case where 3 of 5 possible approvals are needed
36             for an action to be allowed. The "Greedy OR" condition would define the
37             list of conditions to be evaluated. After checking each condition, it would
38             return the total number of successes. The result is then checked against
39             the number needed, returning the boolean value needed by Workflow::State.
40              
41             B<Note:> This class is not used directly, but subclassed by your class
42             that implements the C<evaluate()> method and calls the C<evaluate_condition>
43             method to evaluate its nested conditions.
44              
45             =head1 SYNOPSIS
46              
47             In condition.xml:
48              
49             <condition name="cond1" ... />
50             <condition name="cond2" ... />
51             <condition name="cond3" ... />
52             <condition name="cond4" ... />
53             <condition name="cond5" ... />
54              
55             <condition name="count_approvals" class="Workflow::Condition::GreedyOR">
56             <param name="condition" value="cond1" />
57             <param name="condition" value="cond2" />
58             <param name="condition" value="cond3" />
59             <param name="condition" value="cond4" />
60             <param name="condition" value="cond5" />
61             </condition>
62              
63             <condition name="check_approvals" class="Workflow::Condition::CheckReturn">
64             <param name="condition" value="count_approvals" />
65             <!-- operator "ge" means: greater than or equal to -->
66             <param name="operator" value="ge" />
67             <param name="argument" value="$context->{approvals_needed}" />
68             </condition>
69              
70             In workflow.xml:
71              
72             <state name="CHECK_APPROVALS" autorun="yes">
73             <action name="null_1" resulting_state="APPROVED">
74             <condition name="check_approvals" />
75             </action>
76             <action name="null_2" resulting_state="REJECTED">
77             <condition name="!check_approvals" />
78             </action>
79             </state>
80              
81             =cut
82              
83             =head1 AUTHORS
84              
85             See L<Workflow>
86              
87             =head1 COPYRIGHT
88              
89             Copyright (c) 2004-2023 Chris Winters. All rights reserved.
90              
91             This library is free software; you can redistribute it and/or modify
92             it under the same terms as Perl itself.
93              
94             Please see the F<LICENSE>
95              
96             =head1 AUTHORS
97              
98             Please see L<Workflow>
99              
100             =cut