Define.xs

filter: Statementstmt 87.1% 34 / 39 Branchbran 57.6% 15 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.3% 49 / 65 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/MRO/Define.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #ifndef UTF8f
6 # define UTF8f SVf
7 # define UTF8fARG(u,l,p) newSVpvn_flags (p, l, SVs_TEMP | (u ? SVf_UTF8 : 0)
8 #endif
9  
10 #ifndef cBOOL
11 # define cBOOL(cbool) ((cbool) ? (bool)1 : (bool)0)
12 #endif
13  
14 static HV *mros;
15  
16 static AV *
17 4 resolve (pTHX_ HV *stash, U32 level)
18 {
19 4 dSP;
20 I32 count;
21 SV *tmp, **callback;
22 AV *ret;
23 STRLEN namelen;
24 struct mro_meta *meta;
25 const struct mro_alg *alg;
26  
27 4 ▶ meta = HvMROMETA (stash);
Branch: 1 branch
BranchTrueFalseTotal
meta = HvMROMETA (stash); 4 0 4
28 4 alg = meta->mro_which;
29  
30 4 ▶ namelen = alg->kflags & HVhek_UTF8 ? -alg->length : alg->length;
Branch: 1 branch
BranchTrueFalseTotal
namelen = alg->kflags & HVhek_UTF8 ? -alg->length : alg->length; 2 2 4
31 4 ▶ if (!(callback = hv_fetch (mros, alg->name, namelen, 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(callback = hv_fetch (mros, alg->name, namelen, 0))) { 0 4 4
32 0 croak ("failed to find callback for mro %"UTF8f,
33 cBOOL (alg->kflags & HVhek_UTF8), alg->length, alg->name);
34 }
35  
36 4 ENTER;
37 4 SAVETMPS;
38  
39 4 ▶ PUSHMARK (SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (SP); 0 4 4
40 4 ▶ EXTEND (SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND (SP, 2); 0 4 4
41 4 mPUSHs (newRV_inc ((SV *)stash));
42 4 mPUSHu (level);
43 4 PUTBACK;
44  
45 4 count = call_sv (*callback, G_SCALAR);
46  
47 4 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 4 4
48 0 croak ("mro resolver didn't return exactly one value");
49 }
50  
51 4 SPAGAIN;
52 4 tmp = POPs;
53  
54 4 ▶ if (!SvROK (tmp) || (SvTYPE (SvRV (tmp)) != SVt_PVAV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK (tmp) || (SvTYPE (SvRV (tmp)) != SVt_PVAV)) { 4 0 4
if (!SvROK (tmp) || (SvTYPE (SvRV (tmp)) != SVt_PVAV)) { 0 4 4
55 0 croak ("mro resolver didn't return an array reference");
56 }
57  
58 4 ret = (AV *)SvRV (tmp);
59 4 SvREFCNT_inc (ret);
60  
61 4 PUTBACK;
62 4 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 4 0 4
63 4 LEAVE;
64  
65 4 return ret;
66 }
67  
68 MODULE = MRO::Define PACKAGE = MRO::Define
69  
70 PROTOTYPES: DISABLE
71  
72 void
73 register_mro (name, resolve_cb, kflags=0)
74 SV *name
75 SV *resolve_cb
76 U16 kflags
77 PREINIT:
78 struct mro_alg *mro;
79 const char *name_pv;
80 STRLEN name_len;
81 INIT:
82 2 ▶ if (!SvROK (resolve_cb) || (SvTYPE (SvRV (resolve_cb)) != SVt_PVCV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK (resolve_cb) || (SvTYPE (SvRV (resolve_cb)) != SVt_PVCV)) { 2 0 2
if (!SvROK (resolve_cb) || (SvTYPE (SvRV (resolve_cb)) != SVt_PVCV)) { 0 2 2
83 0 croak ("resolve_cb is not a code reference");
84 }
85  
86 2 name_pv = SvPV (name, name_len);
87  
88 2 Newxz (mro, 1, struct mro_alg);
89 2 mro->name = strdup (name_pv);
90 2 mro->length = name_len;
91 2 mro->kflags = kflags | (SvUTF8(name) ? HVhek_UTF8 : 0);
92 2 mro->resolve = resolve;
93 CODE:
94 2 ▶ if (!hv_store (mros, name_pv, SvUTF8(name) ? -(I32)name_len : (I32)name_len,
Branch: 2 branches
BranchTrueFalseTotal
if (!hv_store (mros, name_pv, SvUTF8(name) ? -(I32)name_len : (I32)name_len, 1 1 2
if (!hv_store (mros, name_pv, SvUTF8(name) ? -(I32)name_len : (I32)name_len, 0 2 2
95 newSVsv (resolve_cb), 0)) {
96 0 croak ("failed to store hash value");
97 }
98 2 Perl_mro_register (aTHX_ mro);
99  
100 BOOT:
101 3 mros = newHV ();
↑ Summary blib/lib/MRO/Define.pm »