POE::Component::Sequence::Nested - Adds special features to nested sequences
use POE qw(Component::Sequence::Nested); POE::Component::Sequence ->new( { auto_pause => 1, auto_resume => 1, merge_heap => 1, }, sub { POE::Component::Sequence ->new( sub { my $subseq = shift; $subseq->heap_set( a => 5, b => 19, op => '+', ); }, )->run; }, sub { my $sequence = shift; my $math = join ' ', map { $sequence->heap_index($_) } qw(a op b); $sequence->heap_set(result => eval $math); } ) ->add_callback(sub { my ($sequence, $result) = @_; print "Answer was " . $sequence->heap_index('result') . "\n"; }) ->run();
A nested sequence is one in which the return value of an action is another Sequence. When this is the case, we can perform some automated tasks which save each action from redundant calls.
By itself it does nothing, but given any of the following actions, it will do it's magic:
The parent sequence remains paused, but the child sequence has a callback added onto it which will resume the parent sequence:
$child_sequence->add_callback(sub { $parent_sequence->resume; });
This propogates a child sequence failure to the parent via $child->add_error_callback(). This would happen anyway if the child sequence throws an exception, but if the child sequence is already catching errors via another callback
The heap of the child sequence will be merged with the parent when it's complete:
$child_sequence->add_finally_callback(sub { $parent_sequence->heap_set( $child_sequence->heap ); });
This allows for shared heap access.
No known bugs, but I'm sure you can find some.
POE::Component::Sequence
Copyright (c) 2008 Eric Waters and XMission LLC (http://www.xmission.com/). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
Eric Waters <ewaters@gmail.com>
To install POE::Component::Sequence, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::Sequence
CPAN shell
perl -MCPAN -e shell install POE::Component::Sequence
For more information on module installation, please visit the detailed CPAN module installation guide.