xs/computed.xs

filter: Statementstmt 98.4% 64 / 65 Branchbran 69.2% 36 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.4% 100 / 117 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/app.xs ↑ Summary include/punk/punk_response.h »
1 MODULE = Punk PACKAGE = Punk::Model::Computed
2  
3 PROTOTYPES: DISABLE
4  
5 # A base for read-only backends whose rows are worked out from the question
6 # (punk_computed.h). Punk::Model::Computed.pm is the documentation.
7  
8 void
9 answers(class, ...)
10 SV *class
11 PPCODE:
12 {
13 14 const char *cls = pmc_cls(aTHX_ class);
14 I32 i;
15 14 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 3 11 14
16 3 AV *t = pmc_tables(aTHX_ cls);
17 3 SSize_t j, n = av_len(t) + 1;
18 3 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 3 0 3
EXTEND(SP, n); 0 3 3
19 10 ▶ for (j = 0; j < n; j++) PUSHs(*av_fetch(t, j, 0));
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < n; j++) PUSHs(*av_fetch(t, j, 0)); 7 3 10
20 3 XSRETURN(n);
21 }
22 11 ▶ if (items % 2 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (items % 2 == 0) 1 10 11
23 1 croak("%s: answers takes table => { ... } pairs", cls);
24 13 ▶ for (i = 1; i + 1 < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) 11 2 13
25 11 pmc_declare(aTHX_ cls, ST(i), ST(i + 1));
26 2 XSRETURN_EMPTY;
27 }
28  
29 SV *
30 new(class, ...)
31 SV *class
32 CODE:
33 7 RETVAL = pmc_build(aTHX_ class, &ST(0), items);
34 OUTPUT:
35 RETVAL
36  
37 SV *
38 table(self)
39 SV *self
40 CODE:
41 1 RETVAL = newSVsv(pdbi_get(aTHX_ pmc_self(aTHX_ self), "table"));
42 OUTPUT:
43 RETVAL
44  
45 SV *
46 app(self)
47 SV *self
48 CODE:
49 {
50 1 SV *a = pdbi_get(aTHX_ pmc_self(aTHX_ self), "app");
51 1 ▶ RETVAL = a ? newSVsv(a) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = a ? newSVsv(a) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */ 1 0 1
52 }
53 OUTPUT:
54 RETVAL
55  
56 SV *
57 filter(self, filter = &PL_sv_undef)
58 SV *self
59 SV *filter
60 CODE:
61 3 RETVAL = newSVsv(pmc_filter(aTHX_ self, filter));
62 OUTPUT:
63 RETVAL
64  
65 SV *
66 options(self, opts = &PL_sv_undef)
67 SV *self
68 SV *opts
69 CODE:
70 1 RETVAL = newSVsv(pmc_options(aTHX_ self, opts));
71 OUTPUT:
72 RETVAL
73  
74 SV *
75 get(self, ...)
76 SV *self
77 CODE:
78 {
79 20 HV *key = (HV *)sv_2mortal((SV *)newHV());
80 I32 i;
81 20 ▶ if (items % 2 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (items % 2 == 0) 1 19 20
82 1 croak("%s: get takes field => value pairs", pmc_cls(aTHX_ self));
83 43 ▶ for (i = 1; i + 1 < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) 24 19 43
84 24 (void)hv_store_ent(key, ST(i), newSVsv(ST(i + 1)), 0);
85 19 RETVAL = pmc_call(aTHX_ self, 0,
86 pmc_filter(aTHX_ self, sv_2mortal(newRV_inc((SV *)key))), NULL);
87 }
88 OUTPUT:
89 RETVAL
90  
91 SV *
92 search(self, filter = &PL_sv_undef, opts = &PL_sv_undef)
93 SV *self
94 SV *filter
95 SV *opts
96 CODE:
97 18 RETVAL = pmc_search(aTHX_ self, filter, opts);
98 OUTPUT:
99 RETVAL
100  
101 SV *
102 count(self, filter = &PL_sv_undef)
103 SV *self
104 SV *filter
105 CODE:
106 1 RETVAL = pmc_call(aTHX_ self, 2, pmc_filter(aTHX_ self, filter), NULL);
107 OUTPUT:
108 RETVAL
109  
110 SV *
111 # uncoverable statement
112 # uncoverable subroutine
113 all(self)
114 SV *self
115 CODE:
116 0 RETVAL = pmc_search(aTHX_ self, NULL, NULL); /* # uncoverable statement */
117 OUTPUT:
118 RETVAL
119  
120 void
121 create(self, ...)
122 SV *self
123 ALIAS:
124 update = 1
125 delete = 2
126 CODE:
127 {
128 static const char *const what[] = { "create", "update", "delete" };
129 6 croak("%s: %s - the %s rows are worked out, not stored", pmc_cls(aTHX_ self),
130 what[ix], SvPV_nolen(pdbi_get(aTHX_ pmc_self(aTHX_ self), "table")));
131 }
132  
133 IV
134 limit(self, opts, dflt, max, what = &PL_sv_undef)
135 SV *self
136 SV *opts
137 SV *dflt
138 IV max
139 SV *what
140 CODE:
141 PERL_UNUSED_VAR(self);
142 12 RETVAL = pmc_limit(aTHX_ opts, dflt, max, what);
143 OUTPUT:
144 RETVAL
145  
146 SV *
147 cache_key(self, ...)
148 SV *self
149 CODE:
150 {
151 I32 i;
152 25 RETVAL = newSVsv(pdbi_get(aTHX_ pmc_self(aTHX_ self), "table"));
153 62 ▶ for (i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) { 39 23 62
154 39 sv_catpvs(RETVAL, "\t");
155 39 pmc_key_part(aTHX_ RETVAL, ST(i), 0);
156 }
157 }
158 OUTPUT:
159 RETVAL
160  
161 SV *
162 cached(self, key, code)
163 SV *self
164 SV *key
165 SV *code
166 CODE:
167 18 RETVAL = pmc_cached(aTHX_ self, key, code);
168 OUTPUT:
169 RETVAL
170  
171 void
172 cache_clear(self)
173 SV *self
174 CODE:
175 {
176 2 SV *c = pdbi_get(aTHX_ pmc_self(aTHX_ self), "cache");
177 2 ▶ # uncoverable branch false
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch false 2 0 2
# uncoverable branch false 2 0 2
178 # uncoverable condition right count:1 class:ignore_covered_err
179 # uncoverable condition right count:2 class:ignore_covered_err
180 if (c && SvROK(c)) hv_clear((HV *)SvRV(c));
181 }
182  
183 IV
184 cache_size(self)
185 SV *self
186 CODE:
187 {
188 6 SV *c = pdbi_get(aTHX_ pmc_self(aTHX_ self), "cache");
189 6 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 6 0 6
# uncoverable condition right count:1 class:ignore_covered_err 6 0 6
# uncoverable condition right count:1 class:ignore_covered_err 0 6 6
# uncoverable condition right count:1 class:ignore_covered_err 0 6 6
190 # uncoverable condition right count:2 class:ignore_covered_err
191 RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0;
192 }
193 OUTPUT:
194 RETVAL
195  
196 void
197 # uncoverable statement class:ignore_covered_err
198 # uncoverable subroutine class:ignore_covered_err
199 error(self, field, message)
200 SV *self
201 SV *field
202 SV *message
203 CODE:
204 PERL_UNUSED_VAR(self);
205 2 pmce_throw(aTHX_ NULL, field, message); /* # uncoverable statement class:ignore_covered_err */
206  
207 void
208 wrap(self, field, code)
209 SV *self
210 SV *field
211 SV *code
212 PPCODE:
213 {
214 7 I32 gimme = GIMME_V;
215 I32 count;
216 7 SV *f = sv_2mortal(newSVsv(field));
217 PERL_UNUSED_VAR(self);
218 7 ▶ if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV)) /* # uncoverable condition left count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV)) /* # uncoverable condition left count:2 class:ignore_covered_err */ 6 1 7
if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV)) /* # uncoverable condition left count:2 class:ignore_covered_err */ 0 6 6
219 1 croak("%s: wrap takes a field and a code reference", pmc_cls(aTHX_ self));
220 6 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 6 6
221 6 PUTBACK;
222 6 count = call_sv(code, gimme | G_EVAL);
223 6 SPAGAIN;
224 6 ▶ if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 6 0 6
if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 3 3 6
225 3 ▶ SV *e = sv_2mortal(newSVsv(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
SV *e = sv_2mortal(newSVsv(ERRSV)); 3 0 3
226 3 SP -= count;
227 3 PUTBACK;
228 3 croak_sv(pmce_from(aTHX_ NULL, f, e));
229 }
230 3 PUTBACK;
231 3 XSRETURN(count);
232 }
233  
234 MODULE = Punk PACKAGE = Punk::Model::Computed::Error
235  
236 PROTOTYPES: DISABLE
237  
238 SV *
239 new(class, field, message)
240 SV *class
241 SV *field
242 SV *message
243 CODE:
244 3 RETVAL = pmce_new(aTHX_ class, field, message);
245 OUTPUT:
246 RETVAL
247  
248 void
249 # uncoverable statement class:ignore_covered_err
250 # uncoverable subroutine class:ignore_covered_err
251 throw(class, field, message)
252 SV *class
253 SV *field
254 SV *message
255 CODE:
256 1 pmce_throw(aTHX_ class, field, message); /* # uncoverable statement class:ignore_covered_err */
257  
258 SV *
259 from(class, field, error)
260 SV *class
261 SV *field
262 SV *error
263 CODE:
264 2 RETVAL = newSVsv(pmce_from(aTHX_ class, field, error));
265 OUTPUT:
266 RETVAL
267  
268 SV *
269 said(class, error)
270 SV *class
271 SV *error
272 CODE:
273 PERL_UNUSED_VAR(class);
274 8 RETVAL = newSVsv(pmce_said(aTHX_ error));
275 OUTPUT:
276 RETVAL
277  
278 SV *
279 field(self, ...)
280 SV *self
281 ALIAS:
282 message = 1
283 CODE:
284 {
285 30 ▶ SV *v = pdbi_get(aTHX_ pmce_hv(aTHX_ self), ix ? "message" : "field");
Branch: 1 branch
BranchTrueFalseTotal
SV *v = pdbi_get(aTHX_ pmce_hv(aTHX_ self), ix ? "message" : "field"); 17 13 30
286 30 ▶ RETVAL = v ? newSVsv(v) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */ 30 0 30
287 }
288 OUTPUT:
289 RETVAL
290  
291 SV *
292 TO_JSON(self, ...)
293 SV *self
294 CODE:
295 {
296 1 HV *h = pmce_hv(aTHX_ self), *out = newHV();
297 1 SV *f = pdbi_get(aTHX_ h, "field"), *m = pdbi_get(aTHX_ h, "message");
298 1 ▶ (void)hv_stores(out, "field", f ? newSVsv(f) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(out, "field", f ? newSVsv(f) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ 1 0 1
299 1 ▶ (void)hv_stores(out, "message", m ? newSVsv(m) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(out, "message", m ? newSVsv(m) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ 1 0 1
300 1 RETVAL = newRV_noinc((SV *)out);
301 }
302 OUTPUT:
303 RETVAL
« xs/app.xs ↑ Summary include/punk/punk_response.h »