NAME Syntax::Keyword::PhaserExpression - phasers as arbitrary expressions rather than blocks SYNOPSIS use Syntax::Keyword::PhaserExpression; if( BEGIN $ENV{DEBUG} ) { printf STDERR "Here's a debugging message> %s\n", gen_debug(); } DESCRIPTION This module provides a syntax plugin that alters the behaviour of perl's BEGIN keyword. This allows hoisting an expression to be evaluated at compile-time, and replace its result into the compiled code. This may be useful for performance, to avoid otherwise-expensive calls whose value won't change, or to inline constants for other performance-related benefits. There may also be situations where it is useful to have expressions evaluated early enough in compiletime so that their effects can influence the compilation of later code. KEYWORDS BEGIN BEGIN expr... An expression prefixed with the BEGIN keyword is evaluated as soon as it is compiled. The scalar result is then captured and inlined, as a constant, into the surrounding code. As the expression is not a full block, it does not create a surrounding scope that hides lexical variables inside it. This can be useful for assigning a value to a variable at compiletime so that later compiletime expressions can see its value. BEGIN my $arg = "the value"; use Some::Module arg => $arg; Note that the expression may not start with an open brace ({) character, as that is used by regular Perl's BEGIN block. This module does not replace that syntax. TODO * Implement some other phaser keywords. CHECK and INIT might be useful. Not END for obvious reasons. ;) AUTHOR Paul Evans