diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-09-17 12:09:22 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-09-17 12:12:30 -0700 |
commit | 986a805c4b258067b82c4f1254518e53cdb1acdf (patch) | |
tree | dc39cc8a91d0c4e01761d4e86182ab92ff7a3de5 /pod/perldelta.pod | |
parent | 7d167fe7dcb6293d9ee9583171a52b3da77f87a2 (diff) | |
download | perl-986a805c4b258067b82c4f1254518e53cdb1acdf.tar.gz |
Make IO::Handle::getline(s) respect the open pragma
See <https://rt.cpan.org/Ticket/Display.html?id=66474>. Also, this
came up in <https://rt.perl.org/rt3/Ticket/Display.html?id=92728>.
The <> operator, when reading from the magic ARGV handle, automatic-
ally opens the next file. Layers set by the lexical open pragma are
applied, if they are in scope at the point where <> is used.
This works almost all the time, because the common convention is:
use open ":utf8";
while(<>) {
...
}
IO::Handle’s getline and getlines methods are Perl subroutines
that call <> themselves. But that happens within the scope of
IO/Handle.pm, so the caller’s I/O layer settings are ignored. That
means that these two expressions are not equivalent within in a
‘use open’ scope:
<>
*ARGV->getline
The latter will open the next file with no layers applied.
This commit solves that by putting PL_check hooks in place in
IO::Handle before compiling the getline and getlines subroutines.
Those hooks cause every state op (nextstate, or dbstate under the
debugger) to have a custom pp function that saves the previous value
of PL_curcop, calls the default pp function, and then restores
PL_curcop.
That means that getline and getlines run with the caller’s compile-
time hints. Another way to see it is that getline and getlines’s own
lexical hints are never activated.
(A state op carries all the lexical pragmata. Every statement
has one. When any op executes, it’s ‘pp’ function is called.
pp_nextstate and pp_dbstate both set PL_curcop to the op itself. Any
code that checks hints looks at PL_curcop, which contains the current
run-time hints.)
Diffstat (limited to 'pod/perldelta.pod')
-rw-r--r-- | pod/perldelta.pod | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 57c8f86931..9304c49740 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -275,6 +275,19 @@ method are now hidden from filters that do not want to deal with strings =item * +L<IO> has been upgraded from version 1.25_05 to 1.25_06, and L<IO::Handle> +from version 1.32 to 1.33. + +Together, these upgrades fix a problem with IO::Handle's C<getline> and +C<getlines> methods. When these methods are called on the special ARGV +handle, the next file is automatically opened, as happens with the built-in +C<< <> >> and C<readline> functions. But, unlike the built-ins, these +methods were not respecting the caller's use of the L<open> pragma and +applying the approprate I/O layers to the newly-opened file +[rt.cpan.org #66474]. + +=item * + L<Math::BigRat> has been upgraded from version 0.2602 to version 0.2603. C<int()> on a Math::BigRat object containing -1/2 now creates a |