Class::Workflow::Transition::Simple - A useful class (or base class) for writing transitions.
use Class::Workflow::Transition::Simple; my $t = Class::Workflow::Transition::Simple->new( name => "feed", to_state => $not_hungry, # Class::Workflow::Transition::State body_sets_fields => 1, body => sub { my ( $self, $instance, @args ) = @_; my $remain = $global_food_warehouse->reduce_quantity; return ( remaining_food => $remain, ); }, );
This is just a string. It can be used to identify the transition in a parent object like Class::Workflow if any.
Class::Workflow
This is the state the transition will transfer to. This comes from Class::Workflow::Transition::Deterministic.
Class::Workflow::Transition::Deterministic
This is an optional sub (it defaults to <sub { }>) which will be called during apply, after all validation has passed.
<sub { }
The body is invoked as a method on the transition.
See body_sets_fields for the semantics of the return value.
body_sets_fields
When true, then the body is expected to return a hash of fields to override in the instance. See Class::Workflow::Transition::Deterministic for details.
This field is present to avoid writing code like this:
return ( {}, @return_values );
When you don't want to set fields in the instance.
Defaults to false (just write return @return_value, set to true to set fields).
See also set_fields.
set_fields
This field is a hash ref that will be used as the list of fields to set on the instance when body_sets_fields is false.
If your transition does not need to dynamically set fields you should probably use this.
Defaults to {}.
{}
These methods come from Class::Workflow::Transition::Validate::Simple.
This class consumes the following roles:
Class::Workflow::Transition::Strict
Class::Workflow::Transition::Validate::Simple
To install Class::Workflow, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Workflow
CPAN shell
perl -MCPAN -e shell install Class::Workflow
For more information on module installation, please visit the detailed CPAN module installation guide.