# bless {}, $self->_class_name;
#}
-sub clone_instance {
- my ($self, $instance) = @_;
- bless { %$instance }, $self->_class_name;
-}
+#sub clone_instance {
+# my ($self, $instance) = @_;
+# bless { %$instance }, $self->_class_name;
+#}
# operations on meta instance
typedef struct {
SV* (*create_instance)(pTHX_ HV* const stash);
+ SV* (*clone_instance) (pTHX_ SV* const instance);
bool (*has_slot) (pTHX_ SV* const mi, SV* const instance);
SV* (*get_slot) (pTHX_ SV* const mi, SV* const instance);
SV* (*set_slot) (pTHX_ SV* const mi, SV* const instance, SV* const value);
/* Class::MOP::Instance stuff */
SV* mop_instance_create (pTHX_ HV* const stash);
-SV* mop_instance_slot (pTHX_ SV* const meta_instance, SV* const attr);
+SV* mop_instance_clone (pTHX_ SV* const instance);
bool mop_instance_has_slot (pTHX_ SV* const instance, SV* const slot);
SV* mop_instance_get_slot (pTHX_ SV* const instance, SV* const slot);
SV* mop_instance_set_slot (pTHX_ SV* const instance, SV* const slot, SV* const value);
#define MOP_mg_obj_refcounted_on(mg) (void)((mg)->mg_flags |= MGf_REFCOUNTED);
#define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash))
+#define MOP_mg_clone_instance(mg, o) MOP_mg_vtbl(mg)->clone_instance (aTHX_ (o))
#define MOP_mg_has_slot(mg, o, slot) MOP_mg_vtbl(mg)->has_slot (aTHX_ (o), (slot))
#define MOP_mg_get_slot(mg, o, slot) MOP_mg_vtbl(mg)->get_slot (aTHX_ (o), (slot))
#define MOP_mg_set_slot(mg, o, slot, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (o), (slot), (v))
return sv_bless( newRV_noinc((SV*)newHV()), stash );
}
+SV*
+mop_instance_clone(pTHX_ SV* const instance) {
+ HV* proto;
+ assert(instance);
+
+ CHECK_INSTANCE(instance);
+ proto = newHVhv((HV*)SvRV(instance));
+ return sv_bless( newRV_noinc((SV*)proto), SvSTASH(SvRV(instance)) );
+}
+
+
+
bool
mop_instance_has_slot(pTHX_ SV* const instance, SV* const slot) {
assert(instance);
static const mop_instance_vtbl mop_default_instance = {
mop_instance_create,
+ mop_instance_clone,
mop_instance_has_slot,
mop_instance_get_slot,
mop_instance_set_slot,
OUTPUT:
RETVAL
+SV*
+clone_instance(SV* self, SV* instance)
+CODE:
+ PERL_UNUSED_VAR(self);
+ RETVAL = mop_instance_clone(aTHX_ instance);
+OUTPUT:
+ RETVAL
+
bool
is_slot_initialized(SV* self, SV* instance, SV* slot)
CODE: