| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| |
| 7 |
|
| /* This code was originally written by Goro Fuji for Class::MOP, and later |
| 8 |
|
| refined by Florian Ragwitz. */ |
| 9 |
|
| |
| 10 |
|
| static bool |
| 11 |
10 |
| check_version (pTHX_ SV *klass, SV *required_version) { |
| 12 |
10 |
| bool ret = 0; |
| 13 |
|
| |
| 14 |
10 |
| dSP; |
| 15 |
10 |
| ENTER; |
| 16 |
10 |
| SAVETMPS; |
| 17 |
10 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
10 |
10 |
|
| 18 |
10 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
10 |
10 |
|
| 19 |
10 |
| PUSHs(klass); |
| 20 |
10 |
| PUSHs(required_version); |
| 21 |
10 |
| PUTBACK; |
| 22 |
|
| |
| 23 |
10 |
| call_method("VERSION", G_DISCARD|G_VOID|G_EVAL); |
| 24 |
|
| |
| 25 |
10 |
| SPAGAIN; |
| 26 |
|
| |
| 27 |
10 |
▶ | if (!SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV)) { |
10 |
0 |
10 |
| if (!SvTRUE(ERRSV)) { |
2 |
8 |
10 |
|
| 28 |
2 |
| ret = 1; |
| 29 |
|
| } |
| 30 |
|
| |
| 31 |
10 |
| PUTBACK; |
| 32 |
10 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
10 |
0 |
10 |
|
| 33 |
10 |
| LEAVE; |
| 34 |
|
| |
| 35 |
10 |
| return ret; |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
|
| static bool |
| 39 |
35 |
| has_a_sub (pTHX_ HV *stash) { |
| 40 |
|
| HE *he; |
| 41 |
|
| |
| 42 |
35 |
| (void)hv_iterinit(stash); |
| 43 |
|
| |
| 44 |
57 |
▶ | while ( (he = hv_iternext(stash)) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ( (he = hv_iternext(stash)) ) { |
45 |
12 |
57 |
|
| 45 |
45 |
| GV * const gv = (GV*)HeVAL(he); |
| 46 |
|
| STRLEN keylen; |
| 47 |
45 |
▶ | const char * const key = HePV(he, keylen); |
Branch: 1 branch
| Branch | True | False | Total |
| const char * const key = HePV(he, keylen); |
0 |
45 |
45 |
|
| 48 |
45 |
| SV *sv = NULL; |
| 49 |
|
| |
| 50 |
45 |
▶ | if(isGV(gv)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(isGV(gv)){ |
45 |
0 |
45 |
|
| 51 |
45 |
▶ | sv = (SV *)GvCVu(gv); |
Branch: 1 branch
| Branch | True | False | Total |
| sv = (SV *)GvCVu(gv); |
43 |
2 |
45 |
|
| 52 |
|
| } |
| 53 |
|
| /* expand the gv into a real typeglob if it contains stub functions or |
| 54 |
|
| constants. */ |
| 55 |
|
| else { |
| 56 |
0 |
| gv_init(gv, stash, key, keylen, GV_ADDMULTI); |
| 57 |
0 |
| sv = (SV *)GvCV(gv); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
45 |
▶ | if (sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv) { |
23 |
22 |
45 |
|
| 61 |
23 |
| return TRUE; |
| 62 |
|
| } |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
12 |
| return FALSE; |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
|
| static SV* KEY_FOR__version; |
| 69 |
|
| static SV* KEY_FOR_VERSION; |
| 70 |
|
| static SV* KEY_FOR_ISA; |
| 71 |
|
| |
| 72 |
|
| static U32 HASH_FOR__version; |
| 73 |
|
| static U32 HASH_FOR_VERSION; |
| 74 |
|
| static U32 HASH_FOR_ISA; |
| 75 |
|
| |
| 76 |
|
| void |
| 77 |
13 |
| prehash_keys (pTHX) { |
| 78 |
13 |
| KEY_FOR__version = newSVpv("-version", 8); |
| 79 |
13 |
| KEY_FOR_VERSION = newSVpv("VERSION", 7); |
| 80 |
13 |
| KEY_FOR_ISA = newSVpv("ISA", 3); |
| 81 |
|
| |
| 82 |
13 |
| PERL_HASH(HASH_FOR__version, "-version", 8); |
| 83 |
13 |
| PERL_HASH(HASH_FOR_VERSION, "VERSION", 7); |
| 84 |
13 |
| PERL_HASH(HASH_FOR_ISA, "ISA", 3); |
| 85 |
13 |
| } |
| 86 |
|
| |
| 87 |
|
| MODULE = Class::Load::XS PACKAGE = Class::Load::XS |
| 88 |
|
| |
| 89 |
|
| PROTOTYPES: DISABLE |
| 90 |
|
| |
| 91 |
|
| BOOT: |
| 92 |
13 |
| prehash_keys(aTHX); |
| 93 |
|
| |
| 94 |
|
| void |
| 95 |
|
| is_class_loaded(klass, options=NULL) |
| 96 |
|
| SV *klass |
| 97 |
|
| HV *options |
| 98 |
|
| PREINIT: |
| 99 |
|
| HV *stash; |
| 100 |
128 |
▶ | bool found_method = FALSE; |
Branch: 1 branch
| Branch | True | False | Total |
| bool found_method = FALSE; |
115 |
13 |
128 |
|
| 101 |
|
| PPCODE: |
| 102 |
128 |
| SvGETMAGIC(klass); |
| 103 |
128 |
▶ | if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
128 |
0 |
128 |
| if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
0 |
128 |
128 |
|
| 104 |
0 |
| XSRETURN_NO; |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
128 |
| stash = gv_stashsv(klass, 0); |
| 108 |
128 |
▶ | if (!stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) { |
63 |
65 |
128 |
|
| 109 |
63 |
| XSRETURN_NO; |
| 110 |
|
| } |
| 111 |
|
| |
| 112 |
65 |
▶ | if (options && hv_exists_ent(options, KEY_FOR__version, HASH_FOR__version)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (options && hv_exists_ent(options, KEY_FOR__version, HASH_FOR__version)) { |
10 |
55 |
65 |
| if (options && hv_exists_ent(options, KEY_FOR__version, HASH_FOR__version)) { |
10 |
0 |
10 |
|
| 113 |
10 |
| HE *required_version = hv_fetch_ent(options, KEY_FOR__version, 0, HASH_FOR__version); |
| 114 |
10 |
▶ | if (check_version (aTHX_ klass, HeVAL(required_version))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (check_version (aTHX_ klass, HeVAL(required_version))) { |
2 |
8 |
10 |
|
| 115 |
2 |
| XSRETURN_YES; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
8 |
| XSRETURN_NO; |
| 119 |
|
| } |
| 120 |
|
| |
| 121 |
55 |
▶ | if (hv_exists_ent (stash, KEY_FOR_VERSION, HASH_FOR_VERSION)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent (stash, KEY_FOR_VERSION, HASH_FOR_VERSION)) { |
19 |
36 |
55 |
|
| 122 |
19 |
| HE *version = hv_fetch_ent(stash, KEY_FOR_VERSION, 0, HASH_FOR_VERSION); |
| 123 |
19 |
▶ | if (version) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (version) { |
19 |
0 |
19 |
|
| 124 |
19 |
| SV *value = HeVAL(version); |
| 125 |
|
| SV *version_sv; |
| 126 |
19 |
▶ | if (value && isGV(value) && (version_sv = GvSV(value))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (value && isGV(value) && (version_sv = GvSV(value))) { |
19 |
0 |
19 |
| if (value && isGV(value) && (version_sv = GvSV(value))) { |
19 |
0 |
19 |
| if (value && isGV(value) && (version_sv = GvSV(value))) { |
18 |
1 |
19 |
|
| 127 |
18 |
▶ | if (SvROK(version_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(version_sv)) { |
1 |
17 |
18 |
|
| 128 |
|
| /* Any object is good enough, though this is most |
| 129 |
|
| likely going to be a version object */ |
| 130 |
1 |
▶ | if (sv_isobject(version_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_isobject(version_sv)) { |
1 |
0 |
1 |
|
| 131 |
1 |
| XSRETURN_YES; |
| 132 |
|
| } |
| 133 |
|
| else { |
| 134 |
0 |
| SV *version_sv_ref = SvRV(version_sv); |
| 135 |
|
| |
| 136 |
0 |
▶ | if (SvOK(version_sv_ref)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(version_sv_ref)) { |
0 |
0 |
0 |
|
| 137 |
0 |
| XSRETURN_YES; |
| 138 |
|
| } |
| 139 |
|
| } |
| 140 |
|
| } |
| 141 |
17 |
▶ | else if (SvOK(version_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvOK(version_sv)) { |
16 |
1 |
17 |
|
| 142 |
16 |
| XSRETURN_YES; |
| 143 |
|
| } |
| 144 |
|
| } |
| 145 |
|
| } |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
38 |
▶ | if (hv_exists_ent (stash, KEY_FOR_ISA, HASH_FOR_ISA)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent (stash, KEY_FOR_ISA, HASH_FOR_ISA)) { |
6 |
32 |
38 |
|
| 149 |
6 |
| HE *isa = hv_fetch_ent(stash, KEY_FOR_ISA, 0, HASH_FOR_ISA); |
| 150 |
6 |
▶ | if (isa) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isa) { |
6 |
0 |
6 |
|
| 151 |
6 |
| SV *value = HeVAL(isa); |
| 152 |
6 |
▶ | if (value && isGV(value) && GvAV(value) && av_len(GvAV(value)) != -1) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (value && isGV(value) && GvAV(value) && av_len(GvAV(value)) != -1) { |
6 |
0 |
6 |
| if (value && isGV(value) && GvAV(value) && av_len(GvAV(value)) != -1) { |
6 |
0 |
6 |
| if (value && isGV(value) && GvAV(value) && av_len(GvAV(value)) != -1) { |
6 |
0 |
6 |
| if (value && isGV(value) && GvAV(value) && av_len(GvAV(value)) != -1) { |
3 |
3 |
6 |
|
| 153 |
3 |
| XSRETURN_YES; |
| 154 |
|
| } |
| 155 |
|
| } |
| 156 |
|
| } |
| 157 |
|
| |
| 158 |
35 |
▶ | if (has_a_sub(aTHX_ stash)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (has_a_sub(aTHX_ stash)) { |
23 |
12 |
35 |
|
| 159 |
23 |
| XSRETURN_YES; |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
12 |
| XSRETURN_NO; |