Mouse

 view release on metacpan or  search on metacpan

xs-src/MouseAttribute.xs  view on Meta::CPAN

        clearer   = *hv_fetchs(args, "clearer",   TRUE);
        predicate = *hv_fetchs(args, "predicate", TRUE);

        if(SvPV_nolen_const(name)[0] == '_'){
            if(!sv_true(clearer)){
                sv_setpvf(clearer, "_clear%"SVf, name);
            }
            if(!sv_true(predicate)){
                sv_setpvf(predicate, "_has%"SVf, name);
            }
        }
        else{
            if(!sv_true(clearer)){
                sv_setpvf(clearer, "clear_%"SVf, name);
            }
            if(!sv_true(predicate)){
                sv_setpvf(predicate, "has_%"SVf, name);
            }
        }
    }

    svp = hv_fetchs(args, "auto_deref", FALSE);
    if(svp && sv_true(*svp)){
        SV* const meth = sv_2mortal(newSVpvs_share("is_a_type_of"));
        if(!tc){
            mouse_throw_error(klass, NULL,
                "You cannot auto-dereference without specifying a type "
                "constraint on attribute (%"SVf")", name);
        }

        if(!(sv_true(mcall1(tc, meth, newSVpvs_flags("ArrayRef", SVs_TEMP)))
            || sv_true(mcall1(tc, meth, newSVpvs_flags("HashRef", SVs_TEMP))) )){
            mouse_throw_error(klass, NULL,
                "You cannot auto-dereference anything other than a ArrayRef "
                "or HashRef on attribute (%"SVf")", name);
        }
    }

    svp = hv_fetchs(args, "trigger", FALSE);
    if(svp){
        if(!IsCodeRef(*svp)){
            mouse_throw_error(klass, NULL,
                "Trigger must be a CODE ref on attribute (%"SVf")",
                name);
        }
    }


    svp = hv_fetchs(args, "lazy", FALSE);
    if(svp && sv_true(*svp)){
        if(!(has_default || has_builder)){
            mouse_throw_error(klass, NULL,
                "You cannot have a lazy attribute (%"SVf") without specifying "
                "a default value for it", name);
        }
    }
}

void
default(SV* self, SV* instance = NULL)
PPCODE:
{
    SV* value = get_slot(self, sv_2mortal(newSVpvs_share("default")));
    if(! value) {
        value = &PL_sv_undef;
    }
    else if (instance != NULL && IsCodeRef(value)) {
        PUSHMARK(SP);
        XPUSHs(instance);
        PUTBACK;
        call_sv_safe(value, G_SCALAR);
        SPAGAIN;
        value = POPs;
        PUTBACK;
    }
    ST(0) = value;
    XSRETURN(1);
}



( run in 0.409 second using v1.01-cache-2.11-cpan-5511b514fd6 )