Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (94 sloc) 2.619 kB
616bb10 [rt.cpan.org 79886] Fix SIGDIE handler save/restore for Perl 5.8.8.
Philip Gwyn authored
1 #!/usr/bin/perl
2 # vim: ts=2 sw=2 filetype=perl expandtab
3
4 use warnings;
5 use strict;
6
7 use Test::More tests => 12;
8
9 BEGIN { $ENV{POE_CATCH_EXCEPTIONS} = 0; }
10
11 use POE;
12 use POE::Session;
13 use POE::Kernel;
14
15 our $WANT;
16
17 sub my_die {
18 my( $err ) = @_;
19 chomp $err;
20 is( $err, $WANT, "error $WANT" );
21 die "$err\nmore\n";
22 }
23
24 my $poe_dummy_sigdie = \&POE::Kernel::_dummy_sigdie_handler;
25
26 POE::Session->create(
27 inline_states => {
28 _start => sub {
29 ok(
30 (
31 not defined $SIG{__DIE__} or
32 $SIG{__DIE__} eq $poe_dummy_sigdie
33 ),
34 '_start'
35 );
36 $poe_kernel->yield( 'step2' );
37 },
38
39 #####
40
41 step2 => sub {
42 # make sure we have a reset __DIE__ in yield
43 ok(
44 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
45 'step2'
46 );
47 my $ret = $poe_kernel->call( $_[SESSION], 'scalar_ctx' );
48 is( $ret, 42, 'ret' );
49 my @ret = $poe_kernel->call( $_[SESSION], 'array_ctx' );
50 is_deeply( \@ret, [ 1..17 ], 'ret' );
51
52
53 $SIG{__DIE__} = \&my_die;
54 $poe_kernel->post( $_[SESSION], 'step3' );
55 },
56
57 scalar_ctx => sub {
58 # make sure we have a reset __DIE__ in call to scalar context
59 ok(
60 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
61 'scalar_ctx'
62 );
63 return 42;
64 },
65
66 array_ctx => sub {
67 # make sure we have a reset __DIE__ in call to array context
68 ok(
69 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
70 'array_ctx'
71 );
72 return ( 1..17 );
73 },
74
75 #####
76
77 step3 => sub {
78 # make sure we have a reset __DIE__ in a post
79 ok(
80 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
81 'step3'
82 );
83 my $ret = $poe_kernel->call( $_[SESSION], 'scalar_ctx3' );
84 is( $ret, 42, 'ret' );
85 my @ret = $poe_kernel->call( $_[SESSION], 'array_ctx3' );
86 fail( 'we never get here' );
87 },
88
89 scalar_ctx3 => sub {
90 # make sure we have a reset __DIE__ even if we set one
91 ok(
92 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
93 'scalar_ctx3'
94 );
95 return 42;
96 },
97
98 array_ctx3 => sub {
99 # now we throw an execption up to our __DIE__ handler
100 ok(
101 (not defined $SIG{__DIE__} or $SIG{__DIE__} eq $poe_dummy_sigdie ),
102 'array_ctx'
103 );
104 $WANT = "array_ctx3";
105 die "$WANT\n";
106 return ( 1..17 );
107 },
108 }
109 );
110
111 eval { $poe_kernel->run };
112
113 # make sure we caught the execption thrown in array_ctx3
114 is($@, "array_ctx3\nmore\n", 'exited');
Something went wrong with that request. Please try again.