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

POE::Session::Cascading - Stack-like POE Sessions

AUTHOR

Matt Cashner (sungo@pobox.com)

DATE

$Date$

SYNOPSIS

    POE::Session::Cascading->new(
        name => 'foo',
        events => [
            'state1' => \&state1,
            'state2 => \&state2,
        ],
    );

    sub state1 {
        my %args = @_;
        $args{KERNEL}->post('somewhere','somestate');
        # [ snip ]
        
    }
    
    sub state2 {
        my %args = @_;
        # [ snip ]
        
        $args{SESSION}->stop;
    }

DESCRIPTION

INTRODUCTION

POE::Session::Cascading provides a stack-like session for POE. Another way of saying it is that a Cascading session is like a big switch statement. In the above example, when state1 is called in session foo, &state1 gets executed. When it finishes, state2 gets fired and &state2 gets executed. If state2 is called in session foo, only state2 will get executed.

CONTROLLING PROPOGATION

Each state can decide whether chain propogation should continue or not. If the state wishes to stop chain propogation, it must call $args{SESSION}->stop. Otherwise, chain propogation will continue. A state can call $args{SESSION}->go to forcibly allow chain propogation. This is largely superflous as this is the default option.

It would be appropriate to return call stop, for instance, if the state has determined that further action by this chain is unnecessary or undesirable. The state might launch a different chain and cal stop to shutdown the current chain's propogation.

LAUNCHING A CHAIN

To initiate a chain, post a call to the relevant state with the session's name. For instance, to activate the chain in the example above, one would write:

    $poe_kernel->post('foo','state1');

Arguments passes to POE's post method will be passed directly to the state and those which follow it.

WRITING A STATE

Cascading states are a bit different from the usual POE states, mainly in the argument list. Cascading states are passed a hash, containing three entries. SESSION contains a reference to the current session's object. KERNEL contains a reference to the POE kernel. ARGS contains an array reference of the arguments passed to the state.

Cascading states can do anything perl can. Cascading states are passed a hash, containing three entries. SESSION contains a reference to the current session's object. KERNEL contains a reference to the POE kernel. ARGS contains an array reference of the arguments passed to the state, including any data passed from the previous state..

METHODS

new()

    POE::Session::Cascading->new(
        name => 'foo',
        events => [
            step1 => \&step1,
            step2 => \&step2,
            step3 => \&step3,
        ]
    );

stop

    $args{SESSION}->stop;

Instruct the current session to stop chain propogation.

go

    $args{SESSION}->go;

Instruct the current session to continue chain propgation.

swap

    $args{SESSION}->swap($state1, $state2);
    

Reorder the event stack. Swap two states in the stack.