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