File Coverage

blib/lib/Workflow/Condition/HasUser.pm
Criterion Covered Total %
statement 21 22 95.4
branch 1 2 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 31 35 88.5


line stmt bran cond sub pod time code
1             package Workflow::Condition::HasUser;
2              
3 14     14   290407 use warnings;
  14         37  
  14         1144  
4 14     14   93 use strict;
  14         30  
  14         460  
5 14     14   195 use v5.14.0;
  14         72  
6              
7 14     14   94 use parent qw( Workflow::Condition );
  14         32  
  14         151  
8              
9             $Workflow::Condition::HasUser::VERSION = '2.09';
10              
11             my $DEFAULT_USER_KEY = 'current_user';
12              
13             sub init {
14 15     15 1 47 my ( $self, $params ) = @_;
15 15   33     112 my $key_name = $params->{user_key} || $DEFAULT_USER_KEY;
16 15         175 $self->SUPER::init( $params );
17              
18 15         266 $self->param( user_key => $key_name );
19             }
20              
21             sub evaluate {
22 2     2 1 8 my ( $self, $wf ) = @_;
23 2         25 $self->log->debug( "Trying to execute condition ", ref $self );
24 2         352 my $user_key = $self->param('user_key');
25 2         12 my $current_user = $wf->context->param($user_key);
26 2         7 $self->log->debug( "Current user in the context is '$current_user' retrieved ",
27             "using parameter key '$user_key'" );
28              
29 2 50       90 return Workflow::Condition::IsTrue->new() if($current_user);
30 0           return Workflow::Condition::IsFalse->new();
31             }
32              
33             1;
34              
35             __END__
36              
37             =pod
38              
39             =head1 NAME
40              
41             Workflow::Condition::HasUser - Condition to determine if a user is available
42              
43             =head1 VERSION
44              
45             This documentation describes version 2.09 of this package
46              
47             =head1 SYNOPSIS
48              
49             # First setup the condition
50              
51             condition:
52             - name: HasUser
53             class: Workflow::Condition::HasUser
54             param:
55             - name: user_key
56             value: CurrentUser
57              
58             # Next, attach it to an action
59              
60             state:
61             - name: INITIAL
62             action:
63             - name: 'create issue'
64             resulting_state: CREATED
65             condition:
66             - name: CurrentUser
67             ...
68              
69             # Whenever you fetch available actions from state 'INITIAL' you must
70             # have the key 'CurrentUser' defined in the workflow context
71              
72             =head1 DESCRIPTION
73              
74             Simple -- possibly too simple -- condition to determine if a user
75             exists in a particular context key. Actually, it really only
76             determines if B<something> exists in a key, but we needed a simple
77             condition to ship with the module.
78              
79             =head2 Parameters
80              
81             You can configure the condition with the following parameters:
82              
83             =over 4
84              
85             =item *
86              
87             B<user_key>, optional
88              
89             Key in workflow context to check for data. If not specified we use
90             'current_user'.
91              
92             =back
93              
94             =head2 METHODS
95              
96             =head3 evaluate ( $wf )
97              
98             Method to evaluate whether a user has been set for a workflow.
99              
100             Takes a workflow object as parameter
101              
102             Throws L<Workflow::Exception> if evaluation fails
103              
104             =head1 SEE ALSO
105              
106             =over
107              
108             =item * L<Workflow::Condition>
109              
110             =back
111              
112             =head1 COPYRIGHT
113              
114             Copyright (c) 2004-2021 Chris Winters. All rights reserved.
115              
116             This library is free software; you can redistribute it and/or modify
117             it under the same terms as Perl itself.
118              
119             Please see the F<LICENSE>
120              
121             =head1 AUTHORS
122              
123             Please see L<Workflow>
124              
125             =cut