Class::StateMachine - define classes for state machines


Class-StateMachine documentation  | view source Contained in the Class-StateMachine distribution.

Index


NAME

Top

Class::StateMachine - define classes for state machines

SYNOPSIS

Top

  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

Top

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

Top

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

Top

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

COPYRIGHT AND LICENSE

Top


Class-StateMachine documentation  | view source Contained in the Class-StateMachine distribution.