| 1 | package Workflow::Condition::LazyAND; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use v5.14.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '2.12'; | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use parent qw( Workflow::Condition ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Workflow::Exception qw( configuration_error ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | __PACKAGE__->mk_accessors('conditions'); | |||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 15 | 2 | my ( $self, $params ) = @_; | |||||||||
| 16 | 2 | $self->SUPER::init( $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 | my @conditions = (); | |||||||||
| 24 | 2 | foreach my $key ( sort grep {m/^condition/} keys %{$params} ) { | |||||||||
| 25 | 5 | push @conditions, $self->normalize_array( $params->{$key} ); | |||||||||
| 26 | } | ||||||||||
| 27 | 2 | $self->conditions( [@conditions] ); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 4 | ▶ | sub evaluate { | ||||||||
|
Subroutine
evaluate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 31 | 4 | my ( $self, $wf ) = @_; | |||||||||
| 32 | 4 | my $conditions = $self->conditions; | |||||||||
| 33 | |||||||||||
| 34 | 4 | my $total = 0; | |||||||||
| 35 | |||||||||||
| 36 | 4 | ▶ | return Workflow::Condition::IsFalse->new("No conditions were defined") unless(@{$conditions}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 4 | foreach my $cond ( @{$conditions} ) { | |||||||||
| 39 | 8 | my $result = $self->evaluate_condition( $wf, $cond ); | |||||||||
| 40 | 8 | ▶ | if ( not $result ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 2 | return Workflow::Condition::IsFalse->new("Stopped after checking $total conditions"); | |||||||||
| 42 | } | ||||||||||
| 43 | 6 | $total++; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 2 | return Workflow::Condition::IsTrue->new("Matched a total of $total conditions"); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 2 | 1; | |||||||||
| 50 | |||||||||||
| 51 | __END__ | ||||||||||