NAME

Class::StateMachine - define classes for state machines

SYNOPSIS

package MySM;
no warnings 'redefine';

use base 'Class::StateMachine';

sub foo : OnState(one) { print "on state one\n" }
sub foo : OnState(two) { print "on state two\n" }

sub bar : OnState(__any__) { print "default action\n" }
sub bar : OnState(three, five, seven) { print "on several states\n" }
sub bar : OnState(one) { print "on state one\n" }

sub new { bless {}, shift }

package main;

my $sm = MySM->new;

$sm->state('one');
$sm->foo; # prints "on state one"

$sm->state('two');
$sm->foo; # prints "on state two"

DESCRIPTION

Class::StateMachine lets define, via the OnState attribute, methods that are dispatched depending on an internal state property.

METHODS

These methods are available on objects of this class:

$obj->state

gets the object state

$obj->state($new_state)

changes the object state

$obj->rebless($class)

changes the object class in a compatible manner, target class should also be derived from Class::StateMachine.

BUGS

Because of certain limitations in current perl implementation of attributed subroutines, attributes have to be processed on CHECK blocks. That means that they will not be available before that, for instance, on module initialization, or in BEGIN blocks.

SEE ALSO

attributes, perlsub, perlmod, warnings, Attribute::Handlers.

COPYRIGHT AND LICENSE

Copyright (C) 2003-2006 by Salvador Fandiño (sfandino@yahoo.com).

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