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