line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Workflow::Condition::LazyOR; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.62'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use base qw( Workflow::Condition::Nested ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
122
|
|
9
|
1
|
|
|
1
|
|
17
|
use Workflow::Exception qw( condition_error configuration_error ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
10
|
1
|
|
|
1
|
|
6
|
use English qw( -no_match_vars ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('conditions'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _init { |
16
|
2
|
|
|
2
|
|
4
|
my ( $self, $params ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This is a tricky one. The admin may have configured this by repeating |
19
|
|
|
|
|
|
|
# the param name "condition" or by using unique names (e.g.: "condition1", |
20
|
|
|
|
|
|
|
# "condition2", etc.). We'll need to string these back together as |
21
|
|
|
|
|
|
|
# an array. |
22
|
|
|
|
|
|
|
# Yes, I know. The regex doesn't require the suffix to be numeric. |
23
|
2
|
|
|
|
|
3
|
my @conditions = (); |
24
|
2
|
|
|
|
|
3
|
foreach my $key ( sort grep {m/^condition/} keys %{$params} ) { |
|
9
|
|
|
|
|
27
|
|
|
2
|
|
|
|
|
8
|
|
25
|
5
|
|
|
|
|
18
|
push @conditions, $self->normalize_array( $params->{$key} ); |
26
|
|
|
|
|
|
|
} |
27
|
2
|
|
|
|
|
7
|
$self->conditions( [@conditions] ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub evaluate { |
32
|
4
|
|
|
4
|
1
|
9
|
my ( $self, $wf ) = @_; |
33
|
4
|
|
|
|
|
12
|
my $conditions = $self->conditions; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
48
|
my $total = 0; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
8
|
foreach my $cond ( @{$conditions} ) { |
|
4
|
|
|
|
|
10
|
|
38
|
8
|
|
|
|
|
37
|
my $result = $self->evaluate_condition( $wf, $cond ); |
39
|
8
|
100
|
|
|
|
202
|
if ($result) { |
40
|
2
|
|
|
|
|
6
|
return $result; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
2
|
|
|
|
|
10
|
condition_error("All nested conditions returned 'false'"); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Workflow::Condition::LazyOR |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This documentation describes version 1.62 of this package |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Using nested conditions (See Workflow::Condition::Nested), this evaluates |
63
|
|
|
|
|
|
|
the given conditions using lazy-evaluation, returning I<true> at the first |
64
|
|
|
|
|
|
|
nested condition that returns I<true>. If all nested conditions return |
65
|
|
|
|
|
|
|
I<false>, LazyOR also returns I<false>. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
In condition.xml: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
<condition name="cond1" ... /> |
72
|
|
|
|
|
|
|
<condition name="cond2" ... /> |
73
|
|
|
|
|
|
|
<condition name="cond3" ... /> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
<condition name="check_prereqs" class="Workflow::Condition::LazyOR"> |
76
|
|
|
|
|
|
|
<param name="condition" value="cond1" /> |
77
|
|
|
|
|
|
|
<param name="condition" value="cond2" /> |
78
|
|
|
|
|
|
|
<param name="condition" value="cond3" /> |
79
|
|
|
|
|
|
|
</condition> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
In workflow.xml: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
<state name="CHECK_PREREQS" autorun="yes"> |
84
|
|
|
|
|
|
|
<action name="null_1" resulting_state="HAVE_PREREQS"> |
85
|
|
|
|
|
|
|
<condition name="check_prereqs" /> |
86
|
|
|
|
|
|
|
</action> |
87
|
|
|
|
|
|
|
<action name="null_2" resulting_state="FAILURE"> |
88
|
|
|
|
|
|
|
<condition name="!check_prereqs" /> |
89
|
|
|
|
|
|
|
</action> |
90
|
|
|
|
|
|
|
</state> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 PARAMETERS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The following parameters may be configured in the C<param> entity of the |
97
|
|
|
|
|
|
|
condition in the XML configuration: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 condition, conditionN |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The condition parameter may be specified as either a list of repeating |
102
|
|
|
|
|
|
|
entries B<or> with a unique integer appended to the I<condition> string: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
<param name="condition" value="first_condition_to_test" /> |
105
|
|
|
|
|
|
|
<param name="condition" value="second_condition_to_test" /> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
B<or> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
<param name="condition1" value="first_condition_to_test" /> |
110
|
|
|
|
|
|
|
<param name="condition2" value="second_condition_to_test" /> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Copyright (c) 2003-2023 Chris Winters. All rights reserved. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
117
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Please see the F<LICENSE> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHORS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Please see L<Workflow> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |