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.12 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 · the 'extra_data' key holds an array of zero or more hashrefs with
187 'table', 'field', 'class' and 'context' keys
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 field \@
234 name $
235 is_required yes|no
236 type $
237 source_list \@ of $
238 source_class $
239 param \@
240 name $
241 value $
242 validator \@
243 name $
244 arg \@
245 value $
246
247 · array of one or more action hashrefs with 'name', 'class' and
248 'description' keys
249
250 · each 'action' may have zero or more values used to fill it; each
251 value has a 'name', 'description' and 'necessity' ('required' or
252 'optional')
253
254 · each 'action' may have any number of 'param' hashrefs, each with
255 'name' and 'value'
256
257 · each 'action' may have any number of 'validator' hashrefs, each
258 with a 'name' key and array of 'arg' declarations
259
260 persister
261 persister:
262
263 extra_table $
264 extra_field $
265 extra_class $
266 extra_context $
267
269 Copyright (c) 2003-2004 Chris Winters. All rights reserved.
270
271 This library is free software; you can redistribute it and/or modify it
272 under the same terms as Perl itself.
273
275 Chris Winters <chris@cwinters.com>
276
277
278
279perl v5.30.1 2020-01-30 Workflow::Config(3)