NAME
FSA::Engine::Transition - Transition object for FSA::Engine objects.
SYNOPSIS
A Transition object is created as part of the definition of your FSA object.
sub _build_fsa_transitions {
my ($self) = @_;
my $transitions = {
open => {
slam_door => FSA::Engine::Transition->new({
test => 'SHOVE DOOR',
action => sub {print "The door slams shut with a BANG\n";},
state => 'closed',
}),
close_door => FSA::Engine::Transition->new({
test => sub {$self->test_door_push(@_)},
action => sub {print "There is a falling 'EEERRRrrrkkk' sound\n";},
state => 'closed',
}),
},
...
DESCRIPTION
This class defines a transition for your FSA class which has included the Moose Role FSA::Engine
It defines the test to carry out to determine if the transition is valid, the state that is to be moved to if the test succeeds and the optional action to perform when the transition is valid.
METHODS
new
Create a new instance. Takes the following attributes.
test
The test to carry out to determine if the transition is to be followed.
If test is a scalar, it is compared with the current fsa_input attribute of your FSA and if they are identical then the test is deemed to have passed.
Otherwise test should be an anonymous subroutine which is called to determine if the transition should be followed. This subroutine should return true if the test succeeds, otherwise undef.
state
The state is simply the name of the state to move to if the test succeeds. It should be defined as a 'Str' Moose attribute.
action
This should be an anonymous subroutine reference which will be called if the transition is followed. The subroutine will be called after any exit action is called from the state being left and before any entry action of the state being moved to.
do_test
This is the method called to determine if the test succeeds. It takes one parameter, the fsa_input value from your FSA.
The method looks at the test attribute, if it is a code reference it calls the anonymous subroutine passing the fsa_input value as the first parameter. The subroutine should return true or false depending upon whether the test should succeed or fail.
If it is not a code reference it carries out a comparison of the input value with the test attribute returning the result of that comparison.
SUPPORT
This module is stored on an open TBD GitHub repository. Feel free to fork and contribute.
Please file bug reports via TBD or by sending email to.
AUTHOR
Ian C. Docherty <pause@iandocherty.com>
COPYRIGHT AND LICENSE
Copyright(c) 2011 Ian C. Docherty
This module is free software; you can distribute it and/or modify it under the same terms as Perl itself.