Class::Workflow::Transition - A function over an instance.


Class-Workflow documentation Contained in the Class-Workflow distribution.

Index


Code Index:

NAME

Top

Class::Workflow::Transition - A function over an instance.

SYNOPSIS

Top

	package MyTransition;
	use Moose;
	with 'Class::Workflow::Transition';

DESCRIPTION

Top

This is the base role for transition implementations.

every transition object must comply to it's interface, and furthermore must also use the derive_and_accept_instance method to return a derived instance at the end of the operation.

METHODS

Top

derive_and_accept_instance $instance, \%attrs, @args

This method calls $instance->derive with the attrs, and then calls the instance accept_instance on the new instance's state.

%attrs must contain the key state, which should do the role Class::Workflow::State.

@args are passed (along with the derived instance) to accept_instance in Class::Workflow::State.

REQUIRED METHODS

Top

apply $insatnce, @args

This method accepts a Class::Workflow::Instance as it's first argument, and is expected to call $self->derive_and_accept_instance( $instance, \%attrs, @args ), with %attrs containing the state that the instance is being transferred to (it doesn't have to be different than the current state).


Class-Workflow documentation Contained in the Class-Workflow distribution.

#!/usr/bin/perl

package Class::Workflow::Transition;
use Moose::Role;

use Carp qw/croak/;

requires "apply";

sub derive_and_accept_instance {
	my ( $self, $proto_instance, $attrs, @args ) = @_;

	croak "You must specify the next state of the instance"
		unless $attrs->{state};

	my $state = $attrs->{state};

	my $instance = $proto_instance->derive(
		transition => $self,
		%$attrs,
	);

	return $state->accept_instance( $instance, @args );
}

__PACKAGE__;

__END__