1Workflow::Factory(3) User Contributed Perl Documentation Workflow::Factory(3)
2
3
4
6 Workflow::Factory - Generates new workflow and supporting objects
7
9 # Import the singleton for easy access
10 use Workflow::Factory qw( FACTORY );
11
12 # Add XML configurations to the factory
13 FACTORY->add_config_from_file( workflow => 'workflow.xml',
14 action => [ 'myactions.xml', 'otheractions.xml' ],
15 validator => [ 'validator.xml', 'myvalidators.xml' ],
16 condition => 'condition.xml',
17 persister => 'persister.xml' );
18
19 # Create a new workflow of type 'MyWorkflow'
20 my $wf = FACTORY->create_workflow( 'MyWorkflow' );
21
22 # Fetch an existing workflow with ID '25'
23 my $wf = FACTORY->fetch_workflow( 'MyWorkflow', 25 );
24
26 Public
27
28 The Workflow Factory is your primary interface to the workflow system.
29 You give it the configuration files and/or data structures for the
30 Workflow, Workflow::Action, Workflow::Condition, Workflow::Persister,
31 and Workflow::Validator objects and then you ask it for new and exist‐
32 ing Workflow objects.
33
34 Internal
35
36 Developers using the workflow system should be familiar with how the
37 factory processes configurations and how it makes the various compo‐
38 nents of the system are instantiated and stored in the factory.
39
41 Public Methods
42
43 instance()
44
45 The factory is a singleton, this is how you get access to the instance.
46 You can also just import the 'FACTORY' constant as in the SYNOPSIS.
47
48 create_workflow( $workflow_type )
49
50 Create a new workflow of type $workflow_type. This will create a new
51 record in whatever persistence mechanism you have associated with
52 $workflow_type and set the workflow to its initial state.
53
54 Any observers you've associated with this workflow type will be
55 attached to the returned workflow object.
56
57 This fires a 'create' event from the just-created workflow object. See
58 "WORKFLOWS ARE OBSERVABLE" in Workflow for more.
59
60 Returns: newly created workflow object.
61
62 fetch_workflow( $workflow_type, $workflow_id )
63
64 Retrieve a workflow object of type $workflow_type and ID $workflow_id.
65 (The $workflow_type is necessary so we can fetch the workflow using the
66 correct persister.) If a workflow with ID $workflow_id is not found
67 "undef" is returned.
68
69 Any observers you've associated with this workflow type will be
70 attached to the returned workflow object.
71
72 This fires a 'fetch' event from the retrieved workflow object. See
73 "WORKFLOWS ARE OBSERVABLE" in Workflow for more.
74
75 Throws exception if no workflow type $workflow_type available.
76
77 Returns: Workflow object
78
79 add_config_from_file( %config_declarations )
80
81 Pass in filenames for the various components you wish to initialize
82 using the keys 'action', 'condition', 'persister', 'validator' and
83 'workflow'. The value for each can be a single filename or an arrayref
84 of filenames.
85
86 The system is familiar with the 'perl' and 'xml' configuration formats
87 -- see the 'doc/configuration.txt' for what we expect as the format and
88 will autodetect the types based on the file extension of each file.
89 Just give your file the right extension and it will be read in prop‐
90 erly.
91
92 You may also use your own custom configuration file format -- see "SUB‐
93 CLASSING" in Workflow::Config for what you need to do.
94
95 You can also read it in yourself and add the resulting hash reference
96 directly to the factory using "add_config()". However, you need to
97 ensure the configurations are added in the proper order -- when you add
98 an 'action' configuration and reference 'validator' objects, those
99 objects should already be read in. A good order is: 'validator', 'con‐
100 dition', 'action', 'workflow'. Then just pass the resulting hash refer‐
101 ences to "add_config()" using the right type and the behavior should be
102 exactly the same.
103
104 Returns: nothing; if we run into a problem parsing one of the files or
105 creating the objects it requires we throw a Workflow::Exception.
106
107 add_config( %config_hashrefs )
108
109 Similar to "add_config_from_file()" -- the keys may be 'action', 'con‐
110 dition', 'persister', 'validator' and/or 'workflow'. But the values are
111 the actual configuration hashrefs instead of the files holding the con‐
112 figurations.
113
114 You normally will only need to call this if you are programmatically
115 creating configurations (e.g., hot-deploying a validator class speci‐
116 fied by a user) or using a custom configuration format and for some
117 reason do not want to use the built-in mechanism in Workflow::Config to
118 read it for you.
119
120 Returns: nothing; if we encounter an error trying to create the objects
121 referenced in a configuration we throw a Workflow::Exception.
122
123 Internal Methods
124
125 save_workflow( $workflow )
126
127 Stores the state and current datetime of the $workflow object. This is
128 normally called only from the Workflow "execute_action()" method.
129
130 Returns: $workflow
131
132 get_workflow_history( $workflow )
133
134 Retrieves all Workflow::History objects related to $workflow.
135
136 NOTE: Normal users get the history objects from the Workflow object
137 itself. Under the covers it calls this.
138
139 Returns: list of Workflow::History objects
140
141 get_action( $workflow, $action_name )
142
143 Retrieves the action $action_name from workflow $workflow. Note that
144 this does not do any checking as to whether the action is proper given
145 the state of $workflow or anything like that. It is mostly an internal
146 method for Workflow (which does do checking as to the propriety of the
147 action) to instantiate new actions.
148
149 Throws exception if no action with name $action_name available.
150
151 Returns: Workflow::Action object
152
153 get_persister( $persister_name )
154
155 Retrieves the persister with name $persister_name.
156
157 Throws exception if no persister with name $persister_name available.
158
159 get_condition( $condition_name )
160
161 Retrieves the condition with name $condition_name.
162
163 Throws exception if no condition with name $condition_name available.
164
165 get_validator( $validator_name )
166
167 Retrieves the validator with name $validator_name.
168
169 Throws exception if no validator with name $validator_name available.
170
171 Internal Configuration Methods
172
173 _add_workflow_config( @config_hashrefs )
174
175 Adds all configurations in @config_hashrefs to the factory. Also cycles
176 through the workflow states and creates a Workflow::State object for
177 each. These states are passed to the workflow when it is instantiated.
178
179 We also require any necessary observer classes and throw an exception
180 if we cannot. If successful the observers are kept around and attached
181 to a workflow in create_workflow() and fetch_workflow().
182
183 Returns: nothing
184
185 _add_action_config( @config_hashrefs )
186
187 Adds all configurations in @config_hashrefs to the factory, doing a
188 'require' on the class referenced in the 'class' attribute of each
189 action.
190
191 Throws an exception if there is no 'class' associated with an action or
192 if we cannot 'require' that class.
193
194 Returns: nothing
195
196 _add_persister_config( @config_hashrefs )
197
198 Adds all configurations in @config_hashrefs to the factory, doing a
199 'require' on the class referenced in the 'class' attribute of each per‐
200 sister.
201
202 Throws an exception if there is no 'class' associated with a persister,
203 if we cannot 'require' that class, or if we cannot instantiate an
204 object of that class.
205
206 Returns: nothing
207
208 _add_condition_config( @config_hashrefs )
209
210 Adds all configurations in @config_hashrefs to the factory, doing a
211 'require' on the class referenced in the 'class' attribute of each con‐
212 dition.
213
214 Throws an exception if there is no 'class' associated with a condition,
215 if we cannot 'require' that class, or if we cannot instantiate an
216 object of that class.
217
218 Returns: nothing
219
220 _add_validator_config( @config_hashrefs )
221
222 Adds all configurations in @config_hashrefs to the factory, doing a
223 'require' on the class referenced in the 'class' attribute of each val‐
224 idator.
225
226 Throws an exception if there is no 'class' associated with a validator,
227 if we cannot 'require' that class, or if we cannot instantiate an
228 object of that class.
229
230 Returns: nothing
231
232 #=head3 associate_observers_with_workflow
233
234 #=head3 new
235
237 Implementation and Usage
238
239 You can subclass the factory to implement your own methods and still
240 use the useful facade of the "FACTORY" constant. For instance, the
241 implementation is typical Perl subclassing:
242
243 package My::Cool::Factory;
244
245 use strict;
246 use base qw( Workflow::Factory );
247
248 sub some_cool_method {
249 my ( $self ) = @_;
250 ...
251 }
252
253 To use your factory you can just do the typical import:
254
255 #!/usr/bin/perl
256
257 use strict;
258 use My::Cool::Factory qw( FACTORY );
259
260 Or you can call "instance()" directly:
261
262 #!/usr/bin/perl
263
264 use strict;
265 use My::Cool::Factory;
266
267 my $factory = My::Cool::Factory->instance();
268
270 Workflow
271
272 Workflow::Action
273
274 Workflow::Condition
275
276 Workflow::Config
277
278 Workflow::Persister
279
280 Workflow::Validator
281
283 Copyright (c) 2003-2006 Chris Winters. All rights reserved.
284
285 This library is free software; you can redistribute it and/or modify it
286 under the same terms as Perl itself.
287
289 Jonas B. Nielsen (jonasbn) <jonasbn@cpan.org> is the current main‐
290 tainer.
291
292 Chris Winters <chris@cwinters.com>, original author.
293
294
295
296perl v5.8.8 2007-04-25 Workflow::Factory(3)