mouse_class_initialize_object(pTHX_ SV* const meta, SV* const object, HV* const args, bool const is_cloning) {
AV* const xc = mouse_get_xc(aTHX_ meta);
AV* const attrs = MOUSE_xc_attrall(xc);
- I32 len = AvFILLp(attrs) + 1;
+ I32 const len = AvFILLp(attrs) + 1;
I32 i;
AV* triggers_queue = NULL;
I32 used = 0;
}
used++;
}
- else if(!is_cloning){ /* no init arg, noop while cloning */
+ else { /* no init arg */
if(flags & (MOUSEf_ATTR_HAS_DEFAULT | MOUSEf_ATTR_HAS_BUILDER)){
- if(!(flags & MOUSEf_ATTR_IS_LAZY)){
+ /* skip if the object has the slot (it occurs on cloning/reblessing) */
+ if(!(flags & MOUSEf_ATTR_IS_LAZY) && !has_slot(object, slot)){
mouse_xa_set_default(aTHX_ xa, object);
}
}
- else if(flags & MOUSEf_ATTR_IS_REQUIRED) {
+ /* don't check while cloning (or reblesseing) */
+ else if(!is_cloning && flags & MOUSEf_ATTR_IS_REQUIRED) {
mouse_throw_error(attr, NULL, "Attribute (%"SVf") is required", slot);
}
}
}
if(triggers_queue){
- len = AvFILLp(triggers_queue) + 1;
+ I32 const len = AvFILLp(triggers_queue) + 1;
for(i = 0; i < len; i++){
AV* const pair = (AV*)AvARRAY(triggers_queue)[i];
SV* const trigger = AvARRAY(pair)[0];