NAME

Class::Workflow::Transition::Simple - A useful class (or base class) for writing transitions.

SYNOPSIS

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,
		);
	},
);

DESCRIPTION

FIELDS

name

This is just a string. It can be used to identify the transition in a parent object like Class::Workflow if any.

to_state

This is the state the transition will transfer to. This comes from Class::Workflow::Transition::Deterministic.

body

This is an optional sub (it defaults to <sub { }>) which will be called during apply, after all validation has passed.

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 {}.

validate
validators
clear_validators
add_validators

These methods come from Class::Workflow::Transition::Validate::Simple.

ROLES

This class consumes the following roles: