@@ -1345,16 +1345,15 @@ transition from one phase of computing to another. For instance,
1345
1345
a C<CHECK> block is called at the end of compiling a compilation
1346
1346
unit. Other kinds of phasers can be installed as well; these are
1347
1347
automatically called at various times as appropriate, and some of
1348
- them respond to various control exceptions and exit values:
1348
+ them respond to various control exceptions and exit values.
1349
+ Phasers marked with a C<*> can be used for their return value.
1349
1350
1350
1351
BEGIN {...}* at compile time, ASAP, only ever runs once
1351
1352
CHECK {...}* at compile time, ALAP, only ever runs once
1352
1353
FINAL {...}* at link time, ALAP, only ever runs once
1353
1354
INIT {...}* at run time, ASAP, only ever runs once
1354
1355
END {...} at run time, ALAP, only ever runs once
1355
1356
1356
- START {...}* on first ever execution, once per closure clone
1357
-
1358
1357
ENTER {...}* at every block entry time, repeats on loop blocks.
1359
1358
LEAVE {...} at every block exit time (even stack unwinds from exceptions)
1360
1359
KEEP {...} at every successful block exit, part of LEAVE queue
@@ -1372,16 +1371,34 @@ them respond to various control exceptions and exit values:
1372
1371
1373
1372
COMPOSE {...} when a role is composed into a class
1374
1373
1375
- Those marked with a C<*> can also be used within an expression:
1374
+ Some of the statement prefixes also behave a little bit like phasers,
1375
+ but they run in-line with the executable code, so they are spelled
1376
+ in lowercase. They parse the same as phasers:
1377
+
1378
+ do {...}* run a block or statement as a term
1379
+ once {...}* run only once, suppressing additional evaluations
1380
+ gather {...}* start a co-routine thread
1381
+ lift {...}* use caller's semantics for operators
1382
+ lazy {...}* return a promise to evaluate
1383
+ sink {...}* eval eagerly and throw results away
1384
+ try {...}* evaluate and trap exceptions
1385
+ quietly {...}* evaluate and suppress warnings
1386
+ contend {...}* attempt side effects under STM
1387
+ async {...} start a subthread
1388
+
1389
+ Constructs marked with a C<*> have a run-time value, and if evaluated
1390
+ earlier than their surrounding expression, they simply save their
1391
+ result for use in the expression later when the rest of the expression
1392
+ is evaluated:
1376
1393
1377
1394
my $compiletime = BEGIN { now };
1378
- our $temphandle = START { maketemp() };
1395
+ our $temphandle = ENTER { maketemp() };
1379
1396
1380
1397
As with other statement prefixes, these value-producing constructs
1381
1398
may be placed in front of either a block or a statement:
1382
1399
1383
1400
my $compiletime = BEGIN now;
1384
- our $temphandle = START maketemp();
1401
+ our $temphandle = ENTER maketemp();
1385
1402
1386
1403
In fact, most of these phasers will take either a block or a statement
1387
1404
(known as a I<blast> in the vernacular). The statement form can be
@@ -1393,7 +1410,7 @@ variables with the same scope as the preceding example, but run the
1393
1410
statements as a whole at the indicated time:
1394
1411
1395
1412
BEGIN my $compiletime = now;
1396
- START our $temphandle = maketemp();
1413
+ ENTER our $temphandle = maketemp();
1397
1414
1398
1415
(Note, however, that the value of a variable calculated at compile
1399
1416
time may not persist under run-time cloning of any surrounding closure.)
@@ -1433,7 +1450,7 @@ the closure as its topic:
1433
1450
Apart from C<CATCH> and C<CONTROL>, which can only occur once, most
1434
1451
of these can occur multiple times within the block. So they aren't
1435
1452
really traits, exactly--they add themselves onto a list stored in the
1436
- actual trait (except for C<START>, which executes inline) . So if you
1453
+ actual trait. So if you
1437
1454
examine the C<ENTER> trait of a block, you'll find that it's really
1438
1455
a list of phasers rather than a single phaser. In general, initializing
1439
1456
phasers execute in order declared, while finalizing phasers execute in
@@ -1443,16 +1460,16 @@ the using module. (It is erroneous to depend on this order if the
1443
1460
module is used more than once, however, since the phasers are only
1444
1461
installed the first time they're noticed.)
1445
1462
1446
- The semantics of C<INIT> and C<START > are not equivalent to each
1463
+ The semantics of C<INIT> and C<once > are not equivalent to each
1447
1464
other in the case of cloned closures. An C<INIT> only runs once for
1448
- all copies of a cloned closure. A C<START > runs separately for each
1465
+ all copies of a cloned closure. A C<once > runs separately for each
1449
1466
clone, so separate clones can keep separate state variables:
1450
1467
1451
1468
our $i = 0;
1452
1469
...
1453
1470
$func = { state $x will start { $x = $i++ }; dostuff($i) };
1454
1471
1455
- But C<state> automatically applies "start " semantics to any initializer,
1472
+ But C<state> automatically applies "once " semantics to any initializer,
1456
1473
so this also works:
1457
1474
1458
1475
$func = { state $x = $i++; dostuff($i) }
@@ -1462,11 +1479,11 @@ previous, and each clone maintains its own state of C<$x>, because that's
1462
1479
what C<state> variables do.
1463
1480
1464
1481
Even in the absence of closure cloning, C<INIT> runs before the
1465
- mainline code, while C<START > puts off the initialization till the
1482
+ mainline code, while C<once > puts off the initialization till the
1466
1483
last possible moment, then runs exactly once, and caches its value
1467
1484
for all subsequent calls (assuming it wasn't called in sink context,
1468
- in which case the C<START > is evaluated once only for its side effects).
1469
- In particular, this means that C<START > can make use of any parameters
1485
+ in which case the C<once > is evaluated once only for its side effects).
1486
+ In particular, this means that C<once > can make use of any parameters
1470
1487
passed in on the first call, whereas C<INIT> cannot.
1471
1488
1472
1489
All of these phaser blocks can see any previously declared lexical
@@ -1496,7 +1513,7 @@ by C<next>. In particular, a C<last> bypasses evaluation of C<NEXT>
1496
1513
phasers.
1497
1514
1498
1515
[Note: the name C<FIRST> used to be associated with C<state>
1499
- declarations. Now it is associated only with loops. See the C<START >
1516
+ declarations. Now it is associated only with loops. See the C<once >
1500
1517
above for C<state> semantics.]
1501
1518
1502
1519
Except for C<CATCH> and C<CONTROL> phasers, which run while an exception
0 commit comments