| 1 | package Workflow::Condition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use parent qw( Workflow::Base ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use v5.14.0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Log::Any qw( $log ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Workflow::Exception qw( workflow_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 35 | ▶ | use Workflow::Condition::IsFalse; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 35 | ▶ | use Workflow::Condition::IsTrue; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 35 | $Workflow::Condition::CACHE_RESULTS = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 35 | $Workflow::Condition::VERSION = '2.12'; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 35 | $Workflow::Condition::STRICT_BOOLEANS = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 35 | my @FIELDS = qw( name class ); | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 35 | __PACKAGE__->mk_accessors(@FIELDS); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 70 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 70 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 70 | $self->name( $params->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 70 | $self->class( $params->{class} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | croak "Class ", ref($self), " must implement 'evaluate()'!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 132 | ▶ | sub evaluate_condition { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate_condition: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 132 | my ( $class, $wf, $condition_or_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 132 | $wf->type; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 132 | my $factory = $wf->_factory(); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 132 | ▶ | my $condition_name = | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | (ref $condition_or_name) ? $condition_or_name->name : $condition_or_name; | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 132 | ▶ | my $condition = (ref $condition_or_name) ? $condition_or_name : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 132 | $log->debug("Checking condition $condition_name"); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | local $wf->{'_condition_result_cache'} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 132 | ▶ | $wf->{'_condition_result_cache'} || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$wf->{'_condition_result_cache'} || {}
MC/DC100%1/1
$wf->{'_condition_result_cache'} || {}
$wf->{'_condition_result_cache'}
Truth table100%2/2
A
A= $wf->{'_condition_result_cache'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 132 | ▶ | if ( $Workflow::Condition::CACHE_RESULTS | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Workflow::Condition::CACHE_RESULTS and exists $wf->{"_condition_result_cache"}{$condition_name}
MC/DC100%2/2
$Workflow::Condition::CACHE_RESULTS and exists $wf->{"_condition_result_cache"}{$condition_name}
$Workflow::Condition::CACHE_RESULTS
exists $wf->{"_condition_result_cache"}{$condition_name}
Truth table100%3/3
A and B
A= $Workflow::Condition::CACHE_RESULTSB= exists $wf->{"_condition_result_cache"}{$condition_name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | && exists $wf->{'_condition_result_cache'}->{$condition_name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | my $cache_value = $wf->{'_condition_result_cache'}->{$condition_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | # The condition has already been evaluated and the result | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # has been cached | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | ▶ | $log->debug( | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache_value || ''
MC/DC100%1/1
$cache_value || ''
$cache_value
Truth table100%2/2
A
A= $cache_value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | "Condition has been cached: '$condition_name', cached result: ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $cache_value || '' | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 20 | return $cache_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # we did not evaluate the condition yet, we have to do | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # it now | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 112 | ▶ | $condition //= $wf->_factory() | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$condition //= $wf->_factory->get_condition($condition_name, $wf->type)
MC/DC0%0/2
$condition //= $wf->_factory->get_condition($condition_name, $wf->type)
$condition
$wf->_factory->get_condition($condition_name, $wf->type)
Truth table66%2/3
A //= B
A= $conditionB= $wf->_factory->get_condition($condition_name, $wf->type)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ->get_condition( $condition_name, $wf->type ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 112 | $log->debug( "Evaluating condition '$condition_name'" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 112 | my $return_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 112 | my $result = $condition->evaluate($wf); | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 111 | ▶ | if (ref $result eq 'Workflow::Condition::IsFalse' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
ref $result eq "Workflow::Condition::IsFalse" or not $Workflow::Condition::STRICT_BOOLEANS || $result
$Workflow::Condition::STRICT_BOOLEANS || $result
MC/DC100%3/3
ref $result eq "Workflow::Condition::IsFalse" or not $Workflow::Condition::STRICT_BOOLEANS || $result
ref $result eq "Workflow::Condition::IsFalse"
$Workflow::Condition::STRICT_BOOLEANS
$result
Truth table100%4/4
A or not(B || C)
A= ref $result eq "Workflow::Condition::IsFalse"B= $Workflow::Condition::STRICT_BOOLEANSC= $result
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | or (not $Workflow::Condition::STRICT_BOOLEANS and not $result)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 53 | $log->info( "Got false result with '$result' on '$condition_name'"); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 53 | $return_value = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | ▶ | } elsif (ref $result eq 'Workflow::Condition::IsTrue' | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
ref $result eq "Workflow::Condition::IsTrue" or not $Workflow::Condition::STRICT_BOOLEANS and $result
not $Workflow::Condition::STRICT_BOOLEANS and $result
MC/DC33%1/3
ref $result eq "Workflow::Condition::IsTrue" or not $Workflow::Condition::STRICT_BOOLEANS and $result
ref $result eq "Workflow::Condition::IsTrue"
not $Workflow::Condition::STRICT_BOOLEANS
$result
Truth table50%2/4
A or not(B) and C
A= ref $result eq "Workflow::Condition::IsTrue"B= not $Workflow::Condition::STRICT_BOOLEANSC= $result
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | or (not $Workflow::Condition::STRICT_BOOLEANS and $result)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 56 | $log->info( "Got true result with '$result' on '$condition_name'"); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 56 | $return_value = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | $log->fatal( "Evaluate on '$condition_name' did not return a valid result object" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | $log->trace( 'Eval result', { result => $result } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | croak "Evaluate on '$condition_name' did not return a valid result object"; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 109 | $wf->{'_condition_result_cache'}->{$condition_name} = $return_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 109 | return $return_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 35 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||