I am working on a tutorial explaining how to poeize a procedural
program, in the hope of making it easier for my coworkers to pick up
POE.
Since I have not worked with POE for that long, I am wondering whether
there is an easier and more elegant way of doing this. This is what I
have so far, starting with the most basic. I would appreciate your
feedback.
Given the following function foo:
sub foo {
&step1() or return (undef, 'step1 failed');
&step2() or return (undef, 'step2 failed');
&step3() or return (undef, 'step3 failed');
&step4();
}
What's the easiest way to poeize this into the following form:
$kernel->post($session, 'foo', $response_postback);
Assume event foo, step1, ... step4 map to state poe_foo, poe_step1, ...
poe_step4.
sub poe_foo {
my($kernel, $session, $response) = @_[ KERNEL, SESSION, ARG0 ];
my $postback3 = $session->postback('step4', $response, $response);
my $postback2 = $session->postback('step3', $postback3, $response);
my $postback1 = $session->postback('step2', $postback2, $response);
$kernel->yield('step1', $postback1, $response);
}
sub poe_step1 {
my($kernel, $session, $success_cbk, $failure_cbk) =
@_[ KERNEL, SESSION, ARG0, ARG1 ];
my $result = &step1;
$result? $success_cbk->($result) :
$failure_cbk->(undef, 'step1 failed');
}
...
Pete