Workflow/Condition/Evaluate.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 96.3% 52 / 54 CC 4 SCAR 5.5
CC
4
Cov
95%
evaluate
3.0
init
2.1
BEGIN
1.0
CRAP 1.7
« Workflow/Condition/LazyOR.pm ↑ Summary Workflow/Validator/InEnumeratedType.pm »
1 package Workflow::Condition::Evaluate;
2  
3 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use parent qw( Workflow::Condition );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use Workflow::Exception qw( configuration_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 30 $Workflow::Condition::Evaluate::VERSION = '2.12';
11  
12 30 my @FIELDS = qw( test );
13 30 __PACKAGE__->mk_accessors(@FIELDS);
14  
15 # These get put into the safe compartment...
16 30 $Workflow::Condition::Evaluate::context = undef;
17  
18 26 ▶sub init {
Subroutine init: called CC=2 SCAR=7.2
Pod documented
19 26 my ( $self, $params ) = @_;
20 26 $self->SUPER::init( $params );
21  
22 26 $self->test( $params->{test} );
23 26 ▶ unless ( $self->test ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->test) 0 26 26
24 0 configuration_error
25 "The evaluate condition must be configured with 'test'";
26 }
27 26 $self->log->info("Added evaluation condition with '$params->{test}'");
28 }
29  
30 37 ▶sub evaluate {
Subroutine evaluate: called CC=3 SCAR=11.0
Pod documented
31 37 my ( $self, $wf ) = @_;
32  
33 37 my $to_eval = $self->test;
34 37 $self->log->info("Evaluating '$to_eval' to see if it returns true...");
35  
36 # Assign our local stuff to package variables...
37 37 $Workflow::Condition::Evaluate::context = $wf->context->param;
38  
39 # Create the Safe compartment and safely eval the test...
40 37 my $safe = Safe->new();
41  
42 37 $safe->share('$context');
43 37 local $@;
44 37 my $rv = $safe->reval($to_eval);
45  
46 37 ▶ $self->log->debug( "Safe eval ran ok, returned: '",
Branch: 1 branch
BranchTrueFalseTotal
defined $rv ? : 21 16 37
47 ( defined $rv ? $rv : '<undef>' ),
48 "'" );
49  
50 37 ▶ return $rv ?
Branch: 1 branch
BranchTrueFalseTotal
$rv ? : 10 27 37
51 Workflow::Condition::IsTrue->new() :
52 Workflow::Condition::IsFalse->new();
53 }
54  
55 30 1;
56  
57 __END__
« Workflow/Condition/LazyOR.pm ↑ Summary Workflow/Validator/InEnumeratedType.pm »