NoVivify.xs

filter: Statementstmt 96.1% 25 / 26 Branchbran 69.2% 18 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.6% 43 / 52 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Hash/NoVivify.pm »
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #ifdef __cplusplus
8 }
9 #endif
10  
11 MODULE = Hash::NoVivify PACKAGE = Hash::NoVivify
12  
13 PROTOTYPES: ENABLE
14  
15 void
16 Exists(href, ...)
17 SV* href
18  
19 CODE:
20 int i;
21 HV* h;
22 U32 hash;
23 SV* t;
24  
25 5 ▶ if (!SvOK(href) ||
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(href) || 5 0 5
26 5 ▶ !SvROK(href) ||
Branch: 1 branch
BranchTrueFalseTotal
!SvROK(href) || 3 2 5
27 3 ▶ (SvTYPE(t = SvRV(href)) != SVt_PVHV)) {
Branch: 1 branch
BranchTrueFalseTotal
(SvTYPE(t = SvRV(href)) != SVt_PVHV)) { 1 2 3
28 3 XSRETURN_NO;
29 }
30  
31 # /* The idea is easy. For each element of the array, */
32 6 ▶# /* if that element exists as a key of the hashref, */
Branch: 1 branch
BranchTrueFalseTotal
# /* if that element exists as a key of the hashref, */ 5 1 6
33 # /* set the hashref to that element. Otherwise, blow */
34 5 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
5 0 5
35 5 ▶# /* Note that at the top, href is an SV* of the hashref */
Branch: 1 branch
BranchTrueFalseTotal
# /* Note that at the top, href is an SV* of the hashref */ 5 0 5
36 10 for (i = 1; i < items; i++) {
37 5
38 4 if (SvOK(href) &&
39 SvROK(href) &&
40 1 SvPOK(ST(i)) &&
41 hv_exists_ent(h = (HV*)SvRV(href), ST(i), 0)) {
42 href = HeVAL(hv_fetch_ent(h, ST(i), FALSE, 0));
43 } else {
44 1 XSRETURN_NO;
45 }
46 }
47  
48 XSRETURN_YES;
49  
50 #/* I know that there's a better way to do this, rather than */
51 #/* duplicating all code, but I don't know what it is right now. */
52 void
53 Defined(href, ...)
54 SV* href
55  
56 CODE:
57 int i;
58 HV* h;
59 U32 hash;
60 SV* t;
61  
62 3 ▶ if (!SvOK(href) ||
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(href) || 3 0 3
63 3 ▶ !SvROK(href) ||
Branch: 1 branch
BranchTrueFalseTotal
!SvROK(href) || 3 0 3
64 3 ▶ (SvTYPE(t = SvRV(href)) != SVt_PVHV)) {
Branch: 1 branch
BranchTrueFalseTotal
(SvTYPE(t = SvRV(href)) != SVt_PVHV)) { 0 3 3
65 0 XSRETURN_NO;
66 }
67  
68 # /* The idea is easy. For each element of the array, */
69 11 ▶# /* if that element exists as a key of the hashref, */
Branch: 1 branch
BranchTrueFalseTotal
# /* if that element exists as a key of the hashref, */ 9 2 11
70 # /* set the hashref to that element. Otherwise, blow */
71 9 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
9 0 9
72 9 ▶# /* Note that at the top, href is an SV* of the hashref */
Branch: 1 branch
BranchTrueFalseTotal
# /* Note that at the top, href is an SV* of the hashref */ 9 0 9
73 18 for (i = 1; i < items; i++) {
74 9
75 8 if (SvOK(href) &&
76 SvROK(href) &&
77 1 SvPOK(ST(i)) &&
78 hv_exists_ent(h = (HV*)SvRV(href), ST(i), 0)) {
79 href = HeVAL(hv_fetch_ent(h, ST(i), FALSE, 0));
80 } else {
81 2 ▶ XSRETURN_NO;
Branch: 1 branch
BranchTrueFalseTotal
XSRETURN_NO; 1 1 2
82 1 }
83 }
84 1  
85 # /* href is the SV of the hashref */
86 if (!SvOK(href))
87 XSRETURN_NO;
88  
89 XSRETURN_YES;
90
91  
↑ Summary blib/lib/Hash/NoVivify.pm »