File Coverage

lib/Workflow/Condition/Negated.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 22 22 100.0


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