The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Machine::State::Transition - State Machine State Transition Class

VERSION

version 0.01

SYNOPSIS

    use Machine::State::Transition;

    my $trans = Machine::State::Transition->new(
        name   => 'resume',
        result => Machine::State::State->new(name => 'awake')
    );

    $trans->hook(during => sub {
        # do something during resume
    });

DESCRIPTION

Machine::State::Transition represents a state transition and it's resulting state.

ATTRIBUTES

executable

    my $executable = $trans->executable;
    $trans->executable(1);

The executable flag determines whether a transition can be execute.

hooks

    my $hooks = $trans->hooks;

The hooks attribute contains the collection of triggers and events to be fired when the transition is executed. The hook method should be used to configure any hooks into the transition processing.

name

    my $name = $trans->name;
    $name = $trans->name('suicide');

The name of the transition. The value can be any scalar value.

result

    my $state = $trans->result;
    $state = $trans->result(Machine::State::State->new(...));

The result represents the resulting state of a transition. The value must be a Machine::State::State object.

terminated

    my $terminated = $trans->terminated;
    $trans->terminated(1);

The terminated flag determines whether a transition in-execution should continue (i.e. processing hooks). This flag is reset on each execution an is meant to be called from within a hook.

METHODS

hook

    $trans = $trans->hook(during => sub {...});
    $trans->hook(before => sub {...});
    $trans->hook(after => sub {...});

The hook method registers a new hook in the append-only hooks collection to be fired when the transition is executed. The method requires an event name, either before, during, or after, and a code reference.

AUTHOR

Al Newkirk <anewkirk@ana.io>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Al Newkirk.

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