File Coverage

lib/Workflow/Condition/HasUser.pm
Criterion Covered Total %
statement 18 25 72.0
branch 0 2 0.0
condition 1 3 33.3
subroutine 6 7 85.7
pod 1 1 100.0
total 26 38 68.4


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