From 7289c5e6ca773d7cc3e5ad4ac9475c02875bb7bd Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 4 Nov 2011 16:37:41 -0700 Subject: [PATCH] Document unicode_eval and evalbytes --- lib/feature.pm | 47 ++++++++++++++++++++++++++++++++++++++++++ pod/perlfunc.pod | 32 ++++++++++++++++++++++++++-- t/porting/known_pod_issues.dat | 3 ++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/lib/feature.pm b/lib/feature.pm index dd44d73..ac17b00 100644 --- a/lib/feature.pm +++ b/lib/feature.pm @@ -129,6 +129,53 @@ C subpragma is B recommended. This subpragma is available starting with Perl 5.11.3, but was not fully implemented until 5.13.8. +=head2 the 'unicode_eval' and 'evalbytes' features + +Under the C feature, Perl's C function, when passed a +string, will evaluate it as a string of characters, ignoring any +C declarations. C exists to declare the encoding of +the script, which only makes sense for a stream of bytes, not a string of +characters. Source filters are forbidden, as they also really only make +sense on strings of bytes. Any attempt to activate a source filter will +result in an error. + +The C feature enables the C keyword, which evaluates +the argument passed to it as a string of bytes. It dies if the string +contains any characters outside the 8-bit range. Source filters work +within C: they apply to the contents of the string being +evaluated. + +Together, these two features are intended to replace the historical C +function, which has (at least) two bugs in it, that cannot easily be fixed +without breaking existing programs: + +=over + +=item * + +C behaves differently depending on the internal encoding of the +string, sometimes treating its argument as a string of bytes, and sometimes +as a string of characters. + +=item * + +Source filters activated within C leak out into whichever I +scope is currently being compiled. To give an example with the CPAN module +L: + + BEGIN { eval "use Semi::Semicolons; # not filtered here " } + # filtered here! + +C fixes that to work the way one would expect: + + use feature "evalbytes"; + BEGIN { evalbytes "use Semi::Semicolons; # filtered " } + # not filtered + +=back + +These two features are available starting with Perl 5.16. + =head1 FEATURE BUNDLES It's possible to load a whole slew of features in one go, using diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 4ce4be3..86770fd 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -161,7 +161,8 @@ C, C, C =item Keywords related to the control flow of your Perl program X -C, C, C, C, C, C, C, +C, C, C, C, +C, C, C C, C<__FILE__>, C, C, C<__LINE__>, C, C<__PACKAGE__>, C, C, C, C, @@ -186,7 +187,8 @@ L. Alternately, include a C or later to the current scope. =item Miscellaneous functions -C, C, C, C, C, C, C, +C, C, C, C, +C, C, C, C, C, C, C, C, C =item Functions for processes and process groups @@ -1634,6 +1636,17 @@ Note that the value is parsed every time the C executes. If EXPR is omitted, evaluates C<$_>. This form is typically used to delay parsing and subsequent execution of the text of EXPR until run time. +If the C feature is enabled (which is the default under a +C or higher declaration), EXPR or C<$_> is treated as a string of +characters, so C declarations have no effect, and source filters +are forbidden. In the absence of the C feature, the string +will sometimes be treated as characters and sometimes as bytes, depending +on the internal encoding, and source filters activated within the C +exhibit the erratic, but historical, behaviour of affecting some outer file +scope that is still compiling. See also the L keyword, which +always treats its input as a byte stream and works properly with source +filters, and the L pragma. + In the second form, the code within the BLOCK is parsed only once--at the same time the code surrounding the C itself was parsed--and executed within the context of the current Perl program. This form is typically @@ -1763,6 +1776,21 @@ surrounding lexical scope, but rather the scope of the first non-DB piece of code that called it. You don't normally need to worry about this unless you are writing a Perl debugger. +=item evalbytes EXPR +X + +=item evalbytes + +This function is like L with a string argument, except it always +parses its argument, or C<$_> if EXPR is omitted, as a string of bytes. A +string containing characters whose ordinal value exceeds 255 results in an +error. Source filters activated within the evaluated code apply to the +code itself. + +This function is only available under the C feature, a +C (or higher) declaration, or with a C prefix. See +L for more information. + =item exec LIST X X diff --git a/t/porting/known_pod_issues.dat b/t/porting/known_pod_issues.dat index 0ee1c43..d8c1933 100644 --- a/t/porting/known_pod_issues.dat +++ b/t/porting/known_pod_issues.dat @@ -1,4 +1,4 @@ -# This file is the data file for porting/podcheck.t. +# This file is the data file for t/porting/podcheck.t. # There are three types of lines. # Comment lines are white-space only or begin with a '#', like this one. Any # changes you make to the comment lines will be lost when the file is @@ -100,6 +100,7 @@ pwd_mkdb(8) recvmsg(3) s2p Scalar::Readonly +Semi::Semicolons sendmail(1) sendmsg(3) sha1sum(1) -- 1.8.3.1