Author: lwall
Date: 2009-07-04 05:34:15 +0200 (Sat, 04 Jul 2009)
New Revision: 27399
Modified:
docs/Perl6/Spec/S04-control.pod
Log:
[S04] allow certain value-producing blocks as statement prefixes
Modified: docs/Perl6/Spec/S04-control.pod
===================================================================
--- docs/Perl6/Spec/S04-control.pod 2009-07-04 02:39:55 UTC (rev 27398)
+++ docs/Perl6/Spec/S04-control.pod 2009-07-04 03:34:15 UTC (rev 27399)
@@ -12,8 +12,8 @@
Created: 19 Aug 2004
- Last Modified: 16 Jun 2009
- Version: 80
+ Last Modified: 3 Jul 2009
+ Version: 81
This document summarizes Apocalypse 4, which covers the block and
statement syntax of Perl.
@@ -1135,6 +1135,23 @@
my $compiletime = BEGIN { localtime };
our $temphandle = START { maketemp() };
+As with other statement prefixes, these value-producing constructs
+may be placed in front of either a block or a statement:
+
+ my $compiletime = BEGIN localtime;
+ our $temphandle = START maketemp();
+
+This can be particularly useful to expose a lexically scoped
+declaration to the surrounding context. Hence these declare the same
+variables with the same scope as the preceding example, but run the
+statements as a whole at the indicated time:
+
+ BEGIN my $compiletime = localtime;
+ START our $temphandle = maketemp();
+
+(Note, however, that the value of a variable calculated at compile
+time may not persist under run-time cloning of any surrounding closure.)
+
Code that is generated at run time can still fire off C<CHECK>
and C<INIT> blocks, though of course those blocks can't do things that
would require travel back in time.