1Workflow::Config(3) User Contributed Perl Documentation Workflow::Config(3)
2
3
4
6 Workflow::Config - Parse configuration files for the workflow
7 components
8
10 This documentation describes version 1.54 of this package
11
13 # Reference multiple files
14
15 my $parser = Workflow::Config->new( 'xml' );
16 my @config = $parser->parse(
17 'action', 'workflow_action.xml', 'other_actions.xml'
18 );
19
20 # Read in one of the file contents from somewhere else
21 my $xml_contents = read_contents_from_db( 'other_actions.xml' );
22 my @config = $parser->parse(
23 'action', 'workflow_action.xml', \$xml_contents
24 );
25 _
26 # Reference multiple files of mixed types
27
28 my @action_config = Workflow::Config->parse_all_files(
29 'action', 'my_actions.xml', 'your_actions.perl'
30 );
31
33 Read in configurations for the various workflow components. Currently
34 the class understands XML (preferred) and serialized Perl data
35 structures as valid configuration file formats. (I tried to use INI
36 files but there was too much deeply nested information. Sorry.)
37
39 parse_all_files( $workflow_config_type, @files )
40
41 Runs through each file in @files and processes it according to the
42 valid
43
45 Creating Your Own Parser
46 If you want to store your configuration in a different format you can
47 create your own parser. All you need to do is:
48
49 1. subclass Workflow::Config
50
51 2. implement the required methods (listed below)
52
53 3. register your parser with Workflow::Config.
54
55 For instance, if you wanted to use YAML for configuration files you
56 would do something like:
57
58 # just a convention, you can use any namespace you want
59 package Workflow::Config::YAML;
60
61 use strict;
62
63 # Requirement 1: Subclass Workflow::Config
64 use base qw( Workflow::Config );
65
66 # Requirement 2: Implement required methods
67 sub parse { ... }
68
69 The third requirement is registration, which just tells
70 Workflow::Config which parser to use for a particular type. To do this
71 you have two options.
72
73 Registration option one
74
75 Register yourself in your own class, adding the following call anywhere
76 the end:
77
78 # Option 1: Register ourselves by name
79 Workflow::Config->register_factory_type( yaml => 'Workflow::Config::YAML' );
80
81 Now you just need to include the configuration class in your workflow
82 invocation script:
83
84 use strict;
85 use Workflow::Factory qw( FACTORY );
86 use Workflow::Config::YAML; # <-- brings in the registration
87
88 Registration option two
89
90 You can also just explicitly add the registration from your workflow
91 invocation script:
92
93 use strict;
94 use Workflow::Factory qw( FACTORY );
95 use Workflow::Config;
96
97 # Option 2: explicitly register your configuration parser
98 Workflow::Config->register_factory_type( yaml => 'Workflow::Config::YAML' );
99
100 Whichever one you choose you can now parse (in this example) YAML files
101 alongside the built-in parsers for XML and Perl files:
102
103 FACTORY->add_config_from_file(
104 workflow => 'workflow.yaml',
105 action => [ 'my_actions.yaml', 'other_actions.xml' ],
106 validator => 'validators.yaml',
107 condition => [ 'my_conditions.yaml', 'other_conditions.xml' ]
108 persister => 'persister.perl',
109 );
110
111 Inherited Methods
112 new( $parser_type )
113
114 Instantiates an object of the correct type -- see Class::Factory for
115 how this is implemented:
116
117 # Parser of type 'Workflow::Config::XML'
118 my $xml_parser = Workflow::Config->new( 'xml' );
119
120 # Parser of type 'Workflow::Config::Perl
121 my $perl_parser = Workflow::Config->new( 'perl' );
122
123 is_valid_config_type( $config_type )
124
125 Returns true if $config_type is a valid configuration type, false if
126 not. Valid configuration types are: 'action', 'condition', 'validator',
127 'workflow'.
128
129 get_valid_config_types()
130
131 Returns list of strings representing the valid configuration types.
132
133 get_config_type_tag( $class, $type )
134
135 Returns string representing a valid configuration type, looking up the
136 type parameter in a lookuptable defined in Workflow::Config class.
137
138 Required Object Methods
139 parse( $workflow_config_type, @items )
140
141 Parse each item in @items to a hash reference based on the
142 configuration type $config_type which must pass the
143 "is_valid_config_type()" test. An 'item' is either a filename or a
144 scalar reference with the contents of a file. (You can mix and match as
145 seen in the SYNOPSIS.)
146
147 Should throw an exception if:
148
149 • You pass an invalid workflow configuration type. Valid workflow
150 configuration types are registered in Workflow::Config and are
151 available from "get_valid_config_types()"; you can check whether a
152 particular type is valid with "is_valid_config_type()". (See above
153 for descriptions.)
154
155 • You pass in a file that cannot be read or parsed because of
156 permissions, malformed XML, incorrect Perl data structure, etc. It
157 does not do a validation check (e.g., to ensure that every 'action'
158 within a workflow state has a 'resulting_state' key).
159
160 Returns: one hash reference for each member of @items
161
163 This gives you an idea of the configuration information in the various
164 workflow pieces:
165
166 workflow
167 workflow
168 type $
169 description $
170 persister $
171 initial_state $
172 observer \@
173 sub $
174 class $
175 state \@
176 name $
177 description $
178 action \@
179 name $
180 resulting_state $
181 condition \@
182 name $
183
184 • the 'type' and 'description' keys are at the top level
185
186 • 'persister' key holds a string declaring the name of a persister as
187 declared in the array of persisters
188
189 • 'initial_state' key holds a string declaring the name of the
190 initial state. by default, this value is 'INIITAL'.
191
192 • 'state' key holds array of one or more 'state' declarations; one of
193 them must be 'INITIAL' (or the value of initial_state, if it's
194 defined)
195
196 • each 'state' declaration holds 'description' and 'name' keys and
197 multiple 'action' declarations
198
199 • each 'action' declaration holds 'name' and 'resulting_state' keys
200 and may hold a 'condition' key with one or more named conditions
201
202 condition
203 conditions:
204
205 condition \@
206 name $
207 class $
208 param \@
209 name $
210 value $
211
212 • array of one or more hashrefs with 'name' and 'class' keys
213
214 validator
215 validators:
216
217 validator \@
218 name $
219 class $
220 param \@
221 name $
222 value $
223
224 • array of one or more hashrefs with 'name' and 'class' keys, plus
225 possibly one or more 'param' hashrefs each with 'name' and 'value'
226 keys
227
228 action
229 actions:
230
231 action \@
232 name $
233 class $
234 description $
235 type $
236 field \@
237 name $
238 is_required yes|no
239 type $
240 source_list \@ of $
241 source_class $
242 param \@
243 name $
244 value $
245 validator \@
246 name $
247 arg \@
248 value $
249
250 • array of one or more action hashrefs with 'name', 'class' and
251 'description' keys
252
253 • each 'action' may specify a 'type' (default value: 'default'); in
254 case a workflow specifies a 'type', actions specifying the same
255 'type' will be preferred over actions with the 'default' type when
256 multiple actions by the same name exist.
257
258 • each 'action' may have zero or more values used to fill it; each
259 value has a 'name', 'description' and 'necessity' ('required' or
260 'optional')
261
262 • each 'action' may have any number of 'param' hashrefs, each with
263 'name' and 'value'
264
265 • each 'action' may have any number of 'validator' hashrefs, each
266 with a 'name' key and array of 'arg' declarations
267
268 persister
269 persister:
270 name $ # all persister classes
271 class $ # all persister classes
272 use_random yes|no # all persister classes
273 use_uuid yes|no # all persister classes
274
275 driver $ # DBI persisters
276 dsn $ # DBI persisters
277 user $ # DBI persisters
278 password $ # DBI persisters
279 workflow_table $ # DBI persisters
280 history_table $ # DBI persisters
281 autocommit $ # DBI persisters
282 date_format $ # DBI persisters
283
284 table $ # DBI/ExtraData persisters
285 data_field $ # DBI/ExtraData persisters
286 context_key $ # DBI/ExtraData persisters
287
288 path $ # File persisters
289
290 • 'name' key holds a string declaring the name by which workflows may
291 refer to this persister configuration
292
293 • 'class' key names a Perl class name to use when instantiating the
294 persister
295
296 • 'use_random' key holds a string declaring (through 'yes'/'no'
297 value) to use random values for the workflow identifier
298
299 • 'use_uuid' key holds a string declaring (through 'yes'/'no' value)
300 to use UUID (universally unique ID) values for the workflow
301 identifier; UUIDs take preference over random IDs
302
303 For documentation of the other keys, please refer to the respective
304 classes.
305
307 Copyright (c) 2003-2021 Chris Winters. All rights reserved.
308
309 This library is free software; you can redistribute it and/or modify it
310 under the same terms as Perl itself.
311
312 Please see the LICENSE
313
315 Please see Workflow
316
317
318
319perl v5.34.0 2021-07-27 Workflow::Config(3)