File Coverage

lib/Workflow/Condition/LazyAND.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 1 1 100.0
total 43 45 95.5


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