Commit | Line | Data |
d846ade3 |
1 | #include "mop.h" |
2 | |
3 | static bool |
4 | find_method (const char *key, STRLEN keylen, SV *val, void *ud) |
5 | { |
6 | bool *found_method = (bool *)ud; |
2dba318b |
7 | PERL_UNUSED_ARG(key); |
8 | PERL_UNUSED_ARG(keylen); |
9 | PERL_UNUSED_ARG(val); |
d846ade3 |
10 | *found_method = TRUE; |
11 | return FALSE; |
12 | } |
13 | |
30bf0c82 |
14 | EXTERN_C XS(boot_Class__MOP__Mixin__HasMethods); |
25bcd95c |
15 | EXTERN_C XS(boot_Class__MOP__Package); |
2611f98e |
16 | EXTERN_C XS(boot_Class__MOP__Mixin__AttributeBase); |
25bcd95c |
17 | EXTERN_C XS(boot_Class__MOP__Method); |
18 | |
d846ade3 |
19 | MODULE = Class::MOP PACKAGE = Class::MOP |
20 | |
21 | PROTOTYPES: DISABLE |
22 | |
23 | BOOT: |
22932438 |
24 | mop_prehash_keys(); |
d846ade3 |
25 | |
30bf0c82 |
26 | MOP_CALL_BOOT (boot_Class__MOP__Mixin__HasMethods); |
e3dcef7f |
27 | MOP_CALL_BOOT (boot_Class__MOP__Package); |
2611f98e |
28 | MOP_CALL_BOOT (boot_Class__MOP__Mixin__AttributeBase); |
e3dcef7f |
29 | MOP_CALL_BOOT (boot_Class__MOP__Method); |
d846ade3 |
30 | |
31 | # use prototype here to be compatible with get_code_info from Sub::Identify |
32 | void |
33 | get_code_info(coderef) |
34 | SV *coderef |
35 | PROTOTYPE: $ |
36 | PREINIT: |
37 | char *pkg = NULL; |
38 | char *name = NULL; |
39 | PPCODE: |
704f58f9 |
40 | SvGETMAGIC(coderef); |
e1f52a8a |
41 | if (mop_get_code_info(coderef, &pkg, &name)) { |
d846ade3 |
42 | EXTEND(SP, 2); |
efc98200 |
43 | mPUSHs(newSVpv(pkg, 0)); |
44 | mPUSHs(newSVpv(name, 0)); |
d846ade3 |
45 | } |
46 | |
d846ade3 |
47 | void |
bd0ad278 |
48 | is_class_loaded(klass) |
d846ade3 |
49 | SV *klass |
50 | PREINIT: |
51 | HV *stash; |
52 | bool found_method = FALSE; |
53 | PPCODE: |
704f58f9 |
54 | SvGETMAGIC(klass); |
55 | if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
d846ade3 |
56 | XSRETURN_NO; |
57 | } |
58 | |
59 | stash = gv_stashsv(klass, 0); |
60 | if (!stash) { |
61 | XSRETURN_NO; |
62 | } |
63 | |
22932438 |
64 | if (hv_exists_ent (stash, KEY_FOR(VERSION), HASH_FOR(VERSION))) { |
65 | HE *version = hv_fetch_ent(stash, KEY_FOR(VERSION), 0, HASH_FOR(VERSION)); |
d846ade3 |
66 | SV *version_sv; |
67 | if (version && HeVAL(version) && (version_sv = GvSV(HeVAL(version)))) { |
68 | if (SvROK(version_sv)) { |
69 | SV *version_sv_ref = SvRV(version_sv); |
70 | |
71 | if (SvOK(version_sv_ref)) { |
72 | XSRETURN_YES; |
73 | } |
74 | } |
75 | else if (SvOK(version_sv)) { |
76 | XSRETURN_YES; |
77 | } |
78 | } |
79 | } |
80 | |
22932438 |
81 | if (hv_exists_ent (stash, KEY_FOR(ISA), HASH_FOR(ISA))) { |
82 | HE *isa = hv_fetch_ent(stash, KEY_FOR(ISA), 0, HASH_FOR(ISA)); |
d9d8a21b |
83 | if (isa && HeVAL(isa) && GvAV(HeVAL(isa)) && av_len(GvAV(HeVAL(isa))) != -1) { |
d846ade3 |
84 | XSRETURN_YES; |
85 | } |
86 | } |
87 | |
e1f52a8a |
88 | mop_get_package_symbols(stash, TYPE_FILTER_CODE, find_method, &found_method); |
d846ade3 |
89 | if (found_method) { |
90 | XSRETURN_YES; |
91 | } |
92 | |
93 | XSRETURN_NO; |