Implement naming routine in add_package_symbol(xsub) to avoid type-glob duplication
gfx [Wed, 22 Jul 2009 08:39:35 +0000 (17:39 +0900)]
lib/Class/MOP/Class.pm
xs/Package.xs

index 2a975e8..1f5ec44 100644 (file)
@@ -636,14 +636,6 @@ sub add_method {
         $body = $method;
     }
 
-
-    my ( $current_package, $current_name ) = Class::MOP::get_code_info($body);
-
-    if ( !defined $current_name || $current_name eq '__ANON__' ) {
-        my $full_method_name = ($self->name . '::' . $method_name);
-        subname($full_method_name => $body);
-    }
-
     $self->add_package_symbol(
         { sigil => '&', type => 'CODE', name => $method_name },
         $body,
index c552f56..e7e444a 100644 (file)
@@ -197,7 +197,7 @@ CODE:
 
                gv = gv_fetchpv(fq_name, ix | (flags & GLOB_CREATE ? GV_ADDMULTI : 0), type);
        }
-
+       assert(isGV_with_GP(gv));
 
 
        if(SvOK(ref)){ /* add_package_symbol with a value */
@@ -217,6 +217,17 @@ CODE:
                        GvCV(gv) = NULL;
                }
                sv_setsv_mg((SV*)gv, ref); /* *glob = $ref */
+
+               if(type == SVt_PVCV){
+                       CV* const subr = (CV*)SvRV(ref);
+                       if(CvANON(subr)
+                               && CvGV(subr)
+                               && isGV(CvGV(subr))
+                               && strEQ(GvNAME(CvGV(subr)), "__ANON__")){
+                               CvGV(subr) = gv;
+                               CvANON_off(subr);
+                       }
+               }
                RETVAL = ref;
        }
        else { /* no values */