File Coverage

lib/Workflow/Condition/LazyOR.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 41 41 100.0


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