NAME
DFA::Simple
-- A PERL module to implement simple Discrete Finite Automata
SYNOPSIS
my $Obj = new DFA::Simple
or
my $Obj = new DFA::Simple $Transitions;
or
my $Obj = new DFA::Simple $Actions, $StateRules;
$Obj->Actions = [...];
my $Trans = $LP->Actions;
$Obj->StateRules = [...];
my $StateRules = $LP->StateRules;
DESCRIPTION
my $Obj = new DFA::Simple $Actions,[States];
This creates a simple automaton with a finite number of individual states. The object is composed of the following three things (with methods to match):
- State
-
The object has a particular state it is in; a specific state from a set of possible states
- Actions
-
The object when enterring or leaving a state may perform some action.
- Rules
-
The object has rules for determining what its next state should be, and how to get there.
State
State
is a method that can get the current state or initiate a transition to a new state.
my $S = $Obj->State;
$Obj->State = $NewState;
The last one leaves the current state and goes to the specified NewState. If the current state is defined, its StateExitCodeRef will be called (see below). Then the new states StateEnterCodeRef will be called (if defined) (see below). Cavaet, no check is made to see if the new state is the same as the old state; this can be used to `reset' the state.
Actions
Actions
is a method that can set or get the objects list of actions to perform when enterring or leaving a particular state.
my $Actions = $Obj->Actions;
$Obj->Actions = [
[StateEnterCodeRef, StateExitCodeRef],
];
Actions is an array reference describing what to do when enterring and leaving various states. When a state is entered, its StateEnterCodeRef will be called (if defined). When a state is left (as in going to a new state) its StateExitCodeRef will be called (if defined).
StateRules
my $StateRules = [
#Rules for state 0
[
[NextState, Test, Thing to do after getting there
],
#Rules for state 1
[
...
],
];
Installation
perl Makefile.PL
make
make install
Author
Randall Maas (randym@acm.org, http://www.hamline.edu/~rcmaas/)