| 1 | #!/usr/bin/perl -w |
| 2 | # vim: ts=2 sw=2 expandtab |
| 3 | |
| 4 | # Jonathan Steinert produced a patch to fix POE::Wheel destruction |
| 5 | # timing, and possibly other things, when they're passed as arguments |
| 6 | # to an event handler. It didn't take into consideration a subtle and |
| 7 | # obscure aspect of recursive signal dispatch. This regression test |
| 8 | # makes sure nested signal dispatches receive the proper parameters. |
| 9 | |
| 10 | use strictscip-perl cpan POE-Test-Loops 1.360 strict/; |
| 11 | |
| 12 | sub POE::Kernel::ASSERT_DEFAULTscip-perl cpan POE-Test-Loops 1.360 main/`POE::Kernel::ASSERT_DEFAULT`(). () { 1 } |
| 13 | |
| 14 | BEGIN { |
| 15 | eval "sub POE::Kernel::TRACE_DEFAULT () { 1 }" if ( |
| 16 | existsscip-perl cpan POE-Test-Loops 1.360 main/exists(). $INCscip-perl cpan POE-Test-Loops 1.360 main/`%INC`.{'Devel/Cover.pm'} |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | use POEscip-perl cpan POE-Test-Loops 1.360 POE/; |
| 21 | use POE::Wheel::ReadWritescip-perl cpan POE-Test-Loops 1.360 POE/Wheel/ReadWrite/; |
| 22 | use POE::Pipe::OneWayscip-perl cpan POE-Test-Loops 1.360 POE/Pipe/OneWay/; |
| 23 | |
| 24 | use Test::Morescip-perl cpan POE-Test-Loops 1.360 Test/More/ tests => 2; |
| 25 | |
| 26 | my $session_count = 0; |
| 27 | |
| 28 | sub start_sessionscip-perl cpan POE-Test-Loops 1.360 main/start_session(). { |
| 29 | $session_count++; |
| 30 | POE::Session->createscip-perl cpan POE-Test-Loops 1.360 POE/Session/create().( |
| 31 | inline_states => { |
| 32 | _start => \&setupscip-perl cpan POE-Test-Loops 1.360 main/setup()., |
| 33 | got_signal => \&handle_signalscip-perl cpan POE-Test-Loops 1.360 main/handle_signal()., |
| 34 | timed_out => \&timed_outscip-perl cpan POE-Test-Loops 1.360 main/timed_out()., |
| 35 | # To pacify assertions. |
| 36 | _stop => sub { }, |
| 37 | _parent => sub { }, |
| 38 | _child => sub { }, |
| 39 | } |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | start_sessionscip-perl cpan POE-Test-Loops 1.360 main/start_session().(); |
| 44 | $poe_kernelscip-perl cpan POE-Test-Loops 1.360 main/$poe_kernel.->signalscip-perl cpan POE-Test-Loops 1.360 main/signal().($poe_kernelscip-perl cpan POE-Test-Loops 1.360 main/$poe_kernel., MOO => 99); |
| 45 | POE::Kernel->runscip-perl cpan POE-Test-Loops 1.360 POE/Kernel/run().(); |
| 46 | |
| 47 | ### End of main code. Beginning of subroutines. |
| 48 | |
| 49 | sub setupscip-perl cpan POE-Test-Loops 1.360 main/setup(). { |
| 50 | start_sessionscip-perl cpan POE-Test-Loops 1.360 main/start_session().() if $session_count < 2; |
| 51 | $_scip-perl cpan POE-Test-Loops 1.360 main/`@_`.[KERNEL]->sigscip-perl cpan POE-Test-Loops 1.360 main/sig().(MOO => "got_signal"); |
| 52 | $_scip-perl cpan POE-Test-Loops 1.360 main/`@_`.[KERNEL]->delayscip-perl cpan POE-Test-Loops 1.360 main/delay().(timed_out => 2); |
| 53 | } |
| 54 | |
| 55 | sub handle_signalscip-perl cpan POE-Test-Loops 1.360 main/handle_signal(). { |
| 56 | okscip-perl cpan POE-Test-Loops 1.360 main/ok().( |
| 57 | ($_scip-perl cpan POE-Test-Loops 1.360 main/`@_`.[ARG0] eq "MOO") && |
| 58 | ($_scip-perl cpan POE-Test-Loops 1.360 main/`@_`.[ARG1] == 99), |
| 59 | "signal parameters: ('$_[ARG0]' eq 'MOO', $_[ARG1] == 99)" |
| 60 | ); |
| 61 | |
| 62 | # Wait just a little bit, in case of spurious signal. |
| 63 | POE::Kernel->delayscip-perl cpan POE-Test-Loops 1.360 POE/Kernel/delay().( timed_out => 0.250 ); |
| 64 | } |
| 65 | |
| 66 | sub timed_outscip-perl cpan POE-Test-Loops 1.360 main/timed_out(). { |
| 67 | $_scip-perl cpan POE-Test-Loops 1.360 main/`@_`.[KERNEL]->sigscip-perl cpan POE-Test-Loops 1.360 main/sig().(MOO => undef); |
| 68 | } |
| 69 | |
| 70 | 1; |