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.62 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 scalar
144 reference with the contents of a file. (You can mix and match as seen
145 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 type $
207 condition \@
208 name $
209 class $
210 param \@
211 name $
212 value $
213
214 • array of one or more hashrefs with 'name' and 'class' keys
215
216 validator
217 validators:
218
219 validator \@
220 name $
221 class $
222 param \@
223 name $
224 value $
225
226 • array of one or more hashrefs with 'name' and 'class' keys, plus
227 possibly one or more 'param' hashrefs each with 'name' and 'value'
228 keys
229
230 action
231 actions:
232
233 type $
234 action \@
235 name $
236 class $
237 description $
238 field \@
239 name $
240 is_required yes|no
241 type $
242 source_list \@ of $
243 source_class $
244 param \@
245 name $
246 value $
247 validator \@
248 name $
249 arg \@
250 value $
251
252 • array of one or more action hashrefs with 'name', 'class' and
253 'description' keys
254
255 • each 'action' may specify a 'type' (default value: 'default'); in
256 case a workflow specifies a 'type', actions specifying the same
257 'type' will be preferred over actions with the 'default' type when
258 multiple actions by the same name exist.
259
260 • each 'action' may have zero or more values used to fill it; each
261 value has a 'name', 'description' and 'necessity' ('required' or
262 'optional')
263
264 • each 'action' may have any number of 'param' hashrefs, each with
265 'name' and 'value'
266
267 • each 'action' may have any number of 'validator' hashrefs, each
268 with a 'name' key and array of 'arg' declarations
269
270 persister
271 persister:
272 name $ # all persister classes
273 class $ # all persister classes
274 use_random yes|no # all persister classes
275 use_uuid yes|no # all persister classes
276
277 driver $ # DBI persisters
278 dsn $ # DBI persisters
279 user $ # DBI persisters
280 password $ # DBI persisters
281 workflow_table $ # DBI persisters
282 history_table $ # DBI persisters
283 autocommit $ # DBI persisters
284 date_format $ # DBI persisters
285
286 table $ # DBI/ExtraData persisters
287 data_field $ # DBI/ExtraData persisters
288 context_key $ # DBI/ExtraData persisters
289
290 path $ # File persisters
291
292 • 'name' key holds a string declaring the name by which workflows may
293 refer to this persister configuration
294
295 • 'class' key names a Perl class name to use when instantiating the
296 persister
297
298 • 'use_random' key holds a string declaring (through 'yes'/'no'
299 value) to use random values for the workflow identifier
300
301 • 'use_uuid' key holds a string declaring (through 'yes'/'no' value)
302 to use UUID (universally unique ID) values for the workflow
303 identifier; UUIDs take preference over random IDs
304
305 For documentation of the other keys, please refer to the respective
306 classes.
307
309 Copyright (c) 2003-2023 Chris Winters. All rights reserved.
310
311 This library is free software; you can redistribute it and/or modify it
312 under the same terms as Perl itself.
313
314 Please see the LICENSE
315
317 Please see Workflow
318
319
320
321perl v5.38.0 2023-07-21 Workflow::Config(3)