TC_CHECK tc_check; /* see TC_CHECK*/
SV *type_constraint; /* Moose::Meta::TypeConstraint object */
- CV *initializer; /* TODO */
- CV *trigger; /* TODO */
+ CV *trigger;
+ CV *initializer;
+ CV *writer; /* used by the initializer */
SV *meta_attr; /* the Moose::Meta::Attribute */
AV *cvs; /* an array of CVs which use this attr, see delete_mi */
if ( attr->initializer && SvTYPE(attr->initializer) != SVt_PVCV )
croak("initializer is not a coderef");
-
-
/* now that we're done preparing/checking args and shit, so we finalize the
* attr, increasing refcounts for any referenced data, and creating the CV
* array */
mi->type = 0; /* nothing else implemented yet */
/* initialize attributes */
- for ( ; mi->num_attrs < num_attrs; mi->num_attrs++ ) {
+ for ( mi->num_attrs = 0; mi->num_attrs < num_attrs; mi->num_attrs++ ) {
SV **desc = av_fetch(attrs, mi->num_attrs, 0);
if ( !desc || !*desc || !SvROK(*desc) || !(SvTYPE(SvRV(*desc)) == SVt_PVAV) ) {
SvREFCNT_dec(attr->type_constraint);
if ( attr->flags & ATTR_TCREFCNT ) SvREFCNT_dec(attr->tc_check.sv);
if ( attr->flags & ATTR_DEFREFCNT ) SvREFCNT_dec(attr->def.sv);
- SvREFCNT_dec(attr->initializer);
SvREFCNT_dec(attr->trigger);
+ SvREFCNT_dec(attr->initializer);
+ SvREFCNT_dec(attr->writer);
SvREFCNT_dec(attr->meta_attr);
}
+/* generate a new attribute method */
+STATIC CV *new_attr_method (pTHX_ SV *attr, XSPROTO(body), char *name) {
+ CV *cv = newXS(name, body, __FILE__);
+
+ if (cv == NULL)
+ croak("Oi vey!");
+
+ /* associate CV with meta attr */
+ stash_in_mg(aTHX_ (SV *)cv, attr);
+
+ /* this will be set on first call */
+ XSANY.any_i32 = 0;
+
+ return cv;
+}
+
+
+
+
/* This macro is used in the XS subs to set up the 'attr' variable.
*
* if XSANY is NULL then define_attr is called on the CV, to set the pointer
XSRETURN_NO;
}
+
+
+
+
+
+
enum xs_body {
xs_body_reader = 0,
xs_body_writer,
PROTOTYPES: ENABLE
CV *
-new_sub(attr, name)
+new_attr_method(attr, name)
INPUT:
SV *attr;
SV *name;
PROTOTYPE: $;$
+ PREINIT:
+ char *pv = SvOK(name) ? SvPV_nolen(name) : NULL;
ALIAS:
new_reader = xs_body_reader
new_writer = xs_body_writer
new_accessor = xs_body_accessor
new_predicate = xs_body_predicate
- PREINIT:
- CV * cv;
CODE:
if ( ix >= max_xs_body )
croak("Unknown Moose::XS body type");
if ( !sv_isobject(attr) )
croak("'attr' must be a Moose::Meta::Attribute");
- cv = newXS(SvOK(name) ? SvPV_nolen(name) : NULL, xs_bodies[ix], __FILE__);
-
- if (cv == NULL)
- croak("Oi vey!");
-
- /* associate CV with meta attr */
- stash_in_mg(aTHX_ (SV *)cv, attr);
-
- /* this will be set on first call */
- XSANY.any_i32 = 0;
-
- RETVAL = cv;
+ RETVAL = new_attr_method(aTHX_ attr, xs_bodies[ix], pv);
OUTPUT:
RETVAL