develooper Front page | perl.perl5.porters | Postings from March 2003

Re: [patch] small lib.pm bufgixes

Thread Previous
From:
Alex Vandiver
Date:
March 2, 2003 03:19
Subject:
Re: [patch] small lib.pm bufgixes
Message ID:
1046603955.32277.11.camel@supox
On Thu, 2003-02-27 at 06:20, Nicholas Clark wrote:
> Possibly the logic of the tests in 5.8 is wrong - if you put an object in
> that is a blessed array, it gets treated as "array" (ie fetch element 0
> and use it subsequently; pass the whole array in as arguments)
> rather than "object"
If I'm reading you right ("blessed coderefs are currently treated as
arrays") then this is incorrect -- blessed coderefs are currently
treated as objects, not arrays.  This is probably as it Should Be.
  However, due to a shortcut, if the first element in the array is a
blessed coderef, one gets the rather misleading error:
Can't call method "INC" on unblessed reference ...
  The patch below fixes this.  As this is my first foray into dabbling
with the perl code, comments and criticisms are appreciated..
 - Alex V.

diff -ruN perl-current/pp_ctl.c perl-patched/pp_ctl.c
--- perl-current/pp_ctl.c	Wed Feb 26 16:51:33 2003
+++ perl-patched/pp_ctl.c	Sun Mar  2 05:39:39 2003
@@ -3049,12 +3049,6 @@
 		    int count;
 		    SV *loader = dirsv;
 
-		    if (SvTYPE(SvRV(loader)) == SVt_PVAV
-			&& !sv_isobject(loader))
-		    {
-			loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
-		    }
-
 		    Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
 				   PTR2UV(SvRV(dirsv)), name);
 		    tryname = SvPVX(namesv);
@@ -3065,13 +3059,25 @@
 		    EXTEND(SP, 2);
 
 		    PUSHMARK(SP);
-		    PUSHs(dirsv);
-		    PUSHs(sv);
-		    PUTBACK;
-		    if (sv_isobject(loader))
-			count = call_method("INC", G_ARRAY);
-		    else
+
+		    if (SvTYPE(SvRV(loader)) == SVt_PVAV
+			&& !sv_isobject(loader))
+		    {
+			PUSHs(loader);
+			loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
+			PUSHs(sv);
+			PUTBACK;
 			count = call_sv(loader, G_ARRAY);
+		    }
+		    else {
+			PUSHs(loader);
+			PUSHs(sv);
+			PUTBACK;
+			if (sv_isobject(loader))
+			  count = call_method("INC", G_ARRAY);
+			else
+			  count = call_sv(loader, G_ARRAY);
+		    }
 		    SPAGAIN;
 
 		    if (count > 0) {
diff -ruN perl-current/t/op/inccode.t perl-patched/t/op/inccode.t
--- perl-current/t/op/inccode.t	Tue Jan 29 22:03:23 2002
+++ perl-patched/t/op/inccode.t	Sun Mar  2 06:03:55 2003
@@ -10,7 +10,7 @@
 use File::Spec;
 
 require "test.pl";
-plan(tests => 44);
+plan(tests => 45);
 
 my @tempfiles = ();
 
@@ -173,6 +173,13 @@
 
 pop @INC;
 
+push @INC, [bless \&fooinc, "Moose"];
+
+$evalret = eval {require Foo4; 1 };
+ok( $evalret,                     'require Foo4; magic via blessed coderef in arrayref' );
+
+pop @INC;
+
 my $filename = $^O eq 'MacOS' ? ':Foo:Foo.pm' : './Foo.pm';
 {
     local @INC;

-- 
Networking -- only one letter away from not working.


Thread Previous


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