1Workflow::Action::InputUFsieerldC(o3n)tributed Perl DocuWmoernktfaltoiwo:n:Action::InputField(3)
2
3
4
6 Workflow::Action::InputField - Metadata about information required by
7 an Action
8
10 # Declare the fields needed by your action in the configuration...
11
12 <action name="CreateUser">
13 <field name="username"
14 is_required="yes"
15 source_class="App::Field::ValidUsers" />
16 <field name="email"
17 is_required="yes" />
18 <field name="office"
19 source_list="Pittsburgh,Hong Kong,Moscow,Portland" />
20 ...
21
23 A workflow Action can declare one or more input fields required to do
24 its job. Think of it as a way for the external world (your application)
25 to discover what information an action needs from it. The application
26 can request these fields from the workflow by action name and present
27 them to the user in whatever form appropriate for the application. The
28 sample command-line application shipped with this distribution just
29 cycles through them one at a time and presents a query to the user for
30 data entry.
31
32 For instance, in the above declaration there are three fields, 'user‐
33 name', 'email' and 'office'. So your application might do:
34
35 my @action_fields = $wf->get_action_fields( 'CreateUser' );
36 foreach my $field ( @action_fields ) {
37 print "Field ", $field->name, "\n",
38 $field->description, "\n",
39 "Required? ", $field->is_required, "\n";
40 my @enum = $field->get_possible_values;
41 if ( scalar @enum ) {
42 print "Possible values: \n";
43 foreach my $val ( @enum ) {
44 print " $val->{label} ($val->{value})\n";
45 }
46 }
47 print "Input? ";
48 my $response = <STDIN>;
49 chomp $response;
50 $wf->context->param( $field->name => $response );
51 }
52 $wf->execute_action( 'CreateUser' );
53
55 Public Methods
56
57 new( \%params )
58
59 Typical constructor; will throw exception if 'name' is not defined or
60 if the property 'source_class' is defined but the class it specifies is
61 not available.
62
63 is_required()
64
65 Returns 'yes' if field is required, 'no' if optional.
66
67 is_optional()
68
69 Returns 'yes' if field is optional, 'no' if required.
70
71 get_possible_values()
72
73 Returns list of possible values for this field. Each possible value is
74 represented by a hashref with the keys 'label' and 'value' which makes
75 it easy to create dropdown lists in templates and the like.
76
77 add_possible_values( @values )
78
79 Adds possible values to be used for this field. Each item in @values
80 may be a simple scalar or a hashref with the keys 'label' and 'value'.
81
82 #=head3 init
83
84 Properties
85
86 name (required)
87
88 Name of the field. This is what the action expects as the key in the
89 workflow context.
90
91 label (optional)
92
93 Label of the field. If not set the value for "name" is used.
94
95 description (optional)
96
97 What does the field mean? This is not required for operation but it is
98 strongly encouraged so your clients can create front ends to feed you
99 the information without much fuss.
100
101 type (optional)
102
103 TODO: Datatype of field (still under construction...). By default it is
104 set to 'basic'.
105
106 requirement ('required'⎪'optional')
107
108 If field is required, 'required', otherwise 'optional'.
109
110 source_class (optional)
111
112 If set the field will call 'get_possible_values()' on the class when
113 the field is instantiated. This should return a list of either simple
114 scalars or a list of hashrefs with 'label' and 'value' keys.
115
116 source_list (optional)
117
118 If set the field will use the specified comma-separated values as the
119 possible values for the field. The resulting list returned from
120 "get_possible_values()" will have the same value for both the 'label'
121 and 'value' keys.
122
124 Workflow::Action
125
127 Copyright (c) 2003-2004 Chris Winters. All rights reserved.
128
129 This library is free software; you can redistribute it and/or modify it
130 under the same terms as Perl itself.
131
133 Chris Winters <chris@cwinters.com>
134
135
136
137perl v5.8.8 2007-04-25 Workflow::Action::InputField(3)