||= $class->_construct_meta(package => $package_name, @args);
}
-sub class_of{
+sub reinitialize {
+ my($class, $package_name, @args) = @_;
+
+ ($package_name && !ref($package_name))
+ || $class->throw_error("You must pass a package name and it cannot be blessed");
+
+ delete $METAS{$package_name};
+ return $class->initialize($package_name, @args);
+}
+
+sub _class_of{
my($class_or_instance) = @_;
return undef unless defined $class_or_instance;
return $METAS{ ref($class_or_instance) || $class_or_instance };
# Means of accessing all the metaclasses that have
# been initialized thus far
-#sub get_all_metaclasses { %METAS }
-sub get_all_metaclass_instances { values %METAS }
-sub get_all_metaclass_names { keys %METAS }
-sub get_metaclass_by_name { $METAS{$_[0]} }
-#sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
-#sub weaken_metaclass { weaken($METAS{$_[0]}) }
-#sub does_metaclass_exist { defined $METAS{$_[0]} }
-#sub remove_metaclass_by_name { delete $METAS{$_[0]} }
+#sub _get_all_metaclasses { %METAS }
+sub _get_all_metaclass_instances { values %METAS }
+sub _get_all_metaclass_names { keys %METAS }
+sub _get_metaclass_by_name { $METAS{$_[0]} }
+#sub _store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
+#sub _weaken_metaclass { weaken($METAS{$_[0]}) }
+#sub _does_metaclass_exist { defined $METAS{$_[0]} }
+#sub _remove_metaclass_by_name { delete $METAS{$_[0]} }
sub name;
require Mouse::Meta::Module; # for the entities of metaclass cache utilities
BEGIN {
- *class_of = \&Mouse::Meta::Module::class_of;
- *get_metaclass_by_name = \&Mouse::Meta::Module::get_metaclass_by_name;
- *get_all_metaclass_instances = \&Mouse::Meta::Module::get_all_metaclass_instances;
- *get_all_metaclass_names = \&Mouse::Meta::Module::get_all_metaclass_names;
+ *class_of = \&Mouse::Meta::Module::_class_of;
+ *get_metaclass_by_name = \&Mouse::Meta::Module::_get_metaclass_by_name;
+ *get_all_metaclass_instances = \&Mouse::Meta::Module::_get_all_metaclass_instances;
+ *get_all_metaclass_names = \&Mouse::Meta::Module::_get_all_metaclass_names;
# is-a predicates
generate_isa_predicate_for('Mouse::Meta::TypeConstraint' => 'is_a_type_constraint');
#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_install_simple_accessor(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_install_simple_accessor(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_install_simple_accessor(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)
CV* mouse_install_simple_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSUBADDR_t const accessor_impl, void* const dptr, I32 const dlen);
+XS(XS_Mouse_simple_accessor);
XS(XS_Mouse_simple_reader);
XS(XS_Mouse_simple_writer);
XS(XS_Mouse_simple_clearer);
INSTALL_SIMPLE_READER(Class, roles);
INSTALL_SIMPLE_PREDICATE_WITH_KEY(Class, is_anon_class, anon_serial_id);
- 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");
+ 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");
newCONSTSUB(gv_stashpvs("Mouse::Meta::Method::Constructor::XS", TRUE), "_generate_constructor",
newRV_inc((SV*)get_cvs("Mouse::Object::new", TRUE)));
INSTALL_SIMPLE_READER_WITH_KEY(Role, get_roles, roles);
INSTALL_SIMPLE_PREDICATE_WITH_KEY(Role, is_anon_role, anon_serial_id);
- INSTALL_SIMPLE_READER_WITH_DEFAULTS(Role, method_metaclass, "Mouse::Meta::Role::Method");
+ INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Role, method_metaclass, "Mouse::Meta::Role::Method");
MODULE = Mouse PACKAGE = Mouse::Object
return xsub;
}
+XS(XS_Mouse_simple_accessor)
+{
+ dVAR; dXSARGS;
+ dMOUSE_self;
+ MAGIC* const mg = (MAGIC*)XSANY.any_ptr;
+ SV* value;
+
+ 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;
+ }
+ }
+ }
+ else if(items == 2){ /* writer */
+ value = set_slot(self, MOUSE_mg_slot(mg), ST(1));
+ }
+ else {
+ croak("Expected exactly one or two argument for an accessor for '%"SVf"'", MOUSE_mg_slot(mg));
+ }
+
+ ST(0) = value;
+ XSRETURN(1);
+}
+
XS(XS_Mouse_simple_reader)
{
dVAR; dXSARGS;
}
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;
- }
- }
- ST(0) = value;
+ ST(0) = value ? value : &PL_sv_undef;
XSRETURN(1);
}
INSTALL_SIMPLE_PREDICATE_WITH_KEY(Attribute, has_builder, builder);
INSTALL_SIMPLE_PREDICATE_WITH_KEY(Attribute, has_documentation, documentation);
- INSTALL_SIMPLE_READER_WITH_DEFAULTS(Attribute, accessor_metaclass, "Mouse::Meta::Method::Accessor::XS");
+ INSTALL_SIMPLE_ACCESSOR_WITH_DEFAULTS(Attribute, accessor_metaclass, "Mouse::Meta::Method::Accessor::XS");