File Coverage

blib/lib/Workflow/Condition/Negated.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Workflow::Condition::Negated;
2              
3 29     29   192451 use warnings;
  29         62  
  29         2025  
4 29     29   180 use strict;
  29         109  
  29         833  
5 29     29   359 use v5.14.0;
  29         108  
6              
7             our $VERSION = '2.09';
8              
9 29     29   176 use parent qw( Workflow::Condition );
  29         58  
  29         198  
10              
11             my @FIELDS = qw( name class negated );
12             __PACKAGE__->mk_accessors(@FIELDS);
13              
14             sub init {
15 9     9 1 32 my ( $self, $params ) = @_;
16 9         29 my $negated = $params->{name};
17 9         68 $self->SUPER::init( $params );
18              
19 9         168 $negated =~ s/ \A ! //gx;
20 9         42 $self->negated( $negated );
21             }
22              
23             sub evaluate {
24 39     39 1 104 my ($self, $wf) = @_;
25 39 100       169 if ($self->evaluate_condition($wf, $self->negated)) {
26 12         91 return Workflow::Condition::IsFalse->new();
27             } else {
28 26         208 return Workflow::Condition::IsTrue->new();
29             }
30             }
31              
32              
33             1;
34              
35             __END__
36              
37             =pod
38              
39             =head1 NAME
40              
41             Workflow::Condition::Negated - Negate workflow condition result
42              
43             =head1 VERSION
44              
45             This documentation describes version 2.09 of this package
46              
47             =head1 DESCRIPTION
48              
49             This class is used by C<Workflow::State> to handle I<negated conditions>:
50             conditions of which the referring name starts with an exclamation mark (!).
51              
52             Such conditions refer to another condition (by the name after the '!') and
53             return the negated result of the condition referred to (true becomes false
54             while false becomes true).
55              
56             =head1 SYNOPSIS
57              
58             In condition.yaml:
59              
60             condition:
61             - name: check_approvals
62             class: ...
63              
64             In workflow.yaml:
65              
66              
67             state:
68             - name: CHECK_APPROVALS
69             autorun: yes
70             condition:
71             - name: null_1
72             resulting_state: APPROVED
73             condition:
74             - name: check_approvals
75             - name: null_2
76             resulting_state: REJECTED
77             condition:
78             - name: !check_approvals
79              
80             =cut
81              
82             =head1 AUTHORS
83              
84             See L<Workflow>
85              
86             =head1 COPYRIGHT
87              
88             Copyright (c) 2004-2021 Chris Winters. All rights reserved.
89              
90             This library is free software; you can redistribute it and/or modify
91             it under the same terms as Perl itself.
92              
93             Please see the F<LICENSE>
94              
95             =head1 AUTHORS
96              
97             Please see L<Workflow>
98              
99             =cut