Change class holders to simple readers
gfx [Thu, 26 Nov 2009 12:50:37 +0000 (21:50 +0900)]
mouse.h
xs-src/Mouse.xs
xs-src/MouseAccessor.xs
xs-src/MouseAttribute.xs

diff --git a/mouse.h b/mouse.h
index 6ddd634..718350c 100644 (file)
--- a/mouse.h
+++ b/mouse.h
@@ -142,16 +142,16 @@ void mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot);
 #define set_slots(self, key, value) set_slot(self, sv_2mortal(newSVpvs_share(key)), value)
 
 /* mouse_simle_accessor.xs */
-#define INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTSV(klass, name, dsv) \
-    (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" #name, #name, sizeof(#name)-1, XS_Mouse_simple_accessor, (dsv), HEf_SVKEY)
-#define INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(klass, name, ds) \
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTSV(klass, name, newSVpvs(ds))
-
 #define INSTALL_SIMPLE_READER(klass, name) \
     INSTALL_SIMPLE_READER_WITH_KEY(klass, name, name)
 #define INSTALL_SIMPLE_READER_WITH_KEY(klass, name, key) \
     (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" #name, #key, sizeof(#key)-1, XS_Mouse_simple_reader, NULL, 0)
 
+#define INSTALL_SIMPLE_READER_WITH_DEFAULTSV(klass, name, dsv) \
+    (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" #name, #name, sizeof(#name)-1, XS_Mouse_simple_reader, (dsv), HEf_SVKEY)
+#define INSTALL_SIMPLE_READER_WITH_DEFAULTS(klass, name, ds) \
+    INSTALL_SIMPLE_READER_WITH_DEFAULTSV(klass, name, newSVpvs(ds))
+
 #define INSTALL_SIMPLE_WRITER(klass, name) \
     NSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, name)
 #define INSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, key) \
index 3b1520f..5fca14f 100644 (file)
@@ -437,10 +437,10 @@ BOOT:
     INSTALL_SIMPLE_READER(Class, roles);
     INSTALL_SIMPLE_PREDICATE_WITH_KEY(Class, is_anon_class, anon_serial_id);
 
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Class, method_metaclass,     "Mouse::Meta::Method");
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Class, attribute_metaclass,  "Mouse::Meta::Attribute");
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Class, constructor_class,    "Mouse::Meta::Method::Constructor::XS");
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Class, destructor_class,     "Mouse::Meta::Method::Destructor::XS");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Class, method_metaclass,     "Mouse::Meta::Method");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Class, attribute_metaclass,  "Mouse::Meta::Attribute");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Class, constructor_class,    "Mouse::Meta::Method::Constructor::XS");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Class, destructor_class,     "Mouse::Meta::Method::Destructor::XS");
 
     newCONSTSUB(gv_stashpvs("Mouse::Meta::Method::Constructor::XS", TRUE), "_generate_constructor",
         newRV_inc((SV*)get_cvs("Mouse::Object::new", TRUE)));
@@ -508,7 +508,7 @@ BOOT:
     INSTALL_SIMPLE_READER_WITH_KEY(Role, get_roles, roles);
     INSTALL_SIMPLE_PREDICATE_WITH_KEY(Role, is_anon_role, anon_serial_id);
 
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Role, method_metaclass,  "Mouse::Meta::Role::Method");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Role, method_metaclass,  "Mouse::Meta::Role::Method");
 
 MODULE = Mouse  PACKAGE = Mouse::Object
 
index 4dd16dd..5d6bcbf 100644 (file)
@@ -254,15 +254,8 @@ XS(XS_Mouse_simple_accessor)
 
     if(items == 1){ /* reader */
         value = get_slot(self, MOUSE_mg_slot(mg));
-        if(!value) {
-            if(MOUSE_mg_ptr(mg)){
-                /* the default value must be a SV */
-                assert(MOUSE_mg_len(mg) == HEf_SVKEY);
-                value = (SV*)MOUSE_mg_ptr(mg);
-            }
-            else{
-                value = &PL_sv_undef;
-            }
+        if(!value){
+            value = &PL_sv_undef;
         }
     }
     else if(items == 2){ /* writer */
@@ -288,7 +281,18 @@ XS(XS_Mouse_simple_reader)
     }
 
     value = get_slot(self, MOUSE_mg_slot(mg));
-    ST(0) = value ? value : &PL_sv_undef;
+    if(!value) {
+        if(MOUSE_mg_ptr(mg)){
+            /* the default value must be a SV */
+            assert(MOUSE_mg_len(mg) == HEf_SVKEY);
+            value = (SV*)MOUSE_mg_ptr(mg);
+        }
+        else{
+            value = &PL_sv_undef;
+        }
+    }
+
+    ST(0) = value;
     XSRETURN(1);
 }
 
index f494f17..30163fb 100644 (file)
@@ -218,5 +218,5 @@ BOOT:
     INSTALL_SIMPLE_PREDICATE_WITH_KEY(Attribute, has_builder, builder);
     INSTALL_SIMPLE_PREDICATE_WITH_KEY(Attribute, has_documentation, documentation);
 
-    INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Attribute, accessor_metaclass, "Mouse::Meta::Method::Accessor::XS");
+    INSTALL_SIMPLE_READER_WITH_DEFAULTS(Attribute, accessor_metaclass, "Mouse::Meta::Method::Accessor::XS");