develooper Front page | perl.perl5.porters | Postings from December 2000

[PATCH] lvalue AUTOLOAD. No, really.

Thread Next
From:
Simon Cozens
Date:
December 26, 2000 19:46
Subject:
[PATCH] lvalue AUTOLOAD. No, really.
Message ID:
20001227023003.A7677@deep-dark-truthful-mirror.perlhacker.org
This'll make ya sick.

--- pp.c~	Wed Dec 27 01:54:01 2000
+++ pp.c	Wed Dec 27 02:13:17 2000
@@ -385,8 +385,12 @@
     if (cv) {
 	if (CvCLONE(cv))
 	    cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
-	if ((PL_op->op_private & OPpLVAL_INTRO) && !CvLVALUE(cv))
-	    DIE(aTHX_ "Can't modify non-lvalue subroutine call");
+	if ((PL_op->op_private & OPpLVAL_INTRO)) {
+	    if (gv && GvCV(gv) == cv && (gv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), FALSE)))
+		cv = GvCV(gv);
+	    if (!CvLVALUE(cv))
+		DIE(aTHX_ "Can't modify non-lvalue subroutine call");
+	}
     }
     else
 	cv = (CV*)&PL_sv_undef;
--- t/pragma/sub_lval.t~	Wed Dec 27 02:14:36 2000
+++ t/pragma/sub_lval.t	Wed Dec 27 02:17:14 2000
@@ -1,4 +1,4 @@
-print "1..46\n";
+print "1..47\n";
 
 BEGIN {
     chdir 't' if -d 't';
@@ -427,3 +427,12 @@
 $a->() = 8;
 print "# '$nnewvar'.\nnot " unless $nnewvar eq '8';
 print "ok 46\n";
+
+# This must happen at run time
+eval {
+    sub AUTOLOAD : lvalue { $newvar };
+};
+foobar() = 12;
+print "# '$newvar'.\nnot " unless $newvar eq "12";
+print "ok 47\n";
+

This still doesn't allow "foo = bar", unfortunately, which is necessary for
the future of Perl poetry. That's coming up. :)

-- 
"Which you then convert to gold, non-perishable food, firearms, good liquor & 
a secluded hideaway in the last of the internet official protocol standards"
        -- Megahal (trained on asr), 1998-11-05

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About