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.59 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 class $
169 type $
170 description $
171 persister $
172 initial_state $
173 observer \@
174 sub $
175 class $
176 state \@
177 name $
178 description $
179 action \@
180 name $
181 resulting_state $
182 condition \@
183 name $
184
185 • the 'class', 'type' and 'description' keys are at the top level
186
187 • 'persister' key holds a string declaring the name of a persister as
188 declared in the array of persisters
189
190 • 'initial_state' key holds a string declaring the name of the
191 initial state. by default, this value is 'INIITAL'.
192
193 • 'state' key holds array of one or more 'state' declarations; one of
194 them must be 'INITIAL' (or the value of initial_state, if it's
195 defined)
196
197 • each 'state' declaration holds 'description' and 'name' keys and
198 multiple 'action' declarations
199
200 • each 'action' declaration holds 'name' and 'resulting_state' keys
201 and may hold a 'condition' key with one or more named conditions
202
203 condition
204 conditions:
205
206 condition \@
207 name $
208 class $
209 param \@
210 name $
211 value $
212
213 • array of one or more hashrefs with 'name' and 'class' keys
214
215 validator
216 validators:
217
218 validator \@
219 name $
220 class $
221 param \@
222 name $
223 value $
224
225 • array of one or more hashrefs with 'name' and 'class' keys, plus
226 possibly one or more 'param' hashrefs each with 'name' and 'value'
227 keys
228
229 action
230 actions:
231
232 action \@
233 name $
234 class $
235 description $
236 type $
237 field \@
238 name $
239 is_required yes|no
240 type $
241 source_list \@ of $
242 source_class $
243 param \@
244 name $
245 value $
246 validator \@
247 name $
248 arg \@
249 value $
250
251 • array of one or more action hashrefs with 'name', 'class' and
252 'description' keys
253
254 • each 'action' may specify a 'type' (default value: 'default'); in
255 case a workflow specifies a 'type', actions specifying the same
256 'type' will be preferred over actions with the 'default' type when
257 multiple actions by the same name exist.
258
259 • each 'action' may have zero or more values used to fill it; each
260 value has a 'name', 'description' and 'necessity' ('required' or
261 'optional')
262
263 • each 'action' may have any number of 'param' hashrefs, each with
264 'name' and 'value'
265
266 • each 'action' may have any number of 'validator' hashrefs, each
267 with a 'name' key and array of 'arg' declarations
268
269 persister
270 persister:
271 name $ # all persister classes
272 class $ # all persister classes
273 use_random yes|no # all persister classes
274 use_uuid yes|no # all persister classes
275
276 driver $ # DBI persisters
277 dsn $ # DBI persisters
278 user $ # DBI persisters
279 password $ # DBI persisters
280 workflow_table $ # DBI persisters
281 history_table $ # DBI persisters
282 autocommit $ # DBI persisters
283 date_format $ # DBI persisters
284
285 table $ # DBI/ExtraData persisters
286 data_field $ # DBI/ExtraData persisters
287 context_key $ # DBI/ExtraData persisters
288
289 path $ # File persisters
290
291 • 'name' key holds a string declaring the name by which workflows may
292 refer to this persister configuration
293
294 • 'class' key names a Perl class name to use when instantiating the
295 persister
296
297 • 'use_random' key holds a string declaring (through 'yes'/'no'
298 value) to use random values for the workflow identifier
299
300 • 'use_uuid' key holds a string declaring (through 'yes'/'no' value)
301 to use UUID (universally unique ID) values for the workflow
302 identifier; UUIDs take preference over random IDs
303
304 For documentation of the other keys, please refer to the respective
305 classes.
306
308 Copyright (c) 2003-2022 Chris Winters. All rights reserved.
309
310 This library is free software; you can redistribute it and/or modify it
311 under the same terms as Perl itself.
312
313 Please see the LICENSE
314
316 Please see Workflow
317
318
319
320perl v5.34.0 2022-02-06 Workflow::Config(3)