The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FSM::Tiny - tiny implementation of finite state machine

VERSION

This document describes FSM::Tiny version 0.01.

SYNOPSIS

    use FSM::Tiny;
    
    my $fsm = FSM::Tiny->new({
        on_enter => sub {
            $_->{count} = 0;
        }
    });
    
    $fsm->register(init => sub {}, [
        add => sub { $_->{count} < 20 },
        end => sub { $_->{count} >= 20 }
    ]);
    
    $fsm->register(add => sub { ++$_->{count} }, [
        init => 1
    ]);
    
    $fsm->register(end => sub { $_->{count} *= 5 });
    
    $fsm->run;

    print $fsm->context->{count}; # => 100

DESCRIPTION

This module is tiny implementation of finite state machine. this provides more simpler interface and code than any cpan's FSM::* modules.

ATTRIBUTES

current

define current state name for this machine.

rules

same as register function.

context

this is global variable of machine. in state behavior(as function) and guard function, it is read as $_

on_enter

it calls when machine transitions start.

on_transition

it calls in between transitions.

on_exit

it calls when machine transitions end.

METHODS

new(%args)

you can define all rules and attributes in this initializer.

register($state_name => $state_fn, [%conditions])

registering state, state behavior(as function), and conditions for transition. %conditions is defined follows:

    [
      destination1 => sub { !!it_should_move_to_destination1_or_not() },
      destination2 => sub { !!it_should_move_to_destination2_or_not() }
    ]

step

it run one transition.

run

it makes run until transitions end.

DEPENDENCIES

Perl 5.8.1 or later.

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

SEE ALSO

perl

AUTHOR

<Taiyoh Tanaka> <<sun.basix@gmail.com>>

LICENSE AND COPYRIGHT

Copyright (c) 2013, <Taiyoh Tanaka>. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.