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/static.xs ↑ Summary xs/markdown.xs »
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);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = a ? newSVsv(a) : newSV(0); 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 all(self)
112 SV *self
113 CODE:
114 0 RETVAL = pmc_search(aTHX_ self, NULL, NULL);
115 OUTPUT:
116 RETVAL
117  
118 void
119 create(self, ...)
120 SV *self
121 ALIAS:
122 update = 1
123 delete = 2
124 CODE:
125 {
126 static const char *const what[] = { "create", "update", "delete" };
127 6 croak("%s: %s - the %s rows are worked out, not stored", pmc_cls(aTHX_ self),
128 what[ix], SvPV_nolen(pdbi_get(aTHX_ pmc_self(aTHX_ self), "table")));
129 }
130  
131 IV
132 limit(self, opts, dflt, max, what = &PL_sv_undef)
133 SV *self
134 SV *opts
135 SV *dflt
136 IV max
137 SV *what
138 CODE:
139 PERL_UNUSED_VAR(self);
140 12 RETVAL = pmc_limit(aTHX_ opts, dflt, max, what);
141 OUTPUT:
142 RETVAL
143  
144 SV *
145 cache_key(self, ...)
146 SV *self
147 CODE:
148 {
149 I32 i;
150 25 RETVAL = newSVsv(pdbi_get(aTHX_ pmc_self(aTHX_ self), "table"));
151 62 ▶ for (i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) { 39 23 62
152 39 sv_catpvs(RETVAL, "\t");
153 39 pmc_key_part(aTHX_ RETVAL, ST(i), 0);
154 }
155 }
156 OUTPUT:
157 RETVAL
158  
159 SV *
160 cached(self, key, code)
161 SV *self
162 SV *key
163 SV *code
164 CODE:
165 18 RETVAL = pmc_cached(aTHX_ self, key, code);
166 OUTPUT:
167 RETVAL
168  
169 void
170 cache_clear(self)
171 SV *self
172 CODE:
173 {
174 2 SV *c = pdbi_get(aTHX_ pmc_self(aTHX_ self), "cache");
175 2 ▶ if (c && SvROK(c)) hv_clear((HV *)SvRV(c));
Branch: 2 branches
BranchTrueFalseTotal
if (c && SvROK(c)) hv_clear((HV *)SvRV(c)); 2 0 2
if (c && SvROK(c)) hv_clear((HV *)SvRV(c)); 2 0 2
176 }
177  
178 IV
179 cache_size(self)
180 SV *self
181 CODE:
182 {
183 6 SV *c = pdbi_get(aTHX_ pmc_self(aTHX_ self), "cache");
184 6 ▶ RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0;
Branch: 4 branches
BranchTrueFalseTotal
RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0; 6 0 6
RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0; 6 0 6
RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0; 0 6 6
RETVAL = c && SvROK(c) ? (IV)HvUSEDKEYS((HV *)SvRV(c)) : 0; 0 6 6
185 }
186 OUTPUT:
187 RETVAL
188  
189 void
190 error(self, field, message)
191 SV *self
192 SV *field
193 SV *message
194 CODE:
195 PERL_UNUSED_VAR(self);
196 2 pmce_throw(aTHX_ NULL, field, message);
197  
198 void
199 wrap(self, field, code)
200 SV *self
201 SV *field
202 SV *code
203 PPCODE:
204 {
205 7 I32 gimme = GIMME_V;
206 I32 count;
207 7 SV *f = sv_2mortal(newSVsv(field));
208 PERL_UNUSED_VAR(self);
209 7 ▶ if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV))
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV)) 6 1 7
if (!(SvROK(code) && SvTYPE(SvRV(code)) == SVt_PVCV)) 0 6 6
210 1 croak("%s: wrap takes a field and a code reference", pmc_cls(aTHX_ self));
211 6 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 6 6
212 6 PUTBACK;
213 6 count = call_sv(code, gimme | G_EVAL);
214 6 SPAGAIN;
215 6 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 6 0 6
if (SvTRUE(ERRSV)) { 3 3 6
216 3 ▶ SV *e = sv_2mortal(newSVsv(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
SV *e = sv_2mortal(newSVsv(ERRSV)); 3 0 3
217 3 SP -= count;
218 3 PUTBACK;
219 3 croak_sv(pmce_from(aTHX_ NULL, f, e));
220 }
221 3 PUTBACK;
222 3 XSRETURN(count);
223 }
224  
225 MODULE = Punk PACKAGE = Punk::Model::Computed::Error
226  
227 PROTOTYPES: DISABLE
228  
229 SV *
230 new(class, field, message)
231 SV *class
232 SV *field
233 SV *message
234 CODE:
235 3 RETVAL = pmce_new(aTHX_ class, field, message);
236 OUTPUT:
237 RETVAL
238  
239 void
240 throw(class, field, message)
241 SV *class
242 SV *field
243 SV *message
244 CODE:
245 1 pmce_throw(aTHX_ class, field, message);
246  
247 SV *
248 from(class, field, error)
249 SV *class
250 SV *field
251 SV *error
252 CODE:
253 2 RETVAL = newSVsv(pmce_from(aTHX_ class, field, error));
254 OUTPUT:
255 RETVAL
256  
257 SV *
258 said(class, error)
259 SV *class
260 SV *error
261 CODE:
262 PERL_UNUSED_VAR(class);
263 8 RETVAL = newSVsv(pmce_said(aTHX_ error));
264 OUTPUT:
265 RETVAL
266  
267 SV *
268 field(self, ...)
269 SV *self
270 ALIAS:
271 message = 1
272 CODE:
273 {
274 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
275 30 ▶ RETVAL = v ? newSVsv(v) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : newSV(0); 30 0 30
276 }
277 OUTPUT:
278 RETVAL
279  
280 SV *
281 TO_JSON(self, ...)
282 SV *self
283 CODE:
284 {
285 1 HV *h = pmce_hv(aTHX_ self), *out = newHV();
286 1 SV *f = pdbi_get(aTHX_ h, "field"), *m = pdbi_get(aTHX_ h, "message");
287 1 ▶ (void)hv_stores(out, "field", f ? newSVsv(f) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(out, "field", f ? newSVsv(f) : newSV(0)); 1 0 1
288 1 ▶ (void)hv_stores(out, "message", m ? newSVsv(m) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(out, "message", m ? newSVsv(m) : newSV(0)); 1 0 1
289 1 RETVAL = newRV_noinc((SV *)out);
290 }
291 OUTPUT:
292 RETVAL
« xs/static.xs ↑ Summary xs/markdown.xs »