xs/validate.xs

filter: Statementstmt 82.7% 24 / 29 Branchbran 52.1% 24 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 64.0% 48 / 75 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/cors.xs ↑ Summary xs/i18n.xs »
1 MODULE = Punk PACKAGE = Punk::Validate
2  
3 PROTOTYPES: DISABLE
4  
5 # The boot half (punk_validate.h): called from Punk::App::compile_extras
6 # when any route carried a validate option. Compiles each schema once
7 # through the JSON::Schema::Fast C ABI, resolves on_invalid, and appends a
8 # C guard closure to the compiled record - after any auth guards.
9 void
10 _compile_routes(self)
11 SV *self
12 CODE:
13 6 pv_compile_routes(aTHX_ self);
14  
15 # How many compiled schemas $c->validate is holding. For the tests: the cache
16 # is bounded, and nothing else can see that it is.
17 IV
18 _cache_count()
19 CODE:
20 3 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 3 0 3
# uncoverable condition right count:1 class:ignore_covered_err 0 3 3
# uncoverable condition right count:1 class:ignore_covered_err 0 3 3
21 # uncoverable condition left count:2 class:ignore_covered_err
22 # uncoverable condition left count:3 class:ignore_covered_err
23 RETVAL = PV_CACHE ? (IV)HvUSEDKEYS(PV_CACHE) : 0;
24 OUTPUT:
25 RETVAL
26  
27 MODULE = Punk PACKAGE = Punk::Validate::Result
28  
29 PROTOTYPES: DISABLE
30  
31 # The collected outcome of one validation: { errors, data, schema? },
32 # built in C (pv_result_new) and read through these accessors.
33  
34 # has_errors: the error count - boolean in practice.
35 SV *
36 has_errors(self)
37 SV *self
38 CODE:
39 {
40 710 AV *errs = pv_result_errors(aTHX_ pv_result_hv(aTHX_ self));
41 710 ▶ RETVAL = newSViv(errs ? av_len(errs) + 1 : 0); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSViv(errs ? av_len(errs) + 1 : 0); /* # uncoverable condition right count:1 class:ignore_covered_err */ 710 0 710
42 }
43 OUTPUT:
44 RETVAL
45  
46 # errors: the arrayref, in the Open::API shape plus name.
47 SV *
48 errors(self)
49 SV *self
50 CODE:
51 {
52 4 HV *h = pv_result_hv(aTHX_ self);
53 4 SV **e = hv_fetchs(h, "errors", 0);
54 4 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 4 0 4
# uncoverable condition right count:1 class:ignore_covered_err 4 0 4
55 # uncoverable condition right count:2 class:ignore_covered_err
56 RETVAL = (e && *e) ? newSVsv(*e) : newRV_noinc((SV *)newAV());
57 }
58 OUTPUT:
59 RETVAL
60  
61 # The first message for one field - error($name) - or undef.
62 SV *
63 error(self, name)
64 SV *self
65 SV *name
66 CODE:
67 {
68 2 AV *errs = pv_result_errors(aTHX_ pv_result_hv(aTHX_ self));
69 2 ▶ SSize_t i, n = errs ? av_len(errs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, n = errs ? av_len(errs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ 2 0 2
70 2 STRLEN wl; const char *want = SvPV_const(name, wl);
71 2 RETVAL = NULL;
72 5 ▶ for (i = 0; i < n && !RETVAL; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n && !RETVAL; i++) { 4 1 5
for (i = 0; i < n && !RETVAL; i++) { 3 1 4
73 3 SV **ep = av_fetch(errs, i, 0);
74 HV *e; SV **nm;
75 3 ▶ # uncoverable branch true
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable branch true 3 0 3
# uncoverable branch true 3 0 3
# uncoverable branch true 3 0 3
76 3 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 0 3 3
77 3 # uncoverable condition left count:2 class:ignore_covered_err
78 3 # uncoverable condition left count:3 class:ignore_covered_err
79 3 ▶ # uncoverable condition left count:4 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:4 class:ignore_covered_err 3 0 3
# uncoverable condition left count:4 class:ignore_covered_err 3 0 3
# uncoverable condition left count:4 class:ignore_covered_err 3 0 3
80 3 if (!(ep && *ep && SvROK(*ep)
81 3 ▶ && SvTYPE(SvRV(*ep)) == SVt_PVHV)) continue;
Branch: 2 branches
BranchTrueFalseTotal
&& SvTYPE(SvRV(*ep)) == SVt_PVHV)) continue; 2 1 3
&& SvTYPE(SvRV(*ep)) == SVt_PVHV)) continue; 2 0 2
82 2 e = (HV *)SvRV(*ep);
83 2 ▶ nm = hv_fetchs(e, "name", 0);
Branch: 2 branches
BranchTrueFalseTotal
nm = hv_fetchs(e, "name", 0); 2 0 2
nm = hv_fetchs(e, "name", 0); 2 0 2
84 # uncoverable branch false
85 # uncoverable condition right count:1 class:ignore_covered_err
86 # uncoverable condition right count:2 class:ignore_covered_err
87 2 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 0 2 2
88 if (nm && *nm && SvOK(*nm)) {
89 STRLEN nl; const char *ns = SvPV_const(*nm, nl);
90 if (nl == wl && memEQ(ns, want, wl)) { /* # uncoverable condition right count:2 class:ignore_covered_err */
91 SV **msg = hv_fetchs(e, "message", 0);
92 # uncoverable condition right count:1 class:ignore_covered_err
93 # uncoverable condition right count:2 class:ignore_covered_err
94 RETVAL = (msg && *msg) ? newSVsv(*msg) : newSV(0);
95 }
96 }
97 }
98 # uncoverable branch true
99 # uncoverable condition left count:1 class:ignore_covered_err
100 if (!RETVAL) RETVAL = newSV(0);
101 }
102 OUTPUT:
103 RETVAL
104  
105 # valid / valid($name): typed, filtered params (punk_validate.h).
106 SV *
107 valid(self, name = &PL_sv_undef)
108 SV *self
109 SV *name
110 CODE:
111 5 RETVAL = pv_result_valid(aTHX_ pv_result_hv(aTHX_ self), name);
112 OUTPUT:
113 RETVAL
114  
115 # TO_JSON: { errors => [...] } - the Result encodes as the 400 body.
116 SV *
117 # uncoverable statement
118 # uncoverable subroutine
119 TO_JSON(self)
120 SV *self
121 CODE:
122 {
123 0 HV *h = pv_result_hv(aTHX_ self); /* # uncoverable statement */
124 0 SV **e = hv_fetchs(h, "errors", 0); /* # uncoverable statement */
125 0 HV *out = newHV(); /* # uncoverable statement */
126 0 ▶ (void)hv_stores(out, "errors", /* # uncoverable statement */
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(out, "errors", /* # uncoverable statement */ 0 0 0
(void)hv_stores(out, "errors", /* # uncoverable statement */ 0 0 0
127 (e && *e) ? newSVsv(*e) : newRV_noinc((SV *)newAV()));
128 0 RETVAL = newRV_noinc((SV *)out); /* # uncoverable statement */
129 }
130 OUTPUT:
131 RETVAL
« xs/cors.xs ↑ Summary xs/i18n.xs »