5 #define NEED_grok_number
6 #define NEED_grok_numeric_radix
7 #define NEED_newRV_noinc
8 #define NEED_newSVpvn_share
9 #define NEED_sv_2pv_flags
13 #define XSPROTO(name) void name(pTHX_ CV* cv)
17 #define gv_stashpvs(x, y) Perl_gv_stashpvn(aTHX_ STR_WITH_LEN(x), y)
21 * delegations and attribute helpers:
30 * I32 *type; // hash, array, whatever + vtable for operation
40 /* These two functions attach magic with no behavior to an SV.
42 * The stashed value is reference counted, and is destroyed when it's parent
43 * object is destroyed.
45 * This is used to keep a reference the the meta attribute from a generated
46 * method, and to cache the C struct based wrapper attached to the meta
50 STATIC MGVTBL null_mg_vtbl = {
64 #endif /* MGf_LOCAL */
67 STATIC MAGIC *stash_in_mg (pTHX_ SV *sv, SV *obj) {
68 MAGIC *mg = sv_magicext(sv, obj, PERL_MAGIC_ext, &null_mg_vtbl, NULL, 0 );
69 mg->mg_flags |= MGf_REFCOUNTED;
74 STATIC SV *get_stashed_in_mg(pTHX_ SV *sv) {
77 if (SvTYPE(sv) >= SVt_PVMG) {
78 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
79 if ((mg->mg_type == PERL_MAGIC_ext) && (mg->mg_virtual == &null_mg_vtbl))
97 /* The folloing data structures deal with type constraints */
99 /* this is an enum of the various kinds of constraint checking an attribute can
102 * tc_cv is the fallback behavior (simply applying the
103 * ->_compiled_type_constraint to the value, but other more optimal checks are
104 * implemented too. */
107 tc_none = 0, /* no type checking */
108 tc_type, /* a builtin type to be checked by check_sv_type */
109 tc_stash, /* a stash for a class, implements TypeConstraint::Class by comparing SvSTASH and then invoking C<isa> if necessary */
110 tc_cv, /* applies a code reference to the value and checks for truth */
111 tc_fptr, /* apply a C function pointer */
112 tc_enum /* TODO check that the value is in an allowed set of values (strings) */
115 /* this is a enum of builtin type check. They are handled in a switch statement
116 * in check_sv_type */
118 Any, /* or item, or bool */
124 GlobRef, /* SVt_PVGV */
125 ArrayRef, /* SVt_PVAV */
126 HashRef, /* SVt_PVHV */
127 CodeRef, /* SVt_PVCV */
130 FileHandle, /* TODO */
137 /* auxillary pointer/int union used for constraint checking */
139 TC type; /* the builtin type number for tc_type */
140 SV *sv; /* the cv for tc_cv, or the stash for tc_stash */
141 OP *op; /* TODO not used */
142 bool (*fptr)(pTHX_ SV *type_constraint, SV *sv); /* the function pointer for tc_fptr FIXME aux data? */
150 /* The folloing data structures deal with type default value generation */
152 /* This is an enum for the various types of default value behaviors an
153 * attribute can have */
156 default_none = 0, /* no default value */
157 default_normal, /* code reference or scalar */
158 default_builder, /* builder method */
159 default_type /* TODO enumerated type optimization (will call newHV, newAV etc to avoid calling a code ref for these simple cases) */
163 SV *sv; /* The default value, or a code ref to generate one. If builder then this sv is applied as a method (stringified) */
164 U32 type; /* TODO for default_type, should probably be one of SVt_PVAV/SVt_PVHV */
172 /* the ATTR struct contains all the meta data for a Moose::Meta::Attribute for
173 * a given meta instance
175 * flags determines the various behaviors
177 * This supports only one slot per attribute in the current implementation, but
178 * slot_sv could contain an array
180 * A list of XSUBs that rely on this attr struct are cross indexed in the cvs
181 * array, so that when the meta instance is destroyed the XSANY field will be
182 * cleared. This is done in delete_mi
186 /* pointer to the MI this attribute is a part of the meta instance struct */
189 U32 flags; /* slot type, TC behavior, coerce, weaken, (no default | default, builder + lazy), auto_deref */
191 /* slot access fields */
192 SV *slot_sv; /* value of the slot (currently always slot name) */
193 U32 slot_u32; /* for optimized access (precomputed hash, possibly something else) */
198 DEFAULT def; /* cv, value or other, depending on flags */
200 TC_CHECK tc_check; /* see TC_CHECK*/
201 SV *type_constraint; /* Moose::Meta::TypeConstraint object */
203 CV *initializer; /* TODO */
204 CV *trigger; /* TODO */
206 SV *meta_attr; /* the Moose::Meta::Attribute */
207 AV *cvs; /* an array of CVs which use this attr, see delete_mi */
210 /* the flags integer is mapped as follows
211 * instance misc reading writing
212 * 00000000 00000000 00000000 00000000
216 * ^ tc.sv is refcounted
223 * ^ def.sv is refcounted
226 * ^ attr is required TODO
228 * flags having to do with the instance layout (TODO, only hash supported for now)
229 * ^^^^^^^ if 0 then nothing special (just hash)? FIXME TBD
232 #define ATTR_INSTANCE_MASK 0xff000000
233 #define ATTR_READING_MASK 0x0000ff00
234 #define ATTR_WRITING_MASK 0x000000ff
236 #define ATTR_MASK_TYPE 0x7
238 #define ATTR_MASK_DEFAULT 0x700
239 #define ATTR_SHIFT_DEFAULT 8
241 #define ATTR_LAZY 0x800
242 #define ATTR_DEFREFCNT 0x1000
244 #define ATTR_COERCE 0x8
245 #define ATTR_TCREFCNT 0x10
246 #define ATTR_WEAK 0x20
247 #define ATTR_TRIGGER 0x40
249 #define ATTR_ISWEAK(attr) ( attr->flags & ATTR_WEAK )
250 #define ATTR_ISLAZY(attr) ( attr->flags & ATTR_LAZY )
251 #define ATTR_ISCOERCE(attr) ( attr->flags & ATTR_COERCE )
253 #define ATTR_TYPE(f) ( attr->flags & 0x7 )
254 #define ATTR_DEFAULT(f) ( ( attr->flags & ATTR_MASK_DEFAULT ) >> ATTR_SHIFT_DEFAULT )
256 #define ATTR_DUMB_READER(attr) !ATTR_IS_LAZY(attr)
257 #define ATTR_DUMB_WRITER(attr) ( ( attr->flags & ATTR_WRITING_MASK ) == 0 )
258 #define ATTR_DUMB_INSTANCE(attr) ( ( attr->flags & ATTR_INSTANCE_MASK ) == 0 )
262 /* This unused (TODO) vtable will implement the meta instance protocol in terms
263 * of function pointers to allow the XS accessors to be used with custom meta
264 * instances in the future.
266 * We'll need to define a default instance of this vtable that uses call_sv,
269 /* FIXME define a vtable that does call_sv for fallback meta instance protocol */
271 SV * (*get)(pTHX_ SV *self, ATTR *attr);
272 void (*set)(pTHX_ SV *self, ATTR *attr, SV *value);
273 bool * (*has)(pTHX_ SV *self, ATTR *attr);
274 SV * (*delete)(pTHX_ SV *self, ATTR *attr);
277 /* TODO this table describes the instance layout of the object. Not yet
282 /* these are not yet implemented */
290 /* this struct models the meta instance *and* meta attributes simultaneously.
291 * It is a cache of the meta attribute behaviors for a given class or subclass
292 * and can be parametrized on that level
295 * An object pointing to this structure is kept in a refcounted magic inside
296 * the meta instance it corresponds to. On C<invalidate_meta_instance> the meta
297 * instance is destroyed, causing the proxy object to be destroyed, deleting
298 * this structure, clearing the XSANY of all dependent attribute methods.
300 * The next invocation of an attribute method will eventually call get_attr,
301 * which will call C<get_meta_instance> on the metaclass (recreating it in the
302 * Class::MOP level), and cache a new MI struct inside it. Subsequent
303 * invocations of get_attr will then search the MI for an ATTR matching the
304 * meta_attribute of the attribute method */
308 /* slot access method */
309 instance_types type; /* TODO only hashes supported currently */
310 instance_vtbl *vtbl; /* TODO */
312 /* attr descriptors */
324 /* these functions implement type constraint checking */
326 /* checks that the SV is a scalar ref */
327 STATIC bool check_is_scalar_ref(SV *sv) {
329 switch (SvTYPE(SvRV(sv))) {
343 /* checks that the SV is a ref to a certain SvTYPE, where type is in the table
345 STATIC bool check_reftype(TC type, SV *sv) {
365 croak("not a reftype %d\n", type);
368 return SvTYPE(SvRV(sv)) == svt;
371 /* checks whether an SV is of a certain class
372 * SvSTASH is first compared by pointer for efficiency */
373 STATIC bool check_sv_class(pTHX_ HV *stash, SV *sv) {
386 if (SvSTASH(rv) == stash)
393 XPUSHs(sv_2mortal(newSVpv(HvNAME_get(stash), 0)));
396 call_method("isa", G_SCALAR);
407 /* checks whether SV of of a known simple type. Most of the non parametrized
408 * Moose core types are implemented here */
409 STATIC bool check_sv_type (TC type, SV *sv) {
426 return (SvOK(sv) && !SvROK(sv));
428 #if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION <5)
429 if (!SvPOK(sv) && !SvPOKp(sv))
430 return SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
433 return looks_like_number(sv);
438 } else if ( SvPOK(sv) ) {
440 char *pv = SvPV(sv, len);
441 int flags = grok_number(pv, len, NULL);
442 return ( flags && !(flags & IS_NUMBER_NOT_INT) );
450 return check_is_scalar_ref(sv);
456 return check_reftype(type, sv);
460 /* not using sv_isobject to avoid repeated get magic */
463 if ( SvOBJECT(rv) ) {
464 char *name = HvNAME_get(SvSTASH(SvRV(sv)));
465 bool is_regexp = strEQ("Regexp", name);
466 return ( (type == RegexpRef) ^ !is_regexp );
472 if ( SvOK(sv) && !SvROK(sv) ) {
476 return ( gv_stashpvn(pv, len, 0) != NULL );
490 /* invoke a CV on an SV and return SvTRUE of the result */
491 STATIC bool check_sv_cv (pTHX_ SV *cv, SV *sv) {
501 call_sv(cv, G_SCALAR);
513 /* checks the type constraint for an SV based on the type constraint kind */
514 STATIC bool check_type_constraint(pTHX_ tc_kind kind, TC_CHECK tc_check, SV *type_constraint, SV *sv) {
520 return check_sv_type(tc_check.type, sv);
523 return check_sv_class(aTHX_ (HV *)tc_check.sv, sv);
526 return tc_check.fptr(aTHX_ type_constraint, sv);
529 return check_sv_cv(aTHX_ tc_check.sv, sv);
541 /* end of type constraint checking functions */
551 /* Initialize the ATTR structure using positional arguments from Perl space. */
553 STATIC void init_attr (MI *mi, ATTR *attr, AV *desc) {
555 U32 slot_hash, init_arg_hash;
556 STRLEN slot_len, init_arg_len;
557 char *slot_pv, *init_arg_pv;
558 I32 ix = av_len(desc);
559 SV **params = AvARRAY(desc);
567 croak("wrong number of args (%d != 14)", (int)ix + 1);
569 for ( ; ix >= 0; ix-- ) {
570 if ( !params[ix] || params[ix] == &PL_sv_undef )
576 /* handle attribute slot array */
578 if ( !SvROK(params[1]) || SvTYPE(SvRV(params[1])) != SVt_PVAV )
579 croak("slots is not an array");
581 if ( av_len((AV *)SvRV(params[1])) != 0 )
582 croak("Only unary slots are supported at the moment");
584 /* calculate a hash from the slot */
585 /* FIXME arrays etc should also be supported */
586 slot_sv = *av_fetch((AV *)SvRV(params[1]), 0, 0);
587 slot_pv = SvPV(slot_sv, slot_len);
588 PERL_HASH(slot_hash, slot_pv, slot_len);
591 init_arg_sv = params[13];
592 init_arg_pv = SvPV(init_arg_sv, init_arg_len);
593 PERL_HASH(init_arg_hash, init_arg_pv, init_arg_len);
596 /* FIXME better organize these, positionals suck */
597 if ( SvTRUE(params[2]) )
600 if ( SvTRUE(params[3]) )
601 flags |= ATTR_COERCE;
603 if ( SvTRUE(params[4]) )
608 /* type constraint data */
613 int tc_kind = SvIV(params[6]);
614 SV *data = params[7];
618 attr->tc_check.type = SvIV(data);
621 flags |= ATTR_TCREFCNT;
622 attr->tc_check.sv = (SV *)gv_stashsv(data, 0);
625 flags |= ATTR_TCREFCNT;
626 attr->tc_check.sv = SvRV(data);
627 if ( SvTYPE(attr->tc_check.sv) != SVt_PVCV )
628 croak("compiled type constraint is not a coderef");
639 /* default/builder data */
641 if ( SvTRUE(params[10]) ) { /* has default */
645 attr->def.sv = SvRV(sv);
646 if ( SvTYPE(attr->def.sv) != SVt_PVCV )
647 croak("compiled type constraint is not a coderef");
649 attr->def.sv = newSVsv(sv);
650 sv_2mortal(attr->def.sv); /* in case of error soon, we refcnt inc it later after we're done checking params */
653 flags |= ( ATTR_DEFREFCNT | ( default_normal << ATTR_SHIFT_DEFAULT ) );
654 } else if ( SvOK(params[12]) ) { /* builder */
655 attr->def.sv = newSVsv(params[12]);
656 flags |= ( ATTR_DEFREFCNT | ( default_builder << ATTR_SHIFT_DEFAULT ) );
661 attr->trigger = SvROK(params[6]) ? (CV *)SvRV(params[6]) : NULL;
662 if ( attr->trigger && SvTYPE(attr->trigger) != SVt_PVCV )
663 croak("trigger is not a coderef");
665 attr->initializer = SvROK(params[7]) ? (CV *)SvRV(params[7]) : NULL;
666 if ( attr->initializer && SvTYPE(attr->initializer) != SVt_PVCV )
667 croak("initializer is not a coderef");
671 /* now that we're done preparing/checking args and shit, so we finalize the
672 * attr, increasing refcounts for any referenced data, and creating the CV
677 /* copy the outer ref SV */
678 attr->meta_attr = newSVsv(params[0]);
679 attr->type_constraint = newSVsv(tc);
681 /* increase the refcount for auxillary structures */
682 SvREFCNT_inc(attr->trigger);
683 SvREFCNT_inc(attr->initializer);
684 if ( flags & ATTR_TCREFCNT ) SvREFCNT_inc(attr->tc_check.sv);
685 if ( flags & ATTR_DEFREFCNT ) SvREFCNT_inc(attr->def.sv);
687 attr->slot_sv = newSVpvn_share(slot_pv, slot_len, slot_hash);
688 attr->slot_u32 = slot_hash;
690 attr->init_arg_sv = newSVpvn_share(init_arg_pv, init_arg_len, init_arg_hash);
691 attr->init_arg_u32 = init_arg_hash;
693 /* cross refs to CVs which use this struct */
697 STATIC SV *new_mi (pTHX_ HV *stash, AV *attrs) {
698 HV *mi_stash = gv_stashpvs("Moose::XS::Meta::Instance",0);
699 SV *sv_ptr = newSViv(0);
700 SV *obj = sv_2mortal(sv_bless(newRV_noinc(sv_ptr), mi_stash));
702 const I32 num_attrs = av_len(attrs) + 1;
706 /* set the pointer now, if we have any initialization errors it'll get
707 * cleaned up because obj is mortal */
708 sv_setiv(sv_ptr, PTR2IV(mi));
710 Newxz(mi->attrs, num_attrs, ATTR);
712 SvREFCNT_inc_simple(stash);
715 mi->type = 0; /* nothing else implemented yet */
717 /* initialize attributes */
718 for ( ; mi->num_attrs < num_attrs; mi->num_attrs++ ) {
719 SV **desc = av_fetch(attrs, mi->num_attrs, 0);
721 if ( !desc || !*desc || !SvROK(*desc) || !(SvTYPE(SvRV(*desc)) == SVt_PVAV) ) {
722 croak("Attribute descriptor has to be a hash reference");
725 init_attr(mi, &mi->attrs[mi->num_attrs], (AV *)SvRV(*desc));
731 STATIC void delete_attr (pTHX_ ATTR *attr) {
733 SV **cvs = AvARRAY(attr->cvs);
735 /* remove the pointers to this ATTR struct from all the the dependent CVs */
736 for ( i = av_len(attr->cvs); i >= 0; i-- ) {
737 CV *cv = (CV *)cvs[i];
741 SvREFCNT_dec(attr->cvs);
742 SvREFCNT_dec(attr->slot_sv);
743 SvREFCNT_dec(attr->type_constraint);
744 if ( attr->flags & ATTR_TCREFCNT ) SvREFCNT_dec(attr->tc_check.sv);
745 if ( attr->flags & ATTR_DEFREFCNT ) SvREFCNT_dec(attr->def.sv);
746 SvREFCNT_dec(attr->initializer);
747 SvREFCNT_dec(attr->trigger);
748 SvREFCNT_dec(attr->meta_attr);
751 STATIC void delete_mi (pTHX_ MI *mi) {
752 SvREFCNT_dec(mi->stash);
754 while ( mi->num_attrs--) {
755 ATTR *attr = &mi->attrs[mi->num_attrs];
756 delete_attr(aTHX_ attr);
759 if ( mi->attrs ) Safefree(mi->attrs);
766 /* these functions call Perl-space for MOP methods, helpers etc */
769 /* wow, so much code for the equivalent of
770 * $attr->associated_class->get_meta_instance */
771 STATIC SV *attr_to_meta_instance(pTHX_ SV *meta_attr) {
777 croak("No attr found in magic!");
786 count = call_pv("Moose::XS::attr_to_meta_instance", G_SCALAR);
789 croak("attr_to_meta_instance borked (%d args returned, expecting 1)", (int)count);
800 return sv_2mortal(mi);
803 /* gets a class and an array of attr parameters */
804 STATIC SV *perl_mi_to_c_mi(pTHX_ SV *perl_mi) {
819 count = call_pv("Moose::XS::meta_instance_to_attr_descs", G_ARRAY);
822 croak("meta_instance_to_attr_descs borked (%d args returned, expecting 2)", (int)count);
830 stash = gv_stashsv(class, 0);
832 mi = new_mi(aTHX_ stash, (AV *)SvRV(attrs));
838 return sv_2mortal(mi);
843 /* locate an ATTR for a MOP level attribute inside an MI */
844 STATIC ATTR *mi_find_attr(SV *mi_obj, SV *meta_attr) {
846 MI *mi = INT2PTR(MI *, SvIV(SvRV(mi_obj)));
848 for ( ix = 0; ix < mi->num_attrs; ix++ ) {
849 if ( SvRV(mi->attrs[ix].meta_attr) == SvRV(meta_attr) ) {
850 return &mi->attrs[ix];
854 croak("Attr %x not found in meta instance of %s", (unsigned int)PTR2UV(SvRV(meta_attr)) /* SvPV_force_nomg(sv_2mortal(newSVsv(meta_attr))) */, HvNAME_get(mi->stash) );
858 /* returns the ATTR for a CV:
860 * 1. get the Moose::Meta::Attribute using get_stashed_in_mg from the CV itself
861 * 2. get the meta instance by calling $attr->associated_class->get_meta_instance
862 * 3. get the MI by using get_stashed_in_mg from the meta instance, creating it if necessary
863 * 4. search for the appropriate ATTR in the MI using mi_find_attr
865 STATIC ATTR *get_attr(pTHX_ CV *cv) {
866 SV *meta_attr = get_stashed_in_mg(aTHX_ (SV *)cv);
867 SV *perl_mi = attr_to_meta_instance(aTHX_ meta_attr);
868 SV *mi_obj = get_stashed_in_mg(aTHX_ SvRV(perl_mi));
871 mi_obj = perl_mi_to_c_mi(aTHX_ perl_mi);
872 stash_in_mg(aTHX_ SvRV(perl_mi), mi_obj);
875 return mi_find_attr(mi_obj, meta_attr);
878 /* Cache a pointer to the appropriate ATTR in the XSANY of the CV, using
880 STATIC ATTR *define_attr (pTHX_ CV *cv) {
881 ATTR *attr = get_attr(aTHX_ cv);
884 XSANY.any_i32 = PTR2IV(attr);
887 av_push( attr->cvs, (SV *)cv );
898 STATIC void weaken(pTHX_ SV *sv) {
900 sv_rvweaken(sv); /* FIXME i think this might warn when weakening an already weak ref */
902 croak("weak references are not implemented in this release of perl");
911 /* meta instance protocol
913 * The slot functions don't change the refcount or copy (aliasing semantics)
915 * create_instance returns a new mortal */
917 STATIC SV *get_slot_lvalue(pTHX_ SV *self, ATTR *attr) {
922 assert(SvTYPE(SvRV(self)) == SVt_PVHV);
924 assert( ATTR_DUMB_INSTANCE(attr) );
926 if ((he = hv_fetch_ent((HV *)SvRV(self), attr->slot_sv, 0, attr->slot_u32)))
932 STATIC bool set_slot_value(pTHX_ SV *self, ATTR *attr, SV *value) {
937 assert(SvTYPE(SvRV(self)) == SVt_PVHV);
939 assert( ATTR_DUMB_INSTANCE(attr) );
941 he = hv_store_ent((HV*)SvRV(self), attr->slot_sv, value, attr->slot_u32);
946 STATIC bool has_slot_value(pTHX_ SV *self, ATTR *attr) {
949 assert(SvTYPE(SvRV(self)) == SVt_PVHV);
951 assert( ATTR_DUMB_INSTANCE(attr) );
953 return hv_exists_ent((HV *)SvRV(self), attr->slot_sv, attr->slot_u32);
956 STATIC SV *deinitialize_slot(pTHX_ SV *self, ATTR *attr) {
959 assert(SvTYPE(SvRV(self)) == SVt_PVHV);
961 assert( ATTR_DUMB_INSTANCE(attr) );
963 return hv_delete_ent((HV *)SvRV(self), attr->slot_sv, 0, attr->slot_u32);
966 STATIC SV *create_instance(pTHX_ MI *mi) {
967 return sv_bless(sv_2mortal(newRV_noinc((SV *)newHV())), mi->stash);
973 /* Shared functionality for readers/writers/accessors, this roughly corresponds
974 * to the methods of Moose::Meta::Attribute on the instance
975 * (get_value/set_value, default value handling, etc)
977 * These functions return mortal copiess and save copies (handling refcounting). */
979 STATIC void attr_set_value(pTHX_ SV *self, ATTR *attr, SV *value);
981 STATIC SV *call_builder (pTHX_ SV *self, ATTR *attr) {
991 /* we invoke the builder as a stringified method. This will not work for
992 * $obj->$coderef etc, for that we need to use 'default' */
994 call_method(SvPV_nolen(attr->def.sv), G_SCALAR);
997 /* the value is a mortal with a refcount of 1, so we need to keep it around */
1005 return sv_2mortal(sv);
1009 STATIC SV *get_default(pTHX_ SV *self, ATTR *attr) {
1010 switch ( ATTR_DEFAULT(attr) ) {
1014 case default_builder:
1015 return call_builder(aTHX_ self, attr);
1017 case default_normal:
1018 if ( SvROK(attr->def.sv) ) {
1019 printf("CV default\n");
1022 printf("simple value\n");
1023 return sv_mortalcopy(attr->def.sv); /* will be copied by set for lazy, and by reader for both cases */
1034 /* $attr->get_value($self), will vivify lazy values if needed
1035 * returns an alias to the sv that is copied in the reader/writer/accessor code
1037 STATIC SV *attr_get_value(pTHX_ SV *self, ATTR *attr) {
1038 SV *value = get_slot_lvalue(aTHX_ self, attr);
1041 return sv_mortalcopy(value);
1042 } else if ( ATTR_ISLAZY(attr) ) {
1043 value = get_default(aTHX_ self, attr);
1044 attr_set_value(aTHX_ self, attr, value);
1051 /* $attr->set_value($self) */
1052 STATIC void attr_set_value(pTHX_ SV *self, ATTR *attr, SV *value) {
1056 /* FIXME croak if required ? */
1060 if ( ATTR_TYPE(attr) ) {
1061 if ( !check_type_constraint(aTHX_ ATTR_TYPE(attr), attr->tc_check, attr->type_constraint, value) )
1065 copy = newSVsv(value);
1067 if ( ATTR_ISWEAK(attr) && SvROK(copy) )
1070 if ( !set_slot_value(aTHX_ self, attr, copy) ) {
1072 croak("Hash store failed.");
1082 /* Perl-space level functionality
1084 * These subs are installed by new_sub's various aliases as the bodies of the
1090 /* This macro is used in the XS subs to set up the 'attr' variable.
1092 * if XSANY is NULL then define_attr is called on the CV, to set the pointer
1093 * to the ATTR struct.
1095 #define dATTR ATTR *attr = (XSANY.any_i32 ? INT2PTR(ATTR *, (XSANY.any_i32)) : define_attr(aTHX_ cv))
1109 Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "self");
1113 value = attr_get_value(aTHX_ ST(0), attr);
1133 Perl_croak(aTHX_ "Usage: %s(%s, %s)", GvNAME(CvGV(cv)), "self", "value");
1137 attr_set_value(aTHX_ ST(0), attr, ST(1));
1139 ST(0) = ST(1); /* return value */
1143 STATIC XS(accessor);
1153 Perl_croak(aTHX_ "Usage: %s(%s, [ %s ])", GvNAME(CvGV(cv)), "self", "value");
1158 attr_set_value(aTHX_ ST(0), attr, ST(1));
1159 ST(0) = ST(1); /* return value */
1161 SV *value = attr_get_value(aTHX_ ST(0), attr);
1172 STATIC XS(predicate);
1173 STATIC XS(predicate)
1182 Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "self");
1186 if ( has_slot_value(aTHX_ ST(0), attr) )
1200 STATIC XSPROTO ((*xs_bodies[])) = {
1207 MODULE = Moose PACKAGE = Moose::XS
1217 new_reader = xs_body_reader
1218 new_writer = xs_body_writer
1219 new_accessor = xs_body_accessor
1220 new_predicate = xs_body_predicate
1224 if ( ix >= max_xs_body )
1225 croak("Unknown Moose::XS body type");
1227 if ( !sv_isobject(attr) )
1228 croak("'attr' must be a Moose::Meta::Attribute");
1230 cv = newXS(SvOK(name) ? SvPV_nolen(name) : NULL, xs_bodies[ix], __FILE__);
1235 /* associate CV with meta attr */
1236 stash_in_mg(aTHX_ (SV *)cv, attr);
1238 /* this will be set on first call */
1246 MODULE = Moose PACKAGE = Moose::XS::Meta::Instance
1254 MI *mi = INT2PTR(MI *, SvIV(SvRV(self)));
1257 delete_mi(aTHX_ mi);
1260 MODULE = Moose PACKAGE = Moose::XS::TypeConstraints
1282 ScalarRef = ScalarRef
1283 FileHandle = FileHandle
1284 RegexpRef = RegexpRef
1287 ClassName = ClassName
1289 RETVAL = check_sv_type(ix, sv);
1294 ObjectOfType(sv, class)
1299 HV *stash = gv_stashsv(class, 0);
1301 RETVAL = check_sv_class(aTHX_ stash, sv);