In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/b932b26697523f5576f3c2608445dfafe32b8832?hp=79bffe477e0016f596b86950244ad3a10a753e58>

- Log -----------------------------------------------------------------
commit b932b26697523f5576f3c2608445dfafe32b8832
Author: Father Chrysostomos <[email protected]>
Date:   Tue Sep 18 08:29:25 2012 -0700

    perldelta for ${^LAST_FH}

M       pod/perldelta.pod

commit 8561ea1dd1a3357825e765e1df4f883e53f89a9d
Author: Father Chrysostomos <[email protected]>
Date:   Mon Sep 17 23:18:08 2012 -0700

    ${^LAST_FH}
    
    This was brought up in ticket #96672.
    
    This variable gives access to the last-read filehandle that Perl uses
    when it appends ", <STDIN> line 1" to a warning or error message.

M       gv.c
M       mg.c
M       pod/perlvar.pod
M       t/op/magic.t
-----------------------------------------------------------------------

Summary of changes:
 gv.c              |    4 ++++
 mg.c              |   14 ++++++++++++++
 pod/perldelta.pod |    6 ++++++
 pod/perlvar.pod   |   11 +++++++++++
 t/op/magic.t      |   17 ++++++++++++++++-
 5 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/gv.c b/gv.c
index 55666f4..08d41db 100644
--- a/gv.c
+++ b/gv.c
@@ -1787,6 +1787,10 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN 
full_len, I32 flags,
                if (strEQ(name2, "LOBAL_PHASE"))
                    goto ro_magicalize;
                break;
+           case '\014':        /* $^LAST_FH */
+               if (strEQ(name2, "AST_FH"))
+                   goto ro_magicalize;
+               break;
             case '\015':        /* $^MATCH */
                 if (strEQ(name2, "ATCH"))
                    goto magicalize;
diff --git a/mg.c b/mg.c
index 26cabbe..cbae421 100644
--- a/mg.c
+++ b/mg.c
@@ -906,6 +906,20 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
     case '\011':               /* ^I */ /* NOT \t in EBCDIC */
        sv_setpv(sv, PL_inplace); /* Will undefine sv if PL_inplace is NULL */
        break;
+    case '\014':               /* ^LAST_FH */
+       if (strEQ(remaining, "AST_FH")) {
+           if (PL_last_in_gv) {
+               assert(isGV_with_GP(PL_last_in_gv));
+               SV_CHECK_THINKFIRST_COW_DROP(sv);
+               prepare_SV_for_RV(sv);
+               SvOK_off(sv);
+               SvRV_set(sv, SvREFCNT_inc_simple_NN(PL_last_in_gv));
+               SvROK_on(sv);
+               sv_rvweaken(sv);
+           }
+           else sv_setsv_nomg(sv, NULL);
+       }
+       break;
     case '\017':               /* ^O & ^OPEN */
        if (nextchar == '\0') {
            sv_setpv(sv, PL_osname);
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index dd14be7..7d3ef03 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -52,6 +52,12 @@ The following new DTrace probes have been added:
 
 =back
 
+=head2 C<${^LAST_FH}>
+
+This new variable provides access to the filehandle that was last read.
+This is the handle used by C<$.> and by C<tell> and C<eof> without
+arguments.
+
 =head2 Looser here-doc parsing
 
 Here-doc terminators no longer require a terminating newline character when
diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index 69e18ce..fc99b8e 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -1401,6 +1401,17 @@ how to select the output channel.  See also 
L<IO::Handle>.
 
 Mnemonic: when you want your pipes to be piping hot.
 
+=item ${^LAST_FH}
+X<${^LAST_FH}>
+
+This read-only variable contains a reference to the last-read filehandle.
+This is set by C<< <HANDLE> >>, C<readline>, C<tell>, C<eof> and C<seek>.
+This is the same handle that C<$.> and C<tell> and C<eof> without arguments
+use.  It is also the handle used when Perl appends ", <STDIN> line 1" to
+an error or warning message.
+
+This variable was added in Perl v5.18.0.
+
 =back
 
 =head3 Variables related to formats
diff --git a/t/op/magic.t b/t/op/magic.t
index 5ddba3c..d3f6a48 100644
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -5,7 +5,7 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan (tests => 171);
+    plan (tests => 176);
 }
 
 # Test that defined() returns true for magic variables created on the fly,
@@ -20,6 +20,7 @@ BEGIN {
        SIG ^OPEN ^TAINT ^UNICODE ^UTF8LOCALE ^WARNING_BITS 1 2 3 4 5 6 7 8
        9 42 & ` ' : ? ! _ - [ ^ ~ = % . ( ) < > \ / $ | + ; ] ^A ^C ^D
        ^E ^F ^H ^I ^L ^N ^O ^P ^S ^T ^V ^W ^UTF8CACHE ::12345 main::98732
+       ^LAST_FH
     )) {
        my $v = $_;
        # avoid using any global vars here:
@@ -604,6 +605,20 @@ SKIP: {
     }
 }
 
+# ${^LAST_FH}
+() = tell STDOUT;
+is ${^LAST_FH}, \*STDOUT, '${^LAST_FH} after tell';
+() = tell STDIN;
+is ${^LAST_FH}, \*STDIN, '${^LAST_FH} after another tell';
+{
+    my $fh = *STDOUT;
+    () = tell $fh;
+    is ${^LAST_FH}, \$fh, '${^LAST_FH} referencing lexical coercible glob';
+}
+# This also tests that ${^LAST_FH} is a weak reference:
+is ${^LAST_FH}, undef, '${^LAST_FH} is undef when PL_last_in_gv is NULL';
+
+
 # ^^^^^^^^^ New tests go here ^^^^^^^^^
 
 SKIP: {

--
Perl5 Master Repository

Reply via email to