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