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

NAME

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

SYNOPSIS

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

DESCRIPTION

58       This is the base class for all Workflow Actions. You do not have to use
59       it as such but it is strongly recommended.
60

OBJECT METHODS

62       Public Methods
63
64       add_field( @fields )
65
66       Add one or more Workflow::Action::InputFields to the action.
67
68       required_fields()
69
70       Return a list of Workflow::Action::InputField objects that are
71       required.
72
73       optional_fields()
74
75       Return a list of Workflow::Action::InputField objects that are
76       optional.
77
78       fields()
79
80       Return a list of all Workflow::Action::InputField objects associated
81       with this action.
82
83       add_validators( @validator_config )
84
85       Given the 'validator' configuration declarations in the action configu‐
86       ration, ask the Workflow::Factory for the Workflow::Validator object
87       associated with each name and store that along with the arguments to be
88       used, runtime and otherwise.
89
90       get_validators()
91
92       Get a list of all the validator hashrefs, each with two keys: 'valida‐
93       tor' and 'args'. The 'validator' key contains the appropriate Work‐
94       flow::Validator object, while 'args' contains an arrayref of arguments
95       to pass to the validator, some of which may need to be evaluated at
96       runtime.
97
98       validate( $workflow )
99
100       Run through all validators for this action. If any fail they will throw
101       a Workflow::Exception, the validation subclass.
102
103       execute( $workflow )
104
105       Subclasses must implement -- this will perform the actual work. It's
106       not required that you return anything, but if the action may be used in
107       a Workflow::State object that has multiple resulting states you should
108       return a simple scalar for a return value.
109
110       #=head3 add_fields
111
112       Private Methods
113
114       #=head3 init( $workflow, \%params )
115

SEE ALSO

117       Workflow
118
119       Workflow::Factory
120
122       Copyright (c) 2003-2004 Chris Winters. All rights reserved.
123
124       This library is free software; you can redistribute it and/or modify it
125       under the same terms as Perl itself.
126

AUTHORS

128       Chris Winters <chris@cwinters.com>
129
130
131
132perl v5.8.8                       2007-04-25               Workflow::Action(3)
Impressum