NAME

Workflow::Factory - Generates new workflow and supporting objects

SYNOPSIS

# Import the singleton for easy access
use Workflow::Factory qw( FACTORY );

# Add XML configurations to the factory
FACTORY->add_config_from_file( workflow  => 'workflow.xml',
                               action    => [ 'myactions.xml', 'otheractions.xml' ],
                               validator => [ 'validator.xml', 'myvalidators.xml' ],
                               condition => 'condition.xml',
                               persister => 'persister.xml' );

# Create a new workflow of type 'MyWorkflow'
my $wf = FACTORY->create_workflow( 'MyWorkflow' );

# Fetch an existing workflow with ID '25'
my $wf = FACTORY->fetch_workflow( 'MyWorkflow', 25 );

DESCRIPTION

Public

The Workflow Factory is your primary interface to the workflow system. You give it the configuration files and/or data structures for the Workflow, Workflow::Action, Workflow::Condition, Workflow::Persister, and Workflow::Validator objects and then you ask it for new and existing Workflow objects.

Internal

Developers using the workflow system should be familiar with how the factory processes configurations and how it makes the various components of the system are instantiated and stored in the factory.

METHODS

Public Methods

instance()

The factory is a singleton, this is how you get access to the instance. You can also just import the 'FACTORY' constant as in the SYNOPSIS.

create_workflow( $workflow_type )

Create a new workflow of type $workflow_type. This will create a new record in whatever persistence mechanism you have associated with $workflow_type and set the workflow to its initial state.

Returns: newly created workflow object.

fetch_workflow( $workflow_type, $workflow_id )

Retrieve a workflow object of type $workflow_type and ID $workflow_id. (The $workflow_type is necessary so we can fetch the workflow using the correct persister.) If a workflow with ID $workflow_id is not found undef is returned.

Throws exception if no workflow type $workflow_type available.

Returns: Workflow object

add_config_from_file( %config_declarations )

Pass in filenames for the various components you wish to initialize using the keys 'action', 'condition', 'persister', 'validator' and 'workflow'. The value for each can be a single filename or an arrayref of filenames.

The system is familiar with the 'perl' and 'xml' configuration formats -- see the 'doc/configuration.txt' for what we expect as the format. Just give your file the right name and it will be read in properly.

You may also use your own custom configuration file format, read it in yourself (or subclass Workflow::Factory to do it for you) and add the resulting hash reference directly to the factory. However, you need to ensure the configurations are added in the proper order -- when you add an 'action' configuration and reference 'validator' objects, those objects should already be read in. A good order is: 'validator', 'condition', 'action', 'workflow'. Then just pass the resulting hash references to add_config() using the right type and the behavior should be exactly the same.

add_config( %config_hashrefs )

Similar to add_config_from_file() -- the keys may be 'action', 'condition', 'persister', 'validator' and/or 'workflow'. But the values are the actual configuration hashrefs instead of the files holding the configurations.

You normally will only need to call this if you are creating configurations on the fly (e.g., hot-deploying a validator class specified by a user) or using a custom configuration format.

Internal Methods

save_workflow( $workflow )

Stores the state and current datetime of the $workflow object. This is normally called only from the Workflow execute_action() method.

Returns: $workflow

get_workflow_history( $workflow )

Retrieves all Workflow::History objects related to $workflow.

NOTE: Normal users get the history objects from the Workflow object itself. Under the covers it calls this.

Returns: list of Workflow::History objects

get_action( $workflow, $action_name )

Retrieves the action $action_name from workflow $workflow. Note that this does not do any checking as to whether the action is proper given the state of $workflow or anything like that. It is mostly an internal method for Workflow (which does do checking as to the propriety of the action) to instantiate new actions.

Throws exception if no action with name $action_name available.

Returns: Workflow::Action object

get_persister( $persister_name )

Retrieves the persister with name $persister_name.

Throws exception if no persister with name $persister_name available.

get_condition( $condition_name )

Retrieves the condition with name $condition_name.

Throws exception if no condition with name $condition_name available.

get_validator( $validator_name )

Retrieves the validator with name $validator_name.

Throws exception if no validator with name $validator_name available.

Internal Configuration Methods

_add_workflow_config( @config_hashrefs )

Adds all configurations in @config_hashrefs to the factory. Also cycles through the workflow states and creates a Workflow::State object for each. These states are passed to the workflow when it is instantiated.

Returns: nothing

_add_action_config( @config_hashrefs )

Adds all configurations in @config_hashrefs to the factory, doing a 'require' on the class referenced in the 'class' attribute of each action.

Throws an exception if there is no 'class' associated with an action or if we cannot 'require' that class.

Returns: nothing

_add_persister_config( @config_hashrefs )

Adds all configurations in @config_hashrefs to the factory, doing a 'require' on the class referenced in the 'class' attribute of each persister.

Throws an exception if there is no 'class' associated with a persister, if we cannot 'require' that class, or if we cannot instantiate an object of that class.

Returns: nothing

_add_condition_config( @config_hashrefs )

Adds all configurations in @config_hashrefs to the factory, doing a 'require' on the class referenced in the 'class' attribute of each condition.

Throws an exception if there is no 'class' associated with a condition, if we cannot 'require' that class, or if we cannot instantiate an object of that class.

Returns: nothing

_add_validator_config( @config_hashrefs )

Adds all configurations in @config_hashrefs to the factory, doing a 'require' on the class referenced in the 'class' attribute of each validator.

Throws an exception if there is no 'class' associated with a validator, if we cannot 'require' that class, or if we cannot instantiate an object of that class.

Returns: nothing

SEE ALSO

Workflow

Workflow::Action

Workflow::Condition

Workflow::Persister

Workflow::Validator

COPYRIGHT

Copyright (c) 2003-2004 Chris Winters. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>