@@ -19,6 +19,7 @@ them respond to various control exceptions and exit values.
19
19
20
20
Here is a summary:
21
21
22
+ = begin code :skip-test
22
23
BEGIN {...} # * at compile time, ASAP, only ever runs once
23
24
CHECK {...} # * at compile time, ALAP, only ever runs once
24
25
INIT {...} # * at run time, ASAP, only ever runs once
@@ -44,19 +45,20 @@ Here is a summary:
44
45
45
46
COMPOSE {...} # when a role is composed into a class
46
47
CLOSE {...} # appears in a supply block, called when the supply is closed
48
+ = end code
47
49
48
50
Phasers marked with a C < * > have a run-time value, and if evaluated earlier than
49
51
their surrounding expression, they simply save their result for use in the
50
52
expression later when the rest of the expression is evaluated:
51
53
52
54
my $compiletime = BEGIN { now };
53
- our $temphandle = ENTER { maketemp() };
55
+ our $random = ENTER { rand };
54
56
55
57
As with other statement prefixes, these value-producing constructs may be
56
58
placed in front of either a block or a statement:
57
59
58
60
my $compiletime = BEGIN now;
59
- our $temphandle = ENTER maketemp() ;
61
+ our $random = ENTER rand ;
60
62
61
63
Most of these phasers will take either a block or a function reference. The
62
64
statement form can be particularly useful to expose a lexically scoped
@@ -67,12 +69,11 @@ These declare the same variables with the same scope as the preceding example,
67
69
but run the statements as a whole at the indicated time:
68
70
69
71
BEGIN my $compiletime = now;
70
- ENTER our $temphandle = maketemp() ;
72
+ ENTER our $random = rand ;
71
73
72
74
(Note, however, that the value of a variable calculated at compile time may not
73
75
persist under run-time cloning of any surrounding closure.)
74
76
75
-
76
77
Most of the non-value-producing phasers may also be so used:
77
78
78
79
END say my $accumulator;
@@ -117,55 +118,66 @@ teardown usually want to happen in the opposite order from each other.
117
118
118
119
= head2 Execution Order
119
120
120
- Compilation Begins
121
+ Compilation Begins
121
122
123
+ = for code :skip-test
122
124
BEGIN {...} # at compile time, ASAP, only ever runs once
123
125
CHECK {...} # at compile time, ALAP, only ever runs once
124
126
COMPOSE {...} # when a role is composed into a class
125
127
126
- Execution Begins
128
+ Execution Begins
127
129
130
+ = for code :skip-test
128
131
INIT {...} # at run time, ASAP, only ever runs once
129
132
130
- Before block execution begins
133
+ Before block execution begins
131
134
135
+ = for code :skip-test
132
136
PRE {...} # assert precondition at every block entry, before ENTER
133
137
134
- Loop execution begins
138
+ Loop execution begins
135
139
140
+ = for code :skip-test
136
141
FIRST {...} # at loop initialization time, before any ENTER
137
142
138
- Block execution begins
143
+ Block execution begins
139
144
145
+ = for code :skip-test
140
146
ENTER {...} # at every block entry time, repeats on loop blocks.
141
147
142
- Exception maybe happens
148
+ Exception maybe happens
143
149
150
+ = for code :skip-test
144
151
CATCH {...} # catch exceptions, before LEAVE
145
152
CONTROL {...} # catch control exceptions, before LEAVE
146
153
147
- End of loop, either continuing or finished
154
+ End of loop, either continuing or finished
148
155
156
+ = for code :skip-test
149
157
NEXT {...} # at loop continuation time, before any LEAVE
150
158
LAST {...} # at loop termination time, after any LEAVE
151
159
152
- End of block
160
+ End of block
153
161
162
+ = for code :skip-test
154
163
LEAVE {...} # at every block exit time (even stack unwinds from exceptions)
155
164
KEEP {...} # at every successful block exit, part of LEAVE queue
156
165
UNDO {...} # at every unsuccessful block exit, part of LEAVE queue
157
166
158
- Postcondition for block
167
+ Postcondition for block
159
168
169
+ = for code :skip-test
160
170
POST {...} # assert postcondition at every block exit, after LEAVE
161
171
162
- Async whenever-block is complete
172
+ Async whenever-block is complete
163
173
174
+ = for code :skip-test
164
175
LAST {...} # if ended normally with done, runs once after block
165
176
QUIT {...} # catch async exceptions
166
177
167
- Program terminating
178
+ Program terminating
168
179
180
+ = for code :skip-test
169
181
END {...} # at run time, ALAP, only ever runs once
170
182
171
183
= head1 Program Execution Phasers
0 commit comments