Ignore all .git.*
[gitmo/Class-MOP.git] / xs / MOP.xs
CommitLineData
d846ade3 1#include "mop.h"
2
7ec7b950 3SV *mop_method_metaclass;
4SV *mop_associated_metaclass;
5SV *mop_wrap;
6
d846ade3 7static bool
8find_method (const char *key, STRLEN keylen, SV *val, void *ud)
9{
10 bool *found_method = (bool *)ud;
11 *found_method = TRUE;
12 return FALSE;
13}
14
25bcd95c 15EXTERN_C XS(boot_Class__MOP__Package);
16EXTERN_C XS(boot_Class__MOP__Class);
17EXTERN_C XS(boot_Class__MOP__Attribute);
18EXTERN_C XS(boot_Class__MOP__Method);
19
d846ade3 20MODULE = Class::MOP PACKAGE = Class::MOP
21
22PROTOTYPES: DISABLE
23
24BOOT:
22932438 25 mop_prehash_keys();
d846ade3 26
e1f52a8a 27 mop_method_metaclass = newSVpvs("method_metaclass");
28 mop_wrap = newSVpvs("wrap");
29 mop_associated_metaclass = newSVpvs("associated_metaclass");
d846ade3 30
e3dcef7f 31 MOP_CALL_BOOT (boot_Class__MOP__Package);
32 MOP_CALL_BOOT (boot_Class__MOP__Class);
33 MOP_CALL_BOOT (boot_Class__MOP__Attribute);
34 MOP_CALL_BOOT (boot_Class__MOP__Method);
d846ade3 35
36# use prototype here to be compatible with get_code_info from Sub::Identify
37void
38get_code_info(coderef)
39 SV *coderef
40 PROTOTYPE: $
41 PREINIT:
42 char *pkg = NULL;
43 char *name = NULL;
44 PPCODE:
e1f52a8a 45 if (mop_get_code_info(coderef, &pkg, &name)) {
d846ade3 46 EXTEND(SP, 2);
47 PUSHs(newSVpv(pkg, 0));
48 PUSHs(newSVpv(name, 0));
49 }
50
51# This is some pretty grotty logic. It _should_ be parallel to the
52# pure Perl version in lib/Class/MOP.pm, so if you want to understand
53# it we suggest you start there.
54void
55is_class_loaded(klass=&PL_sv_undef)
56 SV *klass
57 PREINIT:
58 HV *stash;
59 bool found_method = FALSE;
60 PPCODE:
61 if (!SvPOK(klass) || !SvCUR(klass)) {
62 XSRETURN_NO;
63 }
64
65 stash = gv_stashsv(klass, 0);
66 if (!stash) {
67 XSRETURN_NO;
68 }
69
22932438 70 if (hv_exists_ent (stash, KEY_FOR(VERSION), HASH_FOR(VERSION))) {
71 HE *version = hv_fetch_ent(stash, KEY_FOR(VERSION), 0, HASH_FOR(VERSION));
d846ade3 72 SV *version_sv;
73 if (version && HeVAL(version) && (version_sv = GvSV(HeVAL(version)))) {
74 if (SvROK(version_sv)) {
75 SV *version_sv_ref = SvRV(version_sv);
76
77 if (SvOK(version_sv_ref)) {
78 XSRETURN_YES;
79 }
80 }
81 else if (SvOK(version_sv)) {
82 XSRETURN_YES;
83 }
84 }
85 }
86
22932438 87 if (hv_exists_ent (stash, KEY_FOR(ISA), HASH_FOR(ISA))) {
88 HE *isa = hv_fetch_ent(stash, KEY_FOR(ISA), 0, HASH_FOR(ISA));
d846ade3 89 if (isa && HeVAL(isa) && GvAV(HeVAL(isa))) {
90 XSRETURN_YES;
91 }
92 }
93
e1f52a8a 94 mop_get_package_symbols(stash, TYPE_FILTER_CODE, find_method, &found_method);
d846ade3 95 if (found_method) {
96 XSRETURN_YES;
97 }
98
99 XSRETURN_NO;