1Workflow::Action(3)   User Contributed Perl Documentation  Workflow::Action(3)
2
3
4

NAME

6       Workflow::Action - Base class for Workflow actions
7

VERSION

9       This documentation describes version 1.09 of this package
10

SYNOPSIS

12        # Configure the Action...
13        <action name="CreateUser"
14                class="MyApp::Action::CreateUser">
15          <field name="username" is_required="yes"/>
16          <field name="email" is_required="yes"/>
17          <validator name="IsUniqueUser">
18              <arg>$username</arg>
19          </validator>
20          <validator name="IsValidEmail">
21              <arg>$email</arg>
22          </validator>
23        </action>
24
25        # Define the action
26
27        package MyApp::Action::CreateUser;
28
29        use base qw( Workflow::Action );
30        use Workflow::Exception qw( workflow_error );
31
32        sub execute {
33            my ( $self, $wf ) = @_;
34            my $context = $wf->context;
35
36            # Since 'username' and 'email' have already been validated we
37            # don't need to check them for uniqueness, well-formedness, etc.
38
39            my $user = eval {
40                User->create({ username => $context->param( 'username' ),
41                               email    => $context->param( 'email' ) })
42            };
43
44            # Wrap all errors returned...
45
46            if ( $@ ) {
47                workflow_error
48                    "Cannot create new user with name '", $context->param( 'username' ), "': $EVAL_ERROR";
49            }
50
51            # Set the created user in the context for the application and/or
52            # other actions (observers) to use
53
54            $context->param( user => $user );
55
56            # return the username since it might be used elsewhere...
57            return $user->username;
58        }
59

DESCRIPTION

61       This is the base class for all Workflow Actions. You do not have to use
62       it as such but it is strongly recommended.
63

CONFIGURATION

65       You configure your actions and map them to a specific module in your
66       actions configuration file using the syntax above and that shown in
67       Workflow. In some cases, you'll have actions that apply to all
68       workflows. In more elaborate configurations, you may have one workflow
69       server loading multiple workflows and multiple actions for each.  In
70       these cases, you'll have multiple workflow types and you may want
71       actions with the same names to have different behaviors for each type.
72
73       For example, you may have a workflow type Ticket and another type
74       Order_Parts.  They both may have a Submit action, but you'll want the
75       Submit to be different for each.
76
77       You can specify a type in your actions configuration to associate that
78       action with that workflow type. If you don't provide a type, the action
79       is available to all types. For example:
80
81         <actions>
82           <type>Ticket</type>
83           <description>Actions for the Ticket workflow only.</description>
84           <action name="TIX_NEW"
85                  class="TestApp::Action::TicketCreate">
86         ...Addtional configuration...
87
88       The type must match an existing workflow type or the action will never
89       be called.
90

OBJECT METHODS

92   Public Methods
93       add_field( @fields )
94
95       Add one or more Workflow::Action::InputFields to the action.
96
97       required_fields()
98
99       Return a list of Workflow::Action::InputField objects that are
100       required.
101
102       optional_fields()
103
104       Return a list of Workflow::Action::InputField objects that are
105       optional.
106
107       fields()
108
109       Return a list of all Workflow::Action::InputField objects associated
110       with this action.
111
112       add_validators( @validator_config )
113
114       Given the 'validator' configuration declarations in the action
115       configuration, ask the Workflow::Factory for the Workflow::Validator
116       object associated with each name and store that along with the
117       arguments to be used, runtime and otherwise.
118
119       get_validators()
120
121       Get a list of all the validator hashrefs, each with two keys:
122       'validator' and 'args'. The 'validator' key contains the appropriate
123       Workflow::Validator object, while 'args' contains an arrayref of
124       arguments to pass to the validator, some of which may need to be
125       evaluated at runtime.
126
127       validate( $workflow )
128
129       Run through all validators for this action. If any fail they will throw
130       a Workflow::Exception, the validation subclass.
131
132       execute( $workflow )
133
134       Subclasses must implement -- this will perform the actual work. It's
135       not required that you return anything, but if the action may be used in
136       a Workflow::State object that has multiple resulting states you should
137       return a simple scalar for a return value.
138
139       add_fields
140
141       Method to add fields to the workflow. The method takes an array of
142       fields.
143
144   Private Methods
145       init( $workflow, \%params )
146
147       init is called in conjuction with the overall workflow initialization.
148
149       It sets up the necessary validators based on the on configured actions,
150       input fields and required fields.
151

SEE ALSO

153       Workflow
154
155       Workflow::Factory
156
158       Copyright (c) 2003-2004 Chris Winters. All rights reserved.
159
160       This library is free software; you can redistribute it and/or modify it
161       under the same terms as Perl itself.
162

AUTHORS

164       Chris Winters <chris@cwinters.com>
165
166
167
168perl v5.12.0                      2010-05-07               Workflow::Action(3)
Impressum