1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
use warnings;
use strict;
use Test::More tests => 3;
use XS::APItest qw(establish_cleanup);
my @events;
# unwinding on local return from sub
sub aa {
push @events, "aa0";
establish_cleanup sub { push @events, "bb0" };
push @events, "aa1";
"aa2";
}
sub cc {
push @events, "cc0";
push @events, [ "cc1", aa() ];
push @events, "cc2";
"cc3";
}
@events = ();
push @events, "dd0";
push @events, [ "dd1", cc() ];
is_deeply \@events, [
"dd0",
"cc0",
"aa0",
"aa1",
"bb0",
[ "cc1", "aa2" ],
"cc2",
[ "dd1", "cc3" ],
];
# unwinding on local return from format
sub ff { push @events, "ff0" }
format EE =
@<<
((push @events, "ee0"), (establish_cleanup \&ff), (push @events, "ee1"), "ee2")
.
sub gg {
push @events, "gg0";
write(EE);
push @events, "gg1";
"gg2";
}
@events = ();
open EE, ">", \(my $ee);
push @events, "hh0";
push @events, [ "hh1", gg() ];
close EE;
is_deeply \@events, [
"hh0",
"gg0",
"ee0",
"ee1",
"ff0",
"gg1",
[ "hh1", "gg2" ],
];
# unwinding on die
sub pp {
my $value = eval {
push @events, "pp0";
establish_cleanup sub { push @events, "qq0" };
push @events, "pp1";
die "pp2\n";
push @events, "pp3";
"pp4";
};
[ "pp5", $value, $@ ];
}
@events = ();
push @events, "rr0";
push @events, [ "rr1", pp() ];
is_deeply \@events, [
"rr0",
"pp0",
"pp1",
"qq0",
[ "rr1", [ "pp5", undef, "pp2\n" ] ],
];
1;
|