Workflow/Condition.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 10 / 10 Conditioncond 81.8% 18 / 22 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 93.3% 113 / 121 CC 14 SCAR 21.2
CC
14
Cov
96%
evaluate_condition
14.1
BEGIN
1.0
BEGIN
1.0
CRAP 8.3
« Workflow/Persister/DBI/ExtraData.pm ↑ Summary Workflow/InputField.pm »
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
BranchTrueFalseTotal
ref $condition_or_name ? : 69 63 132
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
BranchTrueFalseTotal
ref $condition_or_name ? : 69 63 132
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'} || {}
l!l
11517
MC/DC100%1/1
$wf->{'_condition_result_cache'} || {}
$wf->{'_condition_result_cache'}
Truth table100%2/2
A
A= $wf->{'_condition_result_cache'}
Aresult
11
00
46  
47 132 ▶ if ( $Workflow::Condition::CACHE_RESULTS
Branch: 1 branch
BranchTrueFalseTotal
if ($Workflow::Condition::CACHE_RESULTS and exists $wf->{'_condition_result_cache'}{$condition_name}) { } 20 112 132
Condition100%3/3
$Workflow::Condition::CACHE_RESULTS and exists $wf->{"_condition_result_cache"}{$condition_name}
!ll&&!rl&&r
288420
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}
ABresult
0X0
100
111
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 || ''
l!l
812
MC/DC100%1/1
$cache_value || ''
$cache_value
Truth table100%2/2
A
A= $cache_value
Aresult
11
00
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)
l!l&&r!l&&!r
59530
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (ref $result eq 'Workflow::Condition::IsFalse' or not $Workflow::Condition::STRICT_BOOLEANS || $result) { } 53 58 111
elsif (ref $result eq 'Workflow::Condition::IsTrue' or not $Workflow::Condition::STRICT_BOOLEANS and $result) { } 56 2 58
Condition100%6/6
ref $result eq "Workflow::Condition::IsFalse" or not $Workflow::Condition::STRICT_BOOLEANS || $result
l!l&&r!l&&!r
51258
$Workflow::Condition::STRICT_BOOLEANS || $result
l!l&&r!l&&!r
5532
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
ABCresult
1XX1
0001
01X0
0010
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
l!l&&r!l&&!r
5602
not $Workflow::Condition::STRICT_BOOLEANS and $result
!ll&&!rl&&r
200
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
ABCresult
1XX1
0111
00X0
0100
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__
« Workflow/Persister/DBI/ExtraData.pm ↑ Summary Workflow/InputField.pm »