This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #77688] tie $scalar can tie a handle
authorFather Chrysostomos <sprout@cpan.org>
Mon, 25 Oct 2010 17:52:42 +0000 (10:52 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 25 Oct 2010 17:52:42 +0000 (10:52 -0700)
Make tie() distinguish between $scalar and *$scalar when $scalar holds
a glob copy, by checking the FAKE flag.

pp_sys.c
t/op/tie.t

index f47395b..7fa9f02 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -826,7 +826,7 @@ PP(pp_tie)
            break;
        case SVt_PVGV:
        case SVt_PVLV:
-           if (isGV_with_GP(varsv)) {
+           if (isGV_with_GP(varsv) && !SvFAKE(varsv)) {
                methname = "TIEHANDLE";
                how = PERL_MAGIC_tiedscalar;
                /* For tied filehandles, we apply tiedscalar magic to the IO
index a9fb89e..5acd9a9 100644 (file)
@@ -953,3 +953,14 @@ print ref tied *$rin, "\n";
 EXPECT
 main
 f
+########
+
+# tie $glob_copy vs tie *$glob_copy
+sub TIESCALAR { print "TIESCALAR\n" }
+sub TIEHANDLE{ print "TIEHANDLE\n" }
+$f = *foo;
+tie *$f, "";
+tie $f, "";
+EXPECT
+TIEHANDLE
+TIESCALAR