| 1 |
|
| /* punk_mrows.h - the Punk::Model contract over rows held in memory, and the |
| 2 |
|
| * two backends built on it: Punk::Model::JSONFile (rows in a JSON file, read |
| 3 |
|
| * and write) and Punk::Model::Markdown (the pages of a `markdown` mount, |
| 4 |
|
| * read-only). |
| 5 |
|
| * |
| 6 |
|
| * Everything that is not SQL is punk_dbq.h's - the operator set, the column |
| 7 |
|
| * checks and their croaks, the ordering with its primary-key tie-breaker, the |
| 8 |
|
| * search options, the keyset token and the page - so a filter, an order_by or |
| 9 |
|
| * a `next` token means the same here as on Punk::Model::DBI. What this file |
| 10 |
|
| * adds is evaluating them against Perl rows instead of writing them as SQL: |
| 11 |
|
| * |
| 12 |
|
| * - three-valued logic, as SQL has it: NULL (undef) never equals, compares |
| 13 |
|
| * or is `in` anything; `!=` leaves NULLs out; `not_in` over a list that |
| 14 |
|
| * holds NULL matches nothing, and over an empty list matches everything; |
| 15 |
|
| * - values compare as numbers when both look like numbers, else as strings |
| 16 |
|
| * (sv_cmp), and NULL sorts before every value, as on SQLite; |
| 17 |
|
| * - `like` takes `%` and `_`, case-sensitively; `starts_with` is a literal |
| 18 |
|
| * prefix. |
| 19 |
|
| * |
| 20 |
|
| * The object is the blessed hash pdbi_build_self makes (opts/table/primary/ |
| 21 |
|
| * columns/col), so pdbq_check_keys and the rest read it unchanged. |
| 22 |
|
| * |
| 23 |
|
| * Include after punk_dbq.h, punk_markdown.h and punk_app.h. */ |
| 24 |
|
| |
| 25 |
|
| #ifndef PUNK_MROWS_H |
| 26 |
|
| #define PUNK_MROWS_H |
| 27 |
|
| |
| 28 |
|
| /* ---- comparing two values -------------------------------------------------- */ |
| 29 |
|
| |
| 30 |
|
| /* A value's number, read WITHOUT caching one on the SV: SvNV would set NOK |
| 31 |
|
| * on a row held in the JSON cache, and the encoder would then write an |
| 32 |
|
| * integer id back as 2.0. */ |
| 33 |
11102 |
| static NV pmr_num(pTHX_ SV *sv) { |
| 34 |
11102 |
▶ | if (SvNOK(sv)) return SvNVX(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvNOK(sv)) return SvNVX(sv); |
63 |
11039 |
11102 |
|
| 35 |
11039 |
▶ | if (SvIOK(sv)) return SvIsUV(sv) ? (NV)SvUVX(sv) : (NV)SvIVX(sv); /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIOK(sv)) return SvIsUV(sv) ? (NV)SvUVX(sv) : (NV)SvIVX(sv); /* # uncoverable condition left count:2 class:ignore_covered_err */ |
11026 |
13 |
11039 |
| if (SvIOK(sv)) return SvIsUV(sv) ? (NV)SvUVX(sv) : (NV)SvIVX(sv); /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
11026 |
11026 |
|
| 36 |
13 |
▶ | return SvPOK(sv) ? Atof(SvPVX(sv)) : 0.0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| return SvPOK(sv) ? Atof(SvPVX(sv)) : 0.0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
13 |
0 |
13 |
|
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
|
| /* An integer key as an IV, without touching the SV's flags: an integer SV, |
| 40 |
|
| * or a string of digits with an optional sign. 0 when it is not one. */ |
| 41 |
25 |
| static int pmr_int(pTHX_ SV *sv, IV *out) { |
| 42 |
|
| /* |
| 43 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 44 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 45 |
25 |
▶ | if (SvIOK(sv) && !SvNOK(sv) && !SvPOK(sv)) { *out = SvIVX(sv); return 1; } |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvIOK(sv) && !SvNOK(sv) && !SvPOK(sv)) { *out = SvIVX(sv); return 1; } |
20 |
5 |
25 |
| if (SvIOK(sv) && !SvNOK(sv) && !SvPOK(sv)) { *out = SvIVX(sv); return 1; } |
20 |
0 |
20 |
| if (SvIOK(sv) && !SvNOK(sv) && !SvPOK(sv)) { *out = SvIVX(sv); return 1; } |
20 |
0 |
20 |
|
| 46 |
|
| /* |
| 47 |
|
| # uncoverable branch true |
| 48 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 49 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 50 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 51 |
5 |
▶ | if (SvNOK(sv) && !SvPOK(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvNOK(sv) && !SvPOK(sv)) { |
0 |
5 |
5 |
| if (SvNOK(sv) && !SvPOK(sv)) { |
0 |
0 |
0 |
|
| 52 |
0 |
| NV v = SvNVX(sv); /* # uncoverable statement */ |
| 53 |
|
| /* |
| 54 |
|
| # uncoverable statement |
| 55 |
|
| # uncoverable branch true |
| 56 |
|
| # uncoverable branch false |
| 57 |
|
| # uncoverable condition left count:1 |
| 58 |
|
| # uncoverable condition right count:1 */ |
| 59 |
0 |
▶ | if (v != (NV)(IV)v) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (v != (NV)(IV)v) return 0; |
0 |
0 |
0 |
|
| 60 |
0 |
| *out = (IV)v; /* # uncoverable statement */ |
| 61 |
0 |
| return 1; /* # uncoverable statement */ |
| 62 |
|
| } |
| 63 |
|
| /* |
| 64 |
|
| # uncoverable branch false |
| 65 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 66 |
5 |
▶ | if (SvPOK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvPOK(sv)) { |
5 |
0 |
5 |
|
| 67 |
5 |
| STRLEN l, i = 0; |
| 68 |
5 |
| const char *p = SvPV_const(sv, l); |
| 69 |
|
| /* |
| 70 |
|
| # uncoverable branch true |
| 71 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 72 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 73 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 74 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 75 |
5 |
▶ | if (l && (p[0] == '-' || p[0] == '+')) i = 1; |
Branch: 3 branches
| Branch | True | False | Total |
| if (l && (p[0] == '-' || p[0] == '+')) i = 1; |
5 |
0 |
5 |
| if (l && (p[0] == '-' || p[0] == '+')) i = 1; |
5 |
0 |
5 |
| if (l && (p[0] == '-' || p[0] == '+')) i = 1; |
0 |
5 |
5 |
|
| 76 |
|
| /* |
| 77 |
|
| # uncoverable branch true |
| 78 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 79 |
5 |
▶ | if (i == l) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == l) return 0; |
0 |
5 |
5 |
|
| 80 |
|
| /* |
| 81 |
|
| # uncoverable branch false |
| 82 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 83 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 84 |
5 |
▶ | for (; i < l; i++) if (!isDIGIT(p[i])) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| for (; i < l; i++) if (!isDIGIT(p[i])) return 0; |
5 |
0 |
5 |
| for (; i < l; i++) if (!isDIGIT(p[i])) return 0; |
5 |
0 |
5 |
|
| 85 |
0 |
| *out = (IV)Atof(p); /* # uncoverable statement */ |
| 86 |
0 |
| return 1; /* # uncoverable statement */ |
| 87 |
|
| } |
| 88 |
0 |
| return 0; /* # uncoverable statement */ |
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| /* A value to string-compare, never the row's own SV unless it already is a |
| 92 |
|
| * string: sv_cmp stringifies, and a cached PV on a number changes how it is |
| 93 |
|
| * encoded. */ |
| 94 |
774 |
| static SV *pmr_str(pTHX_ SV *sv) { |
| 95 |
774 |
▶ | return SvPOK(sv) ? sv : sv_2mortal(newSVsv(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| return SvPOK(sv) ? sv : sv_2mortal(newSVsv(sv)); |
15 |
759 |
774 |
|
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
|
| /* <0, 0, >0 with NULL lowest. Numbers compare as numbers when both sides |
| 99 |
|
| * look like one ("10" after "9"), everything else as strings. Neither side |
| 100 |
|
| * is changed. */ |
| 101 |
5978 |
| static int pmr_cmp(pTHX_ SV *a, SV *b) { |
| 102 |
5978 |
▶ | int da = a && SvOK(a), db = b && SvOK(b); |
Branch: 4 branches
| Branch | True | False | Total |
| int da = a && SvOK(a), db = b && SvOK(b); |
5978 |
0 |
5978 |
| int da = a && SvOK(a), db = b && SvOK(b); |
5958 |
20 |
5978 |
| int da = a && SvOK(a), db = b && SvOK(b); |
5978 |
0 |
5978 |
| int da = a && SvOK(a), db = b && SvOK(b); |
5958 |
20 |
5978 |
|
| 103 |
5978 |
▶ | if (!da || !db) return da == db ? 0 : (da ? 1 : -1); |
Branch: 4 branches
| Branch | True | False | Total |
| if (!da || !db) return da == db ? 0 : (da ? 1 : -1); |
5958 |
20 |
5978 |
| if (!da || !db) return da == db ? 0 : (da ? 1 : -1); |
20 |
5938 |
5958 |
| if (!da || !db) return da == db ? 0 : (da ? 1 : -1); |
40 |
0 |
40 |
| if (!da || !db) return da == db ? 0 : (da ? 1 : -1); |
20 |
20 |
40 |
|
| 104 |
|
| /* |
| 105 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 106 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 107 |
5938 |
▶ | if (!SvROK(a) && !SvROK(b) && looks_like_number(a) && looks_like_number(b)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!SvROK(a) && !SvROK(b) && looks_like_number(a) && looks_like_number(b)) { |
5938 |
0 |
5938 |
| if (!SvROK(a) && !SvROK(b) && looks_like_number(a) && looks_like_number(b)) { |
5938 |
0 |
5938 |
| if (!SvROK(a) && !SvROK(b) && looks_like_number(a) && looks_like_number(b)) { |
5566 |
372 |
5938 |
| if (!SvROK(a) && !SvROK(b) && looks_like_number(a) && looks_like_number(b)) { |
5551 |
15 |
5566 |
|
| 108 |
5551 |
| NV x = pmr_num(aTHX_ a), y = pmr_num(aTHX_ b); |
| 109 |
5551 |
▶ | return x < y ? -1 : x > y ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return x < y ? -1 : x > y ? 1 : 0; |
3613 |
1938 |
5551 |
|
| 110 |
|
| } |
| 111 |
387 |
| return sv_cmp(pmr_str(aTHX_ a), pmr_str(aTHX_ b)); |
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
|
| /* SQL LIKE: `%` any run, `_` one character, everything else literal and |
| 115 |
|
| * case-sensitive. Character-wise on a UTF-8 value, so `_` is one character |
| 116 |
|
| * and not one byte. */ |
| 117 |
155 |
| static int pmr_like(const U8 *s, const U8 *se, const U8 *p, const U8 *pe, |
| 118 |
|
| int utf8) { |
| 119 |
230 |
▶ | while (p < pe) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < pe) { |
225 |
5 |
230 |
|
| 120 |
225 |
▶ | if (*p == '%') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '%') { |
60 |
165 |
225 |
|
| 121 |
120 |
▶ | while (p < pe && *p == '%') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < pe && *p == '%') p++; |
85 |
35 |
120 |
| while (p < pe && *p == '%') p++; |
60 |
25 |
85 |
|
| 122 |
60 |
▶ | if (p == pe) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p == pe) return 1; |
25 |
35 |
60 |
|
| 123 |
|
| for (;;) { |
| 124 |
50 |
▶ | if (pmr_like(s, se, p, pe, utf8)) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (pmr_like(s, se, p, pe, utf8)) return 1; |
25 |
25 |
50 |
|
| 125 |
|
| /* |
| 126 |
|
| # uncoverable branch true |
| 127 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 128 |
25 |
▶ | if (s >= se) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s >= se) return 0; |
0 |
25 |
25 |
|
| 129 |
25 |
▶ | s += utf8 ? UTF8SKIP(s) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| s += utf8 ? UTF8SKIP(s) : 1; |
5 |
20 |
25 |
|
| 130 |
|
| } |
| 131 |
|
| } |
| 132 |
|
| /* |
| 133 |
|
| # uncoverable branch true |
| 134 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 135 |
165 |
▶ | if (s >= se) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s >= se) return 0; |
0 |
165 |
165 |
|
| 136 |
165 |
▶ | if (*p == '_') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '_') { |
15 |
150 |
165 |
|
| 137 |
15 |
▶ | s += utf8 ? UTF8SKIP(s) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| s += utf8 ? UTF8SKIP(s) : 1; |
5 |
10 |
15 |
|
| 138 |
15 |
| p++; |
| 139 |
15 |
| continue; |
| 140 |
|
| } |
| 141 |
150 |
▶ | if (*p != *s) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p != *s) return 0; |
90 |
60 |
150 |
|
| 142 |
60 |
| p++; s++; |
| 143 |
|
| } |
| 144 |
5 |
| return s == se; |
| 145 |
|
| } |
| 146 |
|
| |
| 147 |
|
| /* ---- the filter ------------------------------------------------------------- |
| 148 |
|
| * |
| 149 |
|
| * Compiled once per call into terms (column, operator, value), validated |
| 150 |
|
| * exactly as pdbq_where validates - the same croaks, in the same order - and |
| 151 |
|
| * then run against each row. */ |
| 152 |
|
| |
| 153 |
|
| typedef struct { SV *col; int op; SV *val; } pmr_term; |
| 154 |
|
| |
| 155 |
|
| /* Mortal AV of terms, each an AV [col, op, val]. */ |
| 156 |
302 |
| static AV *pmr_compile(pTHX_ HV *col, SV *table, HV *filter, const char *cls) { |
| 157 |
302 |
| AV *terms = (AV *)sv_2mortal((SV *)newAV()); |
| 158 |
|
| AV *keys; |
| 159 |
|
| SSize_t i, n; |
| 160 |
|
| /* |
| 161 |
|
| # uncoverable branch true |
| 162 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 163 |
302 |
▶ | if (!filter) return terms; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!filter) return terms; |
0 |
302 |
302 |
|
| 164 |
302 |
| keys = pdbi_sorted_keys(aTHX_ filter); |
| 165 |
302 |
| n = av_len(keys) + 1; |
| 166 |
468 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
200 |
268 |
468 |
|
| 167 |
200 |
| SV *k = *av_fetch(keys, i, 0); |
| 168 |
200 |
| HE *he = hv_fetch_ent(filter, k, 0, 0); |
| 169 |
200 |
▶ | SV *val = he ? HeVAL(he) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *val = he ? HeVAL(he) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
200 |
0 |
200 |
|
| 170 |
200 |
| pdbq_check_col(aTHX_ col, k, table, cls, "the filter"); |
| 171 |
195 |
▶ | if (val && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (val && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
195 |
0 |
195 |
| if (val && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
122 |
73 |
195 |
| if (val && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
116 |
6 |
122 |
|
| 172 |
116 |
| HV *ops = (HV *)SvRV(val); |
| 173 |
116 |
| AV *onames = pdbi_sorted_keys(aTHX_ ops); |
| 174 |
116 |
| SSize_t j, m = av_len(onames) + 1; |
| 175 |
116 |
▶ | if (m == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (m == 0) |
5 |
111 |
116 |
|
| 176 |
15 |
▶ | croak("%s: the filter on %s is an empty hashref - it needs an " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("%s: the filter on %s is an empty hashref - it needs an " |
5 |
0 |
5 |
|
| 177 |
|
| "operator (%s)", cls, SvPV_nolen(k), |
| 178 |
|
| SvPV_nolen(pdbq_op_list(aTHX))); |
| 179 |
209 |
▶ | for (j = 0; j < m; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < m; j++) { |
116 |
93 |
209 |
|
| 180 |
116 |
| SV *on = *av_fetch(onames, j, 0); |
| 181 |
116 |
| STRLEN ol; const char *op = SvPV_const(on, ol); |
| 182 |
116 |
| int idx = pdbq_op_index(op, ol); |
| 183 |
|
| HE *oe; |
| 184 |
|
| SV *v; |
| 185 |
|
| AV *t; |
| 186 |
116 |
▶ | if (idx < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (idx < 0) |
5 |
111 |
116 |
|
| 187 |
15 |
▶ | croak("%s: unknown operator '%s' on %s (known: %s)", |
Branch: 1 branch
| Branch | True | False | Total |
| croak("%s: unknown operator '%s' on %s (known: %s)", |
5 |
0 |
5 |
|
| 188 |
|
| cls, op, SvPV_nolen(k), |
| 189 |
|
| SvPV_nolen(pdbq_op_list(aTHX))); |
| 190 |
111 |
| oe = hv_fetch_ent(ops, on, 0, 0); |
| 191 |
111 |
▶ | v = oe ? HeVAL(oe) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| v = oe ? HeVAL(oe) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
111 |
0 |
111 |
|
| 192 |
111 |
| switch (idx) { |
| 193 |
67 |
| case PDBQ_LT: case PDBQ_LE: case PDBQ_GT: case PDBQ_GE: |
| 194 |
|
| case PDBQ_LIKE: case PDBQ_STARTS_WITH: |
| 195 |
67 |
▶ | if (!(v && SvOK(v))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(v && SvOK(v))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
67 |
0 |
67 |
| if (!(v && SvOK(v))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
6 |
61 |
67 |
|
| 196 |
6 |
| croak("%s: '%s' on %s needs a value, not undef", |
| 197 |
|
| cls, PDBQ_OPS[idx].name, SvPV_nolen(k)); |
| 198 |
61 |
▶ | if (SvROK(v)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(v)) |
1 |
60 |
61 |
|
| 199 |
2 |
| croak("%s: '%s' on %s takes a plain value, not a %s", |
| 200 |
|
| cls, PDBQ_OPS[idx].name, SvPV_nolen(k), |
| 201 |
|
| sv_reftype(SvRV(v), 0)); |
| 202 |
60 |
| break; |
| 203 |
33 |
| case PDBQ_IN: case PDBQ_NOT_IN: |
| 204 |
|
| /* |
| 205 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 206 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 207 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 208 |
33 |
▶ | if (!(v && SvOK(v) && SvROK(v) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(v && SvOK(v) && SvROK(v) |
33 |
0 |
33 |
| if (!(v && SvOK(v) && SvROK(v) |
33 |
0 |
33 |
| if (!(v && SvOK(v) && SvROK(v) |
27 |
6 |
33 |
|
| 209 |
27 |
▶ | && SvTYPE(SvRV(v)) == SVt_PVAV)) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(v)) == SVt_PVAV)) |
0 |
27 |
27 |
|
| 210 |
6 |
| croak("%s: '%s' on %s takes an arrayref", |
| 211 |
|
| cls, PDBQ_OPS[idx].name, SvPV_nolen(k)); |
| 212 |
27 |
| break; |
| 213 |
11 |
| default: break; |
| 214 |
|
| } |
| 215 |
98 |
| t = newAV(); |
| 216 |
98 |
| av_push(t, newSVsv(k)); |
| 217 |
98 |
| av_push(t, newSViv(idx)); |
| 218 |
98 |
▶ | av_push(t, v ? newSVsv(v) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(t, v ? newSVsv(v) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
98 |
0 |
98 |
|
| 219 |
98 |
| av_push(terms, newRV_noinc((SV *)t)); |
| 220 |
|
| } |
| 221 |
93 |
| continue; |
| 222 |
|
| } |
| 223 |
79 |
▶ | if (val && SvROK(val)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (val && SvROK(val)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
79 |
0 |
79 |
| if (val && SvROK(val)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
73 |
79 |
|
| 224 |
12 |
▶ | croak("%s: the filter on %s is a %s - a list is spelled " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("%s: the filter on %s is a %s - a list is spelled " |
0 |
6 |
6 |
|
| 225 |
|
| "{ in => [...] }, and everything else is a plain value or " |
| 226 |
|
| "{ operator => value }", cls, SvPV_nolen(k), |
| 227 |
|
| SvTYPE(SvRV(val)) == SVt_PVAV ? "plain arrayref" /* # uncoverable condition left count:1 class:ignore_covered_err */ |
| 228 |
|
| : sv_reftype(SvRV(val), 0)); /* # uncoverable statement */ |
| 229 |
|
| { |
| 230 |
73 |
| AV *t = newAV(); |
| 231 |
73 |
| av_push(t, newSVsv(k)); |
| 232 |
73 |
| av_push(t, newSViv(PDBQ_EQ)); |
| 233 |
73 |
▶ | av_push(t, val ? newSVsv(val) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(t, val ? newSVsv(val) : newSV(0)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
73 |
0 |
73 |
|
| 234 |
73 |
| av_push(terms, newRV_noinc((SV *)t)); |
| 235 |
|
| } |
| 236 |
|
| } |
| 237 |
268 |
| return terms; |
| 238 |
|
| } |
| 239 |
|
| |
| 240 |
743 |
| static int pmr_term_ok(pTHX_ int op, SV *rv, SV *val) { |
| 241 |
743 |
▶ | int rdef = rv && SvOK(rv); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| int rdef = rv && SvOK(rv); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
743 |
0 |
743 |
| int rdef = rv && SvOK(rv); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
676 |
67 |
743 |
|
| 242 |
743 |
| switch (op) { /* # uncoverable branch true count:9 */ |
| 243 |
265 |
| case PDBQ_EQ: |
| 244 |
265 |
▶ | if (!SvOK(val)) return !rdef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(val)) return !rdef; |
54 |
211 |
265 |
|
| 245 |
211 |
▶ | return rdef && pmr_cmp(aTHX_ rv, val) == 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return rdef && pmr_cmp(aTHX_ rv, val) == 0; |
206 |
5 |
211 |
| return rdef && pmr_cmp(aTHX_ rv, val) == 0; |
55 |
151 |
206 |
|
| 246 |
54 |
| case PDBQ_NE: |
| 247 |
54 |
▶ | if (!SvOK(val)) return rdef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(val)) return rdef; |
29 |
25 |
54 |
|
| 248 |
25 |
▶ | return rdef && pmr_cmp(aTHX_ rv, val) != 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return rdef && pmr_cmp(aTHX_ rv, val) != 0; |
20 |
5 |
25 |
| return rdef && pmr_cmp(aTHX_ rv, val) != 0; |
10 |
10 |
20 |
|
| 249 |
50 |
▶ | case PDBQ_LT: return rdef && pmr_cmp(aTHX_ rv, val) < 0; |
Branch: 2 branches
| Branch | True | False | Total |
| case PDBQ_LT: return rdef && pmr_cmp(aTHX_ rv, val) < 0; |
45 |
5 |
50 |
| case PDBQ_LT: return rdef && pmr_cmp(aTHX_ rv, val) < 0; |
30 |
15 |
45 |
|
| 250 |
30 |
▶ | case PDBQ_LE: return rdef && pmr_cmp(aTHX_ rv, val) <= 0; |
Branch: 2 branches
| Branch | True | False | Total |
| case PDBQ_LE: return rdef && pmr_cmp(aTHX_ rv, val) <= 0; |
25 |
5 |
30 |
| case PDBQ_LE: return rdef && pmr_cmp(aTHX_ rv, val) <= 0; |
7 |
18 |
25 |
|
| 251 |
30 |
▶ | case PDBQ_GT: return rdef && pmr_cmp(aTHX_ rv, val) > 0; |
Branch: 2 branches
| Branch | True | False | Total |
| case PDBQ_GT: return rdef && pmr_cmp(aTHX_ rv, val) > 0; |
25 |
5 |
30 |
| case PDBQ_GT: return rdef && pmr_cmp(aTHX_ rv, val) > 0; |
13 |
12 |
25 |
|
| 252 |
15 |
▶ | case PDBQ_GE: return rdef && pmr_cmp(aTHX_ rv, val) >= 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| case PDBQ_GE: return rdef && pmr_cmp(aTHX_ rv, val) >= 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
15 |
0 |
15 |
| case PDBQ_GE: return rdef && pmr_cmp(aTHX_ rv, val) >= 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
10 |
5 |
15 |
|
| 253 |
135 |
| case PDBQ_IN: |
| 254 |
|
| case PDBQ_NOT_IN: { |
| 255 |
135 |
| AV *list = (AV *)SvRV(val); |
| 256 |
135 |
| SSize_t i, n = av_len(list) + 1; |
| 257 |
135 |
| int found = 0, has_null = 0; |
| 258 |
135 |
▶ | if (n == 0) return op == PDBQ_NOT_IN; /* 1=0 / 1=1 */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (n == 0) return op == PDBQ_NOT_IN; /* 1=0 / 1=1 */ |
50 |
85 |
135 |
|
| 259 |
85 |
▶ | if (!rdef) return 0; /* NULL [NOT] IN (...) */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rdef) return 0; /* NULL [NOT] IN (...) */ |
15 |
70 |
85 |
|
| 260 |
151 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
114 |
37 |
151 |
|
| 261 |
114 |
| SV **e = av_fetch(list, i, 0); |
| 262 |
|
| /* |
| 263 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 264 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 265 |
114 |
▶ | if (!(e && *e && SvOK(*e))) { has_null = 1; continue; } |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(e && *e && SvOK(*e))) { has_null = 1; continue; } |
114 |
0 |
114 |
| if (!(e && *e && SvOK(*e))) { has_null = 1; continue; } |
114 |
0 |
114 |
| if (!(e && *e && SvOK(*e))) { has_null = 1; continue; } |
10 |
104 |
114 |
|
| 266 |
104 |
▶ | if (pmr_cmp(aTHX_ rv, *e) == 0) { found = 1; break; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (pmr_cmp(aTHX_ rv, *e) == 0) { found = 1; break; } |
33 |
71 |
104 |
|
| 267 |
|
| } |
| 268 |
70 |
▶ | if (op == PDBQ_IN) return found; |
Branch: 1 branch
| Branch | True | False | Total |
| if (op == PDBQ_IN) return found; |
30 |
40 |
70 |
|
| 269 |
40 |
▶ | return !found && !has_null; /* x NOT IN (.., NULL) */ |
Branch: 2 branches
| Branch | True | False | Total |
| return !found && !has_null; /* x NOT IN (.., NULL) */ |
20 |
20 |
40 |
| return !found && !has_null; /* x NOT IN (.., NULL) */ |
10 |
10 |
20 |
|
| 270 |
|
| } |
| 271 |
164 |
| case PDBQ_LIKE: |
| 272 |
|
| case PDBQ_STARTS_WITH: { |
| 273 |
|
| STRLEN sl, pl; |
| 274 |
|
| const U8 *s, *p; |
| 275 |
|
| /* |
| 276 |
|
| # uncoverable branch true |
| 277 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 278 |
164 |
▶ | if (!rdef) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rdef) return 0; |
0 |
164 |
164 |
|
| 279 |
164 |
▶ | s = (const U8 *)SvPV_const(rv, sl); |
Branch: 1 branch
| Branch | True | False | Total |
| s = (const U8 *)SvPV_const(rv, sl); |
164 |
0 |
164 |
|
| 280 |
164 |
| p = (const U8 *)SvPV_const(val, pl); |
| 281 |
164 |
▶ | if (op == PDBQ_STARTS_WITH) return sl >= pl && memEQ(s, p, pl); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (op == PDBQ_STARTS_WITH) return sl >= pl && memEQ(s, p, pl); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
59 |
105 |
164 |
| if (op == PDBQ_STARTS_WITH) return sl >= pl && memEQ(s, p, pl); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
59 |
0 |
59 |
| if (op == PDBQ_STARTS_WITH) return sl >= pl && memEQ(s, p, pl); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
13 |
46 |
59 |
|
| 282 |
105 |
| return pmr_like(s, s + sl, p, p + pl, SvUTF8(rv) ? 1 : 0); |
| 283 |
|
| } |
| 284 |
0 |
| default: return 0; /* # uncoverable statement */ |
| 285 |
|
| } |
| 286 |
|
| } |
| 287 |
|
| |
| 288 |
1040 |
| static int pmr_match(pTHX_ AV *terms, HV *row) { |
| 289 |
1040 |
| SSize_t i, n = av_len(terms) + 1; |
| 290 |
1300 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
743 |
557 |
1300 |
|
| 291 |
743 |
| AV *t = (AV *)SvRV(*av_fetch(terms, i, 0)); |
| 292 |
743 |
| SV *col = *av_fetch(t, 0, 0); |
| 293 |
743 |
| HE *he = hv_fetch_ent(row, col, 0, 0); |
| 294 |
743 |
▶ | if (!pmr_term_ok(aTHX_ (int)SvIV(*av_fetch(t, 1, 0)), /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!pmr_term_ok(aTHX_ (int)SvIV(*av_fetch(t, 1, 0)), /* # uncoverable condition right count:1 class:ignore_covered_err */ |
743 |
0 |
743 |
| if (!pmr_term_ok(aTHX_ (int)SvIV(*av_fetch(t, 1, 0)), /* # uncoverable condition right count:1 class:ignore_covered_err */ |
483 |
260 |
743 |
|
| 295 |
743 |
| he ? HeVAL(he) : NULL, *av_fetch(t, 2, 0))) |
| 296 |
483 |
| return 0; |
| 297 |
|
| } |
| 298 |
557 |
| return 1; |
| 299 |
|
| } |
| 300 |
|
| |
| 301 |
|
| /* ---- copies ------------------------------------------------------------------ |
| 302 |
|
| * |
| 303 |
|
| * A row handed out is the caller's to change, so it is copied all the way |
| 304 |
|
| * down: a JSON file's rows sit in a per-process cache, and a caller editing |
| 305 |
|
| * a nested hash must not edit the next caller's answer. */ |
| 306 |
|
| |
| 307 |
3718 |
| static SV *pmr_deep(pTHX_ SV *sv) { |
| 308 |
|
| /* |
| 309 |
|
| # uncoverable branch true |
| 310 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 311 |
3718 |
▶ | if (!sv) return newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) return newSV(0); |
0 |
3718 |
3718 |
|
| 312 |
3718 |
▶ | if (SvROK(sv) && !sv_isobject(sv)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(sv) && !sv_isobject(sv)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
887 |
2831 |
3718 |
| if (SvROK(sv) && !sv_isobject(sv)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
887 |
0 |
887 |
|
| 313 |
887 |
| SV *r = SvRV(sv); |
| 314 |
887 |
▶ | if (SvTYPE(r) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(r) == SVt_PVHV) { |
767 |
120 |
887 |
|
| 315 |
767 |
| HV *src = (HV *)r, *dst = newHV(); |
| 316 |
|
| HE *he; |
| 317 |
767 |
| hv_iterinit(src); |
| 318 |
3341 |
▶ | while ((he = hv_iternext(src))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(src))) |
2574 |
767 |
3341 |
|
| 319 |
2574 |
| (void)hv_store_ent(dst, hv_iterkeysv(he), |
| 320 |
|
| pmr_deep(aTHX_ HeVAL(he)), 0); |
| 321 |
767 |
| return newRV_noinc((SV *)dst); |
| 322 |
|
| } |
| 323 |
|
| /* |
| 324 |
|
| # uncoverable branch false |
| 325 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 326 |
120 |
▶ | if (SvTYPE(r) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(r) == SVt_PVAV) { |
120 |
0 |
120 |
|
| 327 |
120 |
| AV *src = (AV *)r, *dst = newAV(); |
| 328 |
120 |
| SSize_t i, n = av_len(src) + 1; |
| 329 |
120 |
| av_extend(dst, n > 0 ? n - 1 : 0); |
| 330 |
405 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
285 |
120 |
405 |
|
| 331 |
285 |
| SV **e = av_fetch(src, i, 0); |
| 332 |
285 |
▶ | av_push(dst, pmr_deep(aTHX_ e ? *e : NULL)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(dst, pmr_deep(aTHX_ e ? *e : NULL)); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
285 |
0 |
285 |
|
| 333 |
|
| } |
| 334 |
120 |
| return newRV_noinc((SV *)dst); |
| 335 |
|
| } |
| 336 |
|
| } |
| 337 |
2831 |
| return newSVsv(sv); |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
|
| /* ---- ordering ---------------------------------------------------------------- */ |
| 341 |
|
| |
| 342 |
|
| typedef struct { AV *cols; AV *desc; } pmr_spec; |
| 343 |
|
| typedef struct { HV *row; const pmr_spec *spec; } pmr_item; |
| 344 |
|
| |
| 345 |
508 |
| static int pmr_rowcmp(pTHX_ const pmr_spec *sp, HV *a, HV *b, AV *bvals) { |
| 346 |
508 |
| SSize_t i, n = av_len(sp->cols) + 1; |
| 347 |
534 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
523 |
11 |
534 |
|
| 348 |
523 |
| SV *c = *av_fetch(sp->cols, i, 0); |
| 349 |
523 |
| HE *ha = hv_fetch_ent(a, c, 0, 0); |
| 350 |
|
| SV *vb; |
| 351 |
|
| int r; |
| 352 |
523 |
▶ | if (bvals) { SV **e = av_fetch(bvals, i, 0); vb = e ? *e : NULL; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (bvals) { SV **e = av_fetch(bvals, i, 0); vb = e ? *e : NULL; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
53 |
470 |
523 |
| if (bvals) { SV **e = av_fetch(bvals, i, 0); vb = e ? *e : NULL; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
53 |
0 |
53 |
|
| 353 |
470 |
▶ | else { HE *hb = hv_fetch_ent(b, c, 0, 0); vb = hb ? HeVAL(hb) : NULL; } /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| else { HE *hb = hv_fetch_ent(b, c, 0, 0); vb = hb ? HeVAL(hb) : NULL; } /* # uncoverable condition right count:1 class:ignore_covered_err */ |
470 |
0 |
470 |
|
| 354 |
523 |
▶ | r = pmr_cmp(aTHX_ ha ? HeVAL(ha) : NULL, vb); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| r = pmr_cmp(aTHX_ ha ? HeVAL(ha) : NULL, vb); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
523 |
0 |
523 |
|
| 355 |
523 |
▶ | if (r) return SvIV(*av_fetch(sp->desc, i, 0)) ? -r : r; |
Branch: 2 branches
| Branch | True | False | Total |
| if (r) return SvIV(*av_fetch(sp->desc, i, 0)) ? -r : r; |
497 |
26 |
523 |
| if (r) return SvIV(*av_fetch(sp->desc, i, 0)) ? -r : r; |
42 |
455 |
497 |
|
| 356 |
|
| } |
| 357 |
11 |
| return 0; |
| 358 |
|
| } |
| 359 |
|
| |
| 360 |
465 |
| static int pmr_qsort_cmp(const void *x, const void *y) { |
| 361 |
|
| dTHX; |
| 362 |
465 |
| const pmr_item *a = (const pmr_item *)x, *b = (const pmr_item *)y; |
| 363 |
465 |
| return pmr_rowcmp(aTHX_ a->spec, a->row, b->row, NULL); |
| 364 |
|
| } |
| 365 |
|
| |
| 366 |
|
| /* ---- the contract over a row list -------------------------------------------- */ |
| 367 |
|
| |
| 368 |
1182 |
| static HV *pmr_self(pTHX_ SV *self, const char *cls) { |
| 369 |
1182 |
▶ | if (!(SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV)) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV)) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
1182 |
0 |
1182 |
| if (!(SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV)) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
1 |
1181 |
1182 |
|
| 370 |
1 |
| croak("%s: not a backend object", cls); |
| 371 |
1181 |
| return (HV *)SvRV(self); |
| 372 |
|
| } |
| 373 |
|
| |
| 374 |
453 |
| static HV *pmr_colset(pTHX_ HV *h) { |
| 375 |
453 |
| SV *c = pdbi_get(aTHX_ h, "col"); |
| 376 |
|
| /* |
| 377 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 378 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 379 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 380 |
453 |
▶ | return (c && SvROK(c) && SvTYPE(SvRV(c)) == SVt_PVHV) ? (HV *)SvRV(c) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (c && SvROK(c) && SvTYPE(SvRV(c)) == SVt_PVHV) ? (HV *)SvRV(c) : NULL; |
453 |
0 |
453 |
| return (c && SvROK(c) && SvTYPE(SvRV(c)) == SVt_PVHV) ? (HV *)SvRV(c) : NULL; |
453 |
0 |
453 |
| return (c && SvROK(c) && SvTYPE(SvRV(c)) == SVt_PVHV) ? (HV *)SvRV(c) : NULL; |
453 |
0 |
453 |
|
| 381 |
|
| } |
| 382 |
|
| |
| 383 |
|
| /* search(\%filter, \%opts) over `rows` (an AV of hashrefs): the page hash. */ |
| 384 |
216 |
| static SV *pmr_search(pTHX_ SV *self, AV *rows, SV *filter, SV *opts, |
| 385 |
|
| const char *cls) { |
| 386 |
216 |
| HV *h = pmr_self(aTHX_ self, cls); |
| 387 |
216 |
▶ | HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
216 |
0 |
216 |
| HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
216 |
0 |
216 |
|
| 388 |
432 |
▶ | ? (HV *)SvRV(filter) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(filter) : NULL; |
216 |
0 |
216 |
|
| 389 |
216 |
▶ | HV *o = (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| HV *o = (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) |
69 |
147 |
216 |
| HV *o = (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) |
69 |
0 |
69 |
|
| 390 |
432 |
▶ | ? (HV *)SvRV(opts) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(opts) : NULL; |
216 |
0 |
216 |
|
| 391 |
216 |
| SV *table = pdbi_get(aTHX_ h, "table"); |
| 392 |
216 |
| SV *pk = pdbi_get(aTHX_ h, "primary"); |
| 393 |
216 |
| HV *col = pmr_colset(aTHX_ h); |
| 394 |
216 |
▶ | SV *lim_sv = o ? pdbi_get(aTHX_ o, "limit") : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *lim_sv = o ? pdbi_get(aTHX_ o, "limit") : NULL; |
69 |
147 |
216 |
|
| 395 |
216 |
▶ | SV *after = o ? pdbi_get(aTHX_ o, "after") : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *after = o ? pdbi_get(aTHX_ o, "after") : NULL; |
69 |
147 |
216 |
|
| 396 |
216 |
▶ | SV *order = o ? pdbi_get(aTHX_ o, "order_by") : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *order = o ? pdbi_get(aTHX_ o, "order_by") : NULL; |
69 |
147 |
216 |
|
| 397 |
|
| IV limit; |
| 398 |
216 |
| AV *cols, *desc, *terms, *vals = NULL, *out; |
| 399 |
|
| int pk_only; |
| 400 |
|
| pmr_spec spec; |
| 401 |
|
| pmr_item *items; |
| 402 |
216 |
▶ | SSize_t i, n = rows ? av_len(rows) + 1 : 0, kept = 0, from = 0, taken; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, n = rows ? av_len(rows) + 1 : 0, kept = 0, from = 0, taken; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
216 |
0 |
216 |
|
| 403 |
|
| |
| 404 |
216 |
| pdbq_check_opts(aTHX_ o, cls); |
| 405 |
211 |
▶ | limit = (lim_sv && SvOK(lim_sv)) ? SvIV(lim_sv) : 20; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| limit = (lim_sv && SvOK(lim_sv)) ? SvIV(lim_sv) : 20; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
27 |
184 |
211 |
| limit = (lim_sv && SvOK(lim_sv)) ? SvIV(lim_sv) : 20; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
27 |
0 |
27 |
|
| 406 |
|
| /* |
| 407 |
|
| # uncoverable branch true |
| 408 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 409 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 410 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 411 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 412 |
211 |
▶ | if (lim_sv && SvOK(lim_sv) && SvNV(lim_sv) >= (NV)IV_MAX) limit = IV_MAX - 1; |
Branch: 3 branches
| Branch | True | False | Total |
| if (lim_sv && SvOK(lim_sv) && SvNV(lim_sv) >= (NV)IV_MAX) limit = IV_MAX - 1; |
27 |
184 |
211 |
| if (lim_sv && SvOK(lim_sv) && SvNV(lim_sv) >= (NV)IV_MAX) limit = IV_MAX - 1; |
27 |
0 |
27 |
| if (lim_sv && SvOK(lim_sv) && SvNV(lim_sv) >= (NV)IV_MAX) limit = IV_MAX - 1; |
0 |
27 |
27 |
|
| 413 |
211 |
▶ | if (limit < 1) limit = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (limit < 1) limit = 1; |
5 |
206 |
211 |
|
| 414 |
211 |
| terms = pmr_compile(aTHX_ col, table, f, cls); |
| 415 |
177 |
| pdbq_order(aTHX_ col, table, pk, order, cls, &cols, &desc, &pk_only); |
| 416 |
|
| /* |
| 417 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 418 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 419 |
177 |
▶ | if (after && SvOK(after) && SvCUR(after)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (after && SvOK(after) && SvCUR(after)) { |
22 |
155 |
177 |
| if (after && SvOK(after) && SvCUR(after)) { |
22 |
0 |
22 |
| if (after && SvOK(after) && SvCUR(after)) { |
22 |
0 |
22 |
|
| 420 |
22 |
▶ | if (av_len(cols) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(cols) < 0) |
1 |
21 |
22 |
|
| 421 |
1 |
| croak("%s: pagination needs a primary key or an order_by", cls); |
| 422 |
21 |
| vals = pdbq_decode_token(aTHX_ after, cols, desc, pk_only, cls); |
| 423 |
|
| } |
| 424 |
|
| |
| 425 |
166 |
▶ | Newx(items, n > 0 ? n : 1, pmr_item); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| Newx(items, n > 0 ? n : 1, pmr_item); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
166 |
0 |
166 |
| Newx(items, n > 0 ? n : 1, pmr_item); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
0 |
166 |
166 |
| Newx(items, n > 0 ? n : 1, pmr_item); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
166 |
0 |
166 |
|
| 426 |
166 |
| SAVEFREEPV(items); |
| 427 |
166 |
| spec.cols = cols; |
| 428 |
166 |
| spec.desc = desc; |
| 429 |
977 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
811 |
166 |
977 |
|
| 430 |
811 |
| SV **e = av_fetch(rows, i, 0); |
| 431 |
|
| HV *r; |
| 432 |
|
| /* |
| 433 |
|
| # uncoverable branch true |
| 434 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 435 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 436 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 437 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 438 |
811 |
▶ | if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
811 |
0 |
811 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
811 |
0 |
811 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
811 |
0 |
811 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
0 |
811 |
811 |
|
| 439 |
811 |
| r = (HV *)SvRV(*e); |
| 440 |
811 |
▶ | if (!pmr_match(aTHX_ terms, r)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pmr_match(aTHX_ terms, r)) continue; |
345 |
466 |
811 |
|
| 441 |
466 |
| items[kept].row = r; |
| 442 |
466 |
| items[kept].spec = &spec; |
| 443 |
466 |
| kept++; |
| 444 |
|
| } |
| 445 |
166 |
▶ | if (kept > 1) qsort(items, (size_t)kept, sizeof *items, pmr_qsort_cmp); |
Branch: 1 branch
| Branch | True | False | Total |
| if (kept > 1) qsort(items, (size_t)kept, sizeof *items, pmr_qsort_cmp); |
112 |
54 |
166 |
|
| 446 |
166 |
▶ | if (vals) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vals) |
11 |
155 |
166 |
|
| 447 |
11 |
| while (from < kept |
| 448 |
43 |
▶ | && pmr_rowcmp(aTHX_ &spec, items[from].row, NULL, vals) <= 0) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| && pmr_rowcmp(aTHX_ &spec, items[from].row, NULL, vals) <= 0) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
43 |
0 |
43 |
| && pmr_rowcmp(aTHX_ &spec, items[from].row, NULL, vals) <= 0) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
32 |
11 |
43 |
|
| 449 |
32 |
| from++; |
| 450 |
|
| |
| 451 |
166 |
| out = newAV(); |
| 452 |
564 |
▶ | for (taken = 0, i = from; i < kept && taken <= limit; i++, taken++) |
Branch: 2 branches
| Branch | True | False | Total |
| for (taken = 0, i = from; i < kept && taken <= limit; i++, taken++) |
414 |
150 |
564 |
| for (taken = 0, i = from; i < kept && taken <= limit; i++, taken++) |
398 |
16 |
414 |
|
| 453 |
398 |
| av_push(out, pmr_deep(aTHX_ sv_2mortal(newRV_inc((SV *)items[i].row)))); |
| 454 |
166 |
| return pdbq_page(aTHX_ newRV_noinc((SV *)out), limit, cols, desc, pk_only); |
| 455 |
|
| } |
| 456 |
|
| |
| 457 |
40 |
| static IV pmr_count(pTHX_ SV *self, AV *rows, SV *filter, const char *cls) { |
| 458 |
40 |
| HV *h = pmr_self(aTHX_ self, cls); |
| 459 |
40 |
▶ | HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
40 |
0 |
40 |
| HV *f = (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) |
40 |
0 |
40 |
|
| 460 |
80 |
▶ | ? (HV *)SvRV(filter) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(filter) : NULL; |
40 |
0 |
40 |
|
| 461 |
40 |
| AV *terms = pmr_compile(aTHX_ pmr_colset(aTHX_ h), |
| 462 |
|
| pdbi_get(aTHX_ h, "table"), f, cls); |
| 463 |
40 |
▶ | SSize_t i, n = rows ? av_len(rows) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, n = rows ? av_len(rows) + 1 : 0; |
12 |
28 |
40 |
|
| 464 |
40 |
| IV c = 0; |
| 465 |
93 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
53 |
40 |
93 |
|
| 466 |
53 |
| SV **e = av_fetch(rows, i, 0); |
| 467 |
|
| /* |
| 468 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 469 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 470 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 471 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 472 |
53 |
▶ | if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
Branch: 4 branches
| Branch | True | False | Total |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
53 |
0 |
53 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
53 |
0 |
53 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
53 |
0 |
53 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
53 |
0 |
53 |
|
| 473 |
53 |
▶ | && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) |
Branch: 1 branch
| Branch | True | False | Total |
| && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) |
51 |
2 |
53 |
|
| 474 |
51 |
| c++; |
| 475 |
|
| } |
| 476 |
40 |
| return c; |
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
|
| /* get(%key): the first row whose key columns equal the given values, copied, |
| 480 |
|
| * or undef. The keys are checked against the fields as DBI checks them. */ |
| 481 |
41 |
| static SV *pmr_get(pTHX_ SV *self, AV *rows, SV **st, I32 items, |
| 482 |
|
| const char *cls) { |
| 483 |
|
| HV *key; |
| 484 |
41 |
| AV *keys = pdbi_key_args(aTHX_ st, items, &key, "get", cls); |
| 485 |
|
| AV *terms; |
| 486 |
41 |
▶ | SSize_t i, n = rows ? av_len(rows) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, n = rows ? av_len(rows) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
41 |
0 |
41 |
|
| 487 |
41 |
| pdbq_check_keys(aTHX_ self, keys, cls, "get"); |
| 488 |
36 |
| terms = pmr_compile(aTHX_ NULL, NULL, key, cls); |
| 489 |
132 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
126 |
6 |
132 |
|
| 490 |
126 |
| SV **e = av_fetch(rows, i, 0); |
| 491 |
|
| /* |
| 492 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 493 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 494 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 495 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 496 |
126 |
▶ | if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
Branch: 4 branches
| Branch | True | False | Total |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
126 |
0 |
126 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
126 |
0 |
126 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
126 |
0 |
126 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
126 |
0 |
126 |
|
| 497 |
126 |
▶ | && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) |
Branch: 1 branch
| Branch | True | False | Total |
| && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) |
30 |
96 |
126 |
|
| 498 |
30 |
| return pmr_deep(aTHX_ *e); |
| 499 |
|
| } |
| 500 |
6 |
| return newSV(0); |
| 501 |
|
| } |
| 502 |
|
| |
| 503 |
|
| /* ---- Punk::Model::JSONFile ---------------------------------------------------- |
| 504 |
|
| * |
| 505 |
|
| * The file is a JSON object and a model's `table` names the array of rows in |
| 506 |
|
| * it, so one file can hold several tables (and values beside them, which |
| 507 |
|
| * `document` hands back). Read through the File::Raw::JSON ABI and kept per |
| 508 |
|
| * process until the file changes - its inode, size or mtime, because a write |
| 509 |
|
| * renames a new file into place and can land in the same second as the read |
| 510 |
|
| * before it. */ |
| 511 |
|
| |
| 512 |
|
| #define PMJ "Punk::Model::JSONFile" |
| 513 |
|
| |
| 514 |
|
| static HV *PMJ_CACHE = NULL; /* file => [ stamp, doc-or-undef ] */ |
| 515 |
|
| |
| 516 |
511 |
| static SV *pmj_file(pTHX_ HV *h) { |
| 517 |
511 |
| SV *o = pdbi_get(aTHX_ h, "opts"); |
| 518 |
|
| /* |
| 519 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 520 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 521 |
511 |
▶ | SV *f = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "file") : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *f = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "file") : NULL; |
511 |
0 |
511 |
| SV *f = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "file") : NULL; |
511 |
0 |
511 |
|
| 522 |
|
| /* |
| 523 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 524 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 525 |
511 |
▶ | if (!(f && SvOK(f) && SvCUR(f))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(f && SvOK(f) && SvCUR(f))) |
506 |
5 |
511 |
| if (!(f && SvOK(f) && SvCUR(f))) |
506 |
0 |
506 |
| if (!(f && SvOK(f) && SvCUR(f))) |
0 |
506 |
506 |
|
| 526 |
5 |
| croak(PMJ ": the database needs a `file` (database name => " |
| 527 |
|
| "{ backend => '" PMJ "', file => 'data.json' })"); |
| 528 |
506 |
| return f; |
| 529 |
|
| } |
| 530 |
|
| |
| 531 |
|
| /* The bytes of the file decoded, or NULL with *err set to why. Owned. */ |
| 532 |
188 |
| static SV *pmj_decode_file(pTHX_ const char *path, SV **err) { |
| 533 |
188 |
| SV *bytes = pmd_slurp(aTHX_ path); |
| 534 |
188 |
| SV *doc = NULL; |
| 535 |
188 |
| *err = NULL; |
| 536 |
|
| /* |
| 537 |
|
| # uncoverable branch true |
| 538 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 539 |
188 |
▶ | if (!bytes) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!bytes) return NULL; |
0 |
188 |
188 |
|
| 540 |
|
| /* the backend is XS registered at boot, so its .pm - and with it the |
| 541 |
|
| * module the decode is called in - may never have been required */ |
| 542 |
188 |
| (void)pk_require_once(aTHX_ "File::Raw::JSON", TRUE); |
| 543 |
|
| { |
| 544 |
188 |
| dSP; |
| 545 |
|
| int count; |
| 546 |
188 |
| ENTER; SAVETMPS; |
| 547 |
188 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); PUSHs(bytes); PUTBACK; |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(bytes); PUTBACK; |
0 |
188 |
188 |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(bytes); PUTBACK; |
0 |
188 |
188 |
|
| 548 |
188 |
| count = call_pv("File::Raw::JSON::file_json_decode", G_SCALAR | G_EVAL); |
| 549 |
188 |
| SPAGAIN; |
| 550 |
188 |
▶ | doc = (count > 0) ? newSVsv(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| doc = (count > 0) ? newSVsv(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
188 |
0 |
188 |
|
| 551 |
188 |
| PUTBACK; |
| 552 |
188 |
▶ | if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
188 |
0 |
188 |
| if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
11 |
177 |
188 |
|
| 553 |
11 |
▶ | *err = newSVsv(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| *err = newSVsv(ERRSV); |
11 |
0 |
11 |
|
| 554 |
|
| /* |
| 555 |
|
| # uncoverable branch false |
| 556 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 557 |
11 |
▶ | if (doc) { SvREFCNT_dec(doc); doc = NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (doc) { SvREFCNT_dec(doc); doc = NULL; } |
11 |
0 |
11 |
|
| 558 |
|
| } |
| 559 |
188 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
188 |
0 |
188 |
|
| 560 |
|
| } |
| 561 |
188 |
▶ | if (doc && !(SvROK(doc) && SvTYPE(SvRV(doc)) == SVt_PVHV)) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (doc && !(SvROK(doc) && SvTYPE(SvRV(doc)) == SVt_PVHV)) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
177 |
11 |
188 |
| if (doc && !(SvROK(doc) && SvTYPE(SvRV(doc)) == SVt_PVHV)) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
177 |
0 |
177 |
| if (doc && !(SvROK(doc) && SvTYPE(SvRV(doc)) == SVt_PVHV)) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
1 |
176 |
177 |
|
| 562 |
1 |
| SvREFCNT_dec(doc); |
| 563 |
1 |
| doc = NULL; |
| 564 |
1 |
| *err = newSVpvs("it is not a JSON object\n"); |
| 565 |
|
| } |
| 566 |
188 |
| return doc; |
| 567 |
|
| } |
| 568 |
|
| |
| 569 |
|
| /* The decoded file, borrowed from the cache, or NULL (no file, or a broken |
| 570 |
|
| * one - which warns once per version of it). */ |
| 571 |
305 |
| static HV *pmj_document(pTHX_ SV *self) { |
| 572 |
305 |
| HV *h = pmr_self(aTHX_ self, PMJ); |
| 573 |
305 |
| SV *file = pmj_file(aTHX_ h); |
| 574 |
305 |
| const char *path = SvPV_nolen(file); |
| 575 |
|
| Stat_t st; |
| 576 |
|
| SV *stamp; |
| 577 |
|
| HE *he; |
| 578 |
305 |
▶ | if (!PMJ_CACHE) PMJ_CACHE = newHV(); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PMJ_CACHE) PMJ_CACHE = newHV(); |
7 |
298 |
305 |
|
| 579 |
305 |
▶ | if (PerlLIO_stat(path, &st) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PerlLIO_stat(path, &st) < 0) { |
11 |
294 |
305 |
|
| 580 |
11 |
| (void)hv_delete_ent(PMJ_CACHE, file, G_DISCARD, 0); |
| 581 |
11 |
| return NULL; |
| 582 |
|
| } |
| 583 |
294 |
| stamp = sv_2mortal(newSVpvf("%" UVuf ":%" IVdf ":%" IVdf, |
| 584 |
|
| (UV)st.st_ino, (IV)st.st_size, (IV)st.st_mtime)); |
| 585 |
294 |
| he = hv_fetch_ent(PMJ_CACHE, file, 0, 0); |
| 586 |
294 |
▶ | if (he && SvROK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (he && SvROK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
281 |
13 |
294 |
| if (he && SvROK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
281 |
0 |
281 |
|
| 587 |
281 |
| AV *slot = (AV *)SvRV(HeVAL(he)); |
| 588 |
281 |
▶ | if (sv_eq(*av_fetch(slot, 0, 0), stamp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_eq(*av_fetch(slot, 0, 0), stamp)) { |
266 |
15 |
281 |
|
| 589 |
266 |
| SV *d = *av_fetch(slot, 1, 0); |
| 590 |
266 |
▶ | return SvROK(d) ? (HV *)SvRV(d) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return SvROK(d) ? (HV *)SvRV(d) : NULL; |
251 |
15 |
266 |
|
| 591 |
|
| } |
| 592 |
|
| } |
| 593 |
|
| { |
| 594 |
28 |
| SV *err = NULL; |
| 595 |
28 |
| SV *doc = pmj_decode_file(aTHX_ path, &err); |
| 596 |
28 |
| AV *slot = newAV(); |
| 597 |
28 |
| av_push(slot, newSVsv(stamp)); |
| 598 |
28 |
▶ | av_push(slot, doc ? doc : newSV(0)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(slot, doc ? doc : newSV(0)); |
7 |
21 |
28 |
|
| 599 |
28 |
| (void)hv_store_ent(PMJ_CACHE, file, newRV_noinc((SV *)slot), 0); |
| 600 |
28 |
▶ | if (!doc) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!doc) { |
7 |
21 |
28 |
|
| 601 |
14 |
▶ | warn(PMJ ": %s is unusable, so it has no rows: %s", path, |
Branch: 1 branch
| Branch | True | False | Total |
| warn(PMJ ": %s is unusable, so it has no rows: %s", path, |
7 |
0 |
7 |
|
| 602 |
|
| err ? SvPV_nolen(err) : "it could not be read\n"); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
| 603 |
|
| /* |
| 604 |
|
| # uncoverable branch false |
| 605 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 606 |
7 |
▶ | if (err) SvREFCNT_dec(err); |
Branch: 1 branch
| Branch | True | False | Total |
| if (err) SvREFCNT_dec(err); |
7 |
0 |
7 |
|
| 607 |
7 |
| return NULL; |
| 608 |
|
| } |
| 609 |
21 |
| return (HV *)SvRV(doc); |
| 610 |
|
| } |
| 611 |
|
| } |
| 612 |
|
| |
| 613 |
|
| /* The table's rows, borrowed, or NULL. */ |
| 614 |
285 |
| static AV *pmj_rows(pTHX_ SV *self) { |
| 615 |
285 |
| HV *doc = pmj_document(aTHX_ self); |
| 616 |
|
| SV *t, *rows; |
| 617 |
285 |
▶ | if (!doc) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!doc) return NULL; |
28 |
257 |
285 |
|
| 618 |
257 |
| t = pdbi_get(aTHX_ pmr_self(aTHX_ self, PMJ), "table"); |
| 619 |
257 |
| rows = pdbi_get(aTHX_ doc, SvPV_nolen(t)); |
| 620 |
257 |
▶ | return (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| return (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) |
257 |
0 |
257 |
| return (rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV) |
257 |
0 |
257 |
|
| 621 |
514 |
▶ | ? (AV *)SvRV(rows) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (AV *)SvRV(rows) : NULL; |
257 |
0 |
257 |
|
| 622 |
|
| } |
| 623 |
|
| |
| 624 |
|
| /* ---- writing ------------------------------------------------------------------ |
| 625 |
|
| * |
| 626 |
|
| * Every write is read-modify-write of the whole file under an exclusive lock |
| 627 |
|
| * on `<file>.lock` (so two workers cannot lose each other's change), from a |
| 628 |
|
| * FRESH read rather than the cache, encoded pretty with sorted keys (so the |
| 629 |
|
| * file diffs well), written to a temporary file and renamed over the old one |
| 630 |
|
| * (so a reader never sees half of it). */ |
| 631 |
|
| |
| 632 |
|
| typedef struct { int fd; } pmj_lock; |
| 633 |
|
| |
| 634 |
|
| /* The lock is fcntl's on every POSIX system and flock only on Windows, where |
| 635 |
|
| * perl emulates flock and there is no F_SETLKW. Solaris has no flock(2), so |
| 636 |
|
| * HAS_FLOCK is undefined there and a flock-only lock compiled to nothing: four |
| 637 |
|
| * forked writers kept about half of 100 rows (CPAN Testers, Punk 0.66). An |
| 638 |
|
| * fcntl lock belongs to the process and goes when it closes the descriptor, |
| 639 |
|
| * which is all this needs: the lock file is opened here and nowhere else. */ |
| 640 |
|
| #if defined(F_SETLKW) && !defined(WIN32) |
| 641 |
|
| # define PMJ_LOCK_FCNTL |
| 642 |
|
| #elif defined(HAS_FLOCK) && defined(LOCK_EX) |
| 643 |
|
| # define PMJ_LOCK_FLOCK |
| 644 |
|
| #endif |
| 645 |
|
| |
| 646 |
166 |
| static void pmj_lock_take(pTHX_ const char *path, pmj_lock *l) { |
| 647 |
166 |
| SV *lp = sv_2mortal(newSVpvf("%s.lock", path)); |
| 648 |
166 |
| l->fd = PerlLIO_open3(SvPV_nolen(lp), O_RDWR | O_CREAT, 0644); |
| 649 |
|
| /* |
| 650 |
|
| # uncoverable branch true class:ignore_covered_err |
| 651 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 652 |
166 |
▶ | if (l->fd < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (l->fd < 0) |
1 |
165 |
166 |
|
| 653 |
2 |
| croak(PMJ ": cannot open %s: %s", SvPV_nolen(lp), Strerror(errno)); /* # uncoverable statement class:ignore_covered_err */ |
| 654 |
|
| #if defined(PMJ_LOCK_FCNTL) |
| 655 |
|
| { |
| 656 |
|
| struct flock fl; |
| 657 |
165 |
| Zero(&fl, 1, struct flock); |
| 658 |
165 |
| fl.l_type = F_WRLCK; |
| 659 |
165 |
| fl.l_whence = SEEK_SET; |
| 660 |
|
| /* |
| 661 |
|
| # uncoverable branch true |
| 662 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 663 |
165 |
▶ | while (fcntl(l->fd, F_SETLKW, &fl) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (fcntl(l->fd, F_SETLKW, &fl) < 0) { |
0 |
165 |
165 |
|
| 664 |
|
| /* |
| 665 |
|
| # uncoverable statement |
| 666 |
|
| # uncoverable branch true |
| 667 |
|
| # uncoverable branch false |
| 668 |
|
| # uncoverable condition left count:1 |
| 669 |
|
| # uncoverable condition right count:1 */ |
| 670 |
0 |
▶ | if (errno == EINTR) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (errno == EINTR) continue; |
0 |
0 |
0 |
|
| 671 |
0 |
| PerlLIO_close(l->fd); /* # uncoverable statement */ |
| 672 |
0 |
| croak(PMJ ": cannot lock %s: %s", SvPV_nolen(lp), Strerror(errno)); /* # uncoverable statement */ |
| 673 |
|
| } |
| 674 |
|
| } |
| 675 |
|
| #elif defined(PMJ_LOCK_FLOCK) |
| 676 |
|
| while (flock(l->fd, LOCK_EX) < 0) { |
| 677 |
|
| if (errno == EINTR) continue; |
| 678 |
|
| PerlLIO_close(l->fd); |
| 679 |
|
| croak(PMJ ": cannot lock %s: %s", SvPV_nolen(lp), Strerror(errno)); |
| 680 |
|
| } |
| 681 |
|
| #else |
| 682 |
|
| PerlLIO_close(l->fd); |
| 683 |
|
| croak(PMJ ": no file locking on this system, so %s cannot be written " |
| 684 |
|
| "safely", path); |
| 685 |
|
| #endif |
| 686 |
165 |
| } |
| 687 |
|
| |
| 688 |
166 |
| static void pmj_lock_drop(pmj_lock *l) { |
| 689 |
|
| /* |
| 690 |
|
| # uncoverable branch false class:ignore_covered_err |
| 691 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 692 |
166 |
▶ | if (l->fd >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (l->fd >= 0) { |
165 |
1 |
166 |
|
| 693 |
|
| #if defined(PMJ_LOCK_FLOCK) |
| 694 |
|
| (void)flock(l->fd, LOCK_UN); |
| 695 |
|
| #endif |
| 696 |
165 |
| PerlLIO_close(l->fd); |
| 697 |
165 |
| l->fd = -1; |
| 698 |
|
| } |
| 699 |
166 |
| } |
| 700 |
|
| |
| 701 |
|
| /* The lock, held until the enclosing LEAVE - on a croak as much as on a |
| 702 |
|
| * return, because the save stack unwinds either way. Call between ENTER and |
| 703 |
|
| * LEAVE. */ |
| 704 |
166 |
| static void pmj_unlock_cb(pTHX_ void *p) { |
| 705 |
166 |
| pmj_lock *l = (pmj_lock *)p; |
| 706 |
|
| PERL_UNUSED_CONTEXT; |
| 707 |
166 |
| pmj_lock_drop(l); |
| 708 |
166 |
| Safefree(l); |
| 709 |
166 |
| } |
| 710 |
|
| |
| 711 |
166 |
| static void pmj_lock_scoped(pTHX_ const char *path) { |
| 712 |
|
| pmj_lock *l; |
| 713 |
166 |
| Newx(l, 1, pmj_lock); |
| 714 |
166 |
| l->fd = -1; |
| 715 |
166 |
| SAVEDESTRUCTOR_X(pmj_unlock_cb, l); |
| 716 |
166 |
| pmj_lock_take(aTHX_ path, l); |
| 717 |
165 |
| } |
| 718 |
|
| |
| 719 |
|
| /* Write `doc` to `path` atomically. Croaks on failure (the old file stays). */ |
| 720 |
140 |
| static void pmj_write(pTHX_ const char *path, HV *doc) { |
| 721 |
|
| frj_opts o; |
| 722 |
|
| SV *json, *tmp; |
| 723 |
|
| PerlIO *fp; |
| 724 |
|
| STRLEN jl; |
| 725 |
|
| const char *jp; |
| 726 |
140 |
| const frj_abi *frj = punk_frj(aTHX); |
| 727 |
140 |
| frj->opts_init(&o); |
| 728 |
140 |
| o.pretty = 1; |
| 729 |
140 |
| o.sort_keys = 1; |
| 730 |
140 |
| json = sv_2mortal(frj->encode(aTHX_ sv_2mortal(newRV_inc((SV *)doc)), &o)); |
| 731 |
140 |
| jp = SvPV_const(json, jl); |
| 732 |
140 |
| tmp = sv_2mortal(newSVpvf("%s.tmp.%" IVdf, path, (IV)PerlProc_getpid())); |
| 733 |
140 |
| fp = PerlIO_open(SvPV_nolen(tmp), "wb"); |
| 734 |
|
| /* |
| 735 |
|
| # uncoverable branch true |
| 736 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 737 |
140 |
▶ | if (!fp) croak(PMJ ": cannot write %s: %s", SvPV_nolen(tmp), Strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fp) croak(PMJ ": cannot write %s: %s", SvPV_nolen(tmp), Strerror(errno)); |
0 |
140 |
140 |
|
| 738 |
|
| /* |
| 739 |
|
| # uncoverable branch true |
| 740 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 741 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 742 |
140 |
▶ | if (PerlIO_write(fp, jp, jl) != (SSize_t)jl || PerlIO_write(fp, "\n", 1) != 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (PerlIO_write(fp, jp, jl) != (SSize_t)jl || PerlIO_write(fp, "\n", 1) != 1) { |
140 |
0 |
140 |
| if (PerlIO_write(fp, jp, jl) != (SSize_t)jl || PerlIO_write(fp, "\n", 1) != 1) { |
0 |
140 |
140 |
|
| 743 |
0 |
| PerlIO_close(fp); /* # uncoverable statement */ |
| 744 |
0 |
| (void)PerlLIO_unlink(SvPV_nolen(tmp)); /* # uncoverable statement */ |
| 745 |
0 |
| croak(PMJ ": cannot write %s: %s", SvPV_nolen(tmp), Strerror(errno)); /* # uncoverable statement */ |
| 746 |
|
| } |
| 747 |
|
| /* |
| 748 |
|
| # uncoverable branch true |
| 749 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 750 |
140 |
▶ | if (PerlIO_close(fp) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PerlIO_close(fp) != 0) { |
0 |
140 |
140 |
|
| 751 |
0 |
| (void)PerlLIO_unlink(SvPV_nolen(tmp)); /* # uncoverable statement */ |
| 752 |
0 |
| croak(PMJ ": cannot write %s: %s", SvPV_nolen(tmp), Strerror(errno)); /* # uncoverable statement */ |
| 753 |
|
| } |
| 754 |
|
| /* |
| 755 |
|
| # uncoverable branch true |
| 756 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 757 |
140 |
▶ | if (PerlLIO_rename(SvPV_nolen(tmp), path) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PerlLIO_rename(SvPV_nolen(tmp), path) != 0) { |
0 |
140 |
140 |
|
| 758 |
0 |
| int e = errno; /* # uncoverable statement */ |
| 759 |
0 |
| (void)PerlLIO_unlink(SvPV_nolen(tmp)); /* # uncoverable statement */ |
| 760 |
0 |
| croak(PMJ ": cannot replace %s: %s", path, Strerror(e)); /* # uncoverable statement */ |
| 761 |
|
| } |
| 762 |
140 |
| } |
| 763 |
|
| |
| 764 |
|
| /* The file as it is now, for a write: decoded fresh (never the cache), or a |
| 765 |
|
| * new empty object when there is no file. Croaks on a broken file rather |
| 766 |
|
| * than writing over what somebody may still want. Mortal HV. The table's |
| 767 |
|
| * array is created when missing; *rows_out points at it. */ |
| 768 |
165 |
| static HV *pmj_fresh(pTHX_ SV *self, const char *path, AV **rows_out) { |
| 769 |
165 |
| HV *h = pmr_self(aTHX_ self, PMJ); |
| 770 |
165 |
| SV *t = pdbi_get(aTHX_ h, "table"); |
| 771 |
|
| Stat_t st; |
| 772 |
|
| HV *doc; |
| 773 |
|
| SV *rows; |
| 774 |
165 |
▶ | if (PerlLIO_stat(path, &st) < 0) doc = (HV *)sv_2mortal((SV *)newHV()); |
Branch: 1 branch
| Branch | True | False | Total |
| if (PerlLIO_stat(path, &st) < 0) doc = (HV *)sv_2mortal((SV *)newHV()); |
5 |
160 |
165 |
|
| 775 |
|
| else { |
| 776 |
160 |
| SV *err = NULL; |
| 777 |
160 |
| SV *d = pmj_decode_file(aTHX_ path, &err); |
| 778 |
160 |
▶ | if (!d) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!d) { |
5 |
155 |
160 |
|
| 779 |
5 |
▶ | SV *why = sv_2mortal(err ? err : newSVpvs("it could not be read\n")); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *why = sv_2mortal(err ? err : newSVpvs("it could not be read\n")); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
5 |
5 |
|
| 780 |
5 |
| croak(PMJ ": %s is unusable, so nothing was written: %s", path, |
| 781 |
|
| SvPV_nolen(why)); |
| 782 |
|
| } |
| 783 |
155 |
| sv_2mortal(d); |
| 784 |
155 |
| doc = (HV *)SvRV(d); |
| 785 |
|
| } |
| 786 |
160 |
| rows = pdbi_get(aTHX_ doc, SvPV_nolen(t)); |
| 787 |
|
| /* |
| 788 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 789 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 790 |
160 |
▶ | if (!(rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV)) { |
155 |
5 |
160 |
| if (!(rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV)) { |
155 |
0 |
155 |
| if (!(rows && SvROK(rows) && SvTYPE(SvRV(rows)) == SVt_PVAV)) { |
0 |
155 |
155 |
|
| 791 |
5 |
| AV *a = newAV(); |
| 792 |
5 |
| (void)hv_store_ent(doc, t, newRV_noinc((SV *)a), 0); |
| 793 |
5 |
| *rows_out = a; |
| 794 |
|
| } |
| 795 |
155 |
| else *rows_out = (AV *)SvRV(rows); |
| 796 |
160 |
| return doc; |
| 797 |
|
| } |
| 798 |
|
| |
| 799 |
|
| /* The known, defined columns of `data`, as a fresh HV. */ |
| 800 |
156 |
| static HV *pmj_known(pTHX_ HV *col, HV *d, int keep_undef) { |
| 801 |
156 |
| HV *out = newHV(); |
| 802 |
|
| HE *he; |
| 803 |
|
| /* |
| 804 |
|
| # uncoverable branch true |
| 805 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 806 |
156 |
▶ | if (!d) return out; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!d) return out; |
0 |
156 |
156 |
|
| 807 |
156 |
| hv_iterinit(d); |
| 808 |
462 |
▶ | while ((he = hv_iternext(d))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(d))) { |
306 |
156 |
462 |
|
| 809 |
306 |
| SV *k = hv_iterkeysv(he); |
| 810 |
306 |
| SV *v = HeVAL(he); |
| 811 |
|
| /* |
| 812 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 813 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 814 |
306 |
▶ | if (col && HvUSEDKEYS(col) && !hv_exists_ent(col, k, 0)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (col && HvUSEDKEYS(col) && !hv_exists_ent(col, k, 0)) continue; |
306 |
0 |
306 |
| if (col && HvUSEDKEYS(col) && !hv_exists_ent(col, k, 0)) continue; |
0 |
306 |
306 |
| if (col && HvUSEDKEYS(col) && !hv_exists_ent(col, k, 0)) continue; |
306 |
0 |
306 |
| if (col && HvUSEDKEYS(col) && !hv_exists_ent(col, k, 0)) continue; |
15 |
291 |
306 |
|
| 815 |
291 |
▶ | if (!keep_undef && !SvOK(v)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!keep_undef && !SvOK(v)) continue; |
256 |
35 |
291 |
| if (!keep_undef && !SvOK(v)) continue; |
5 |
251 |
256 |
|
| 816 |
286 |
| (void)hv_store_ent(out, k, pmr_deep(aTHX_ v), 0); |
| 817 |
|
| } |
| 818 |
156 |
| return out; |
| 819 |
|
| } |
| 820 |
|
| |
| 821 |
|
| /* The index of the row whose `pk` equals `id`, or -1. */ |
| 822 |
125 |
| static SSize_t pmj_find(pTHX_ AV *rows, SV *pk, SV *id) { |
| 823 |
125 |
| SSize_t i, n = av_len(rows) + 1; |
| 824 |
5125 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
5015 |
110 |
5125 |
|
| 825 |
5015 |
| SV **e = av_fetch(rows, i, 0); |
| 826 |
|
| HE *he; |
| 827 |
|
| /* |
| 828 |
|
| # uncoverable branch true |
| 829 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 830 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 831 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 832 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 833 |
5015 |
▶ | if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
5015 |
0 |
5015 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
5015 |
0 |
5015 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
5015 |
0 |
5015 |
| if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue; |
0 |
5015 |
5015 |
|
| 834 |
5015 |
| he = hv_fetch_ent((HV *)SvRV(*e), pk, 0, 0); |
| 835 |
|
| /* |
| 836 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 837 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 838 |
5015 |
▶ | if (he && SvOK(HeVAL(he)) && pmr_cmp(aTHX_ HeVAL(he), id) == 0) return i; |
Branch: 3 branches
| Branch | True | False | Total |
| if (he && SvOK(HeVAL(he)) && pmr_cmp(aTHX_ HeVAL(he), id) == 0) return i; |
5015 |
0 |
5015 |
| if (he && SvOK(HeVAL(he)) && pmr_cmp(aTHX_ HeVAL(he), id) == 0) return i; |
5015 |
0 |
5015 |
| if (he && SvOK(HeVAL(he)) && pmr_cmp(aTHX_ HeVAL(he), id) == 0) return i; |
15 |
5000 |
5015 |
|
| 839 |
|
| } |
| 840 |
110 |
| return -1; |
| 841 |
|
| } |
| 842 |
|
| |
| 843 |
141 |
| static SV *pmj_create(pTHX_ SV *self, SV *data) { |
| 844 |
141 |
| HV *h = pmr_self(aTHX_ self, PMJ); |
| 845 |
|
| /* |
| 846 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 847 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 848 |
141 |
▶ | HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
141 |
0 |
141 |
| HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
141 |
0 |
141 |
|
| 849 |
141 |
| SV *pk = pdbi_get(aTHX_ h, "primary"); |
| 850 |
141 |
| const char *path = SvPV_nolen(pmj_file(aTHX_ h)); |
| 851 |
141 |
| HV *row = (HV *)sv_2mortal((SV *)pmj_known(aTHX_ pmr_colset(aTHX_ h), d, 0)); |
| 852 |
|
| AV *rows; |
| 853 |
|
| HV *doc; |
| 854 |
|
| SV *out; |
| 855 |
141 |
▶ | if (!HvUSEDKEYS(row)) croak(PMJ ": create with no known columns"); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!HvUSEDKEYS(row)) croak(PMJ ": create with no known columns"); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
141 |
141 |
| if (!HvUSEDKEYS(row)) croak(PMJ ": create with no known columns"); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
5 |
136 |
141 |
|
| 856 |
136 |
| ENTER; |
| 857 |
136 |
| pmj_lock_scoped(aTHX_ path); |
| 858 |
|
| { |
| 859 |
|
| { |
| 860 |
135 |
| doc = pmj_fresh(aTHX_ self, path, &rows); |
| 861 |
|
| /* |
| 862 |
|
| # uncoverable branch false class:ignore_covered_err |
| 863 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 864 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 865 |
130 |
▶ | if (pk && SvOK(pk)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (pk && SvOK(pk)) { |
130 |
0 |
130 |
| if (pk && SvOK(pk)) { |
130 |
0 |
130 |
|
| 866 |
130 |
| HE *he = hv_fetch_ent(row, pk, 0, 0); |
| 867 |
130 |
▶ | if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
110 |
20 |
130 |
| if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
110 |
0 |
110 |
|
| 868 |
110 |
▶ | if (pmj_find(aTHX_ rows, pk, HeVAL(he)) >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pmj_find(aTHX_ rows, pk, HeVAL(he)) >= 0) |
5 |
105 |
110 |
|
| 869 |
15 |
▶ | croak(PMJ ": a row with %s = %s already exists in %s", |
Branch: 1 branch
| Branch | True | False | Total |
| croak(PMJ ": a row with %s = %s already exists in %s", |
5 |
0 |
5 |
|
| 870 |
|
| SvPV_nolen(pk), SvPV_nolen(HeVAL(he)), path); |
| 871 |
|
| } |
| 872 |
|
| else { |
| 873 |
|
| /* the next integer key, when every key so far is one */ |
| 874 |
20 |
| SSize_t i, n = av_len(rows) + 1; |
| 875 |
20 |
| IV max = 0; |
| 876 |
40 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
25 |
15 |
40 |
|
| 877 |
25 |
| SV **e = av_fetch(rows, i, 0); |
| 878 |
|
| HE *ke; |
| 879 |
|
| SV *k; |
| 880 |
|
| /* |
| 881 |
|
| # uncoverable branch true |
| 882 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 883 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 884 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 885 |
25 |
▶ | if (!(e && *e && SvROK(*e))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(e && *e && SvROK(*e))) continue; |
25 |
0 |
25 |
| if (!(e && *e && SvROK(*e))) continue; |
25 |
0 |
25 |
| if (!(e && *e && SvROK(*e))) continue; |
0 |
25 |
25 |
|
| 886 |
25 |
| ke = hv_fetch_ent((HV *)SvRV(*e), pk, 0, 0); |
| 887 |
25 |
▶ | k = ke ? HeVAL(ke) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| k = ke ? HeVAL(ke) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
25 |
0 |
25 |
|
| 888 |
|
| /* |
| 889 |
|
| # uncoverable branch true |
| 890 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 891 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 892 |
25 |
▶ | if (!(k && SvOK(k))) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(k && SvOK(k))) continue; |
25 |
0 |
25 |
| if (!(k && SvOK(k))) continue; |
0 |
25 |
25 |
|
| 893 |
|
| { |
| 894 |
|
| IV kv; |
| 895 |
25 |
▶ | if (!pmr_int(aTHX_ k, &kv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pmr_int(aTHX_ k, &kv)) |
5 |
20 |
25 |
|
| 896 |
5 |
| croak(PMJ ": create needs a value for %s - its " |
| 897 |
|
| "existing keys are not all integers, so " |
| 898 |
|
| "there is no next one", SvPV_nolen(pk)); |
| 899 |
|
| /* |
| 900 |
|
| # uncoverable branch false |
| 901 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 902 |
20 |
▶ | if (kv > max) max = kv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (kv > max) max = kv; |
20 |
0 |
20 |
|
| 903 |
|
| } |
| 904 |
|
| } |
| 905 |
15 |
| (void)hv_store_ent(row, pk, newSViv(max + 1), 0); |
| 906 |
|
| } |
| 907 |
|
| } |
| 908 |
120 |
| av_push(rows, newRV_inc((SV *)row)); |
| 909 |
120 |
| pmj_write(aTHX_ path, doc); |
| 910 |
|
| } |
| 911 |
|
| } |
| 912 |
120 |
| LEAVE; |
| 913 |
120 |
| out = pmr_deep(aTHX_ sv_2mortal(newRV_inc((SV *)row))); |
| 914 |
120 |
| return out; |
| 915 |
|
| } |
| 916 |
|
| |
| 917 |
21 |
| static SV *pmj_update(pTHX_ SV *self, SV *data) { |
| 918 |
21 |
| HV *h = pmr_self(aTHX_ self, PMJ); |
| 919 |
|
| /* |
| 920 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 921 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 922 |
21 |
▶ | HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
21 |
0 |
21 |
| HV *d = (SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) ? (HV *)SvRV(data) : NULL; |
21 |
0 |
21 |
|
| 923 |
21 |
| SV *pk = pdbi_get(aTHX_ h, "primary"); |
| 924 |
|
| const char *path; |
| 925 |
|
| HV *changes; |
| 926 |
|
| HE *pke; |
| 927 |
|
| SV *id; |
| 928 |
21 |
| SV *out = NULL; |
| 929 |
21 |
▶ | if (!(pk && SvOK(pk))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(pk && SvOK(pk))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
21 |
0 |
21 |
| if (!(pk && SvOK(pk))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
1 |
20 |
21 |
|
| 930 |
1 |
| croak(PMJ ": update needs a primary key"); |
| 931 |
20 |
▶ | pke = d ? hv_fetch_ent(d, pk, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| pke = d ? hv_fetch_ent(d, pk, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
20 |
0 |
20 |
|
| 932 |
20 |
▶ | if (!(pke && SvOK(HeVAL(pke)))) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(pke && SvOK(HeVAL(pke)))) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
15 |
5 |
20 |
| if (!(pke && SvOK(HeVAL(pke)))) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
15 |
15 |
|
| 933 |
5 |
| croak(PMJ ": update needs the primary key in the data"); |
| 934 |
15 |
| id = sv_2mortal(newSVsv(HeVAL(pke))); |
| 935 |
15 |
| path = SvPV_nolen(pmj_file(aTHX_ h)); |
| 936 |
15 |
| changes = (HV *)sv_2mortal((SV *)pmj_known(aTHX_ pmr_colset(aTHX_ h), d, 1)); |
| 937 |
15 |
| (void)hv_delete_ent(changes, pk, G_DISCARD, 0); |
| 938 |
15 |
| ENTER; |
| 939 |
15 |
| pmj_lock_scoped(aTHX_ path); |
| 940 |
|
| { |
| 941 |
|
| { |
| 942 |
|
| AV *rows; |
| 943 |
15 |
| HV *doc = pmj_fresh(aTHX_ self, path, &rows); |
| 944 |
15 |
| SSize_t at = pmj_find(aTHX_ rows, pk, id); |
| 945 |
15 |
▶ | if (at >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (at >= 0) { |
10 |
5 |
15 |
|
| 946 |
10 |
| HV *row = (HV *)SvRV(*av_fetch(rows, at, 0)); |
| 947 |
|
| HE *he; |
| 948 |
10 |
| hv_iterinit(changes); |
| 949 |
25 |
▶ | while ((he = hv_iternext(changes))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(changes))) |
15 |
10 |
25 |
|
| 950 |
15 |
| (void)hv_store_ent(row, hv_iterkeysv(he), |
| 951 |
|
| newSVsv(HeVAL(he)), 0); |
| 952 |
|
| /* |
| 953 |
|
| # uncoverable branch false |
| 954 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 955 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 956 |
10 |
▶ | if (HvUSEDKEYS(changes)) pmj_write(aTHX_ path, doc); |
Branch: 2 branches
| Branch | True | False | Total |
| if (HvUSEDKEYS(changes)) pmj_write(aTHX_ path, doc); |
0 |
10 |
10 |
| if (HvUSEDKEYS(changes)) pmj_write(aTHX_ path, doc); |
10 |
0 |
10 |
|
| 957 |
10 |
| out = pmr_deep(aTHX_ *av_fetch(rows, at, 0)); |
| 958 |
|
| } |
| 959 |
|
| } |
| 960 |
|
| } |
| 961 |
15 |
| LEAVE; |
| 962 |
15 |
▶ | return out ? out : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| return out ? out : newSV(0); |
5 |
10 |
15 |
|
| 963 |
|
| } |
| 964 |
|
| |
| 965 |
15 |
| static IV pmj_delete(pTHX_ SV *self, SV **st, I32 items) { |
| 966 |
15 |
| HV *h = pmr_self(aTHX_ self, PMJ); |
| 967 |
|
| HV *key; |
| 968 |
15 |
| AV *keys = pdbi_key_args(aTHX_ st, items, &key, "delete", PMJ); |
| 969 |
|
| AV *terms; |
| 970 |
|
| const char *path; |
| 971 |
15 |
| IV gone = 0; |
| 972 |
15 |
| pdbq_check_keys(aTHX_ self, keys, PMJ, "delete"); |
| 973 |
15 |
| terms = pmr_compile(aTHX_ NULL, NULL, key, PMJ); |
| 974 |
15 |
| path = SvPV_nolen(pmj_file(aTHX_ h)); |
| 975 |
15 |
| ENTER; |
| 976 |
15 |
| pmj_lock_scoped(aTHX_ path); |
| 977 |
|
| { |
| 978 |
|
| { |
| 979 |
|
| Stat_t st0; |
| 980 |
|
| /* |
| 981 |
|
| # uncoverable branch false |
| 982 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 983 |
15 |
▶ | if (PerlLIO_stat(path, &st0) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PerlLIO_stat(path, &st0) == 0) { |
15 |
0 |
15 |
|
| 984 |
|
| AV *rows; |
| 985 |
15 |
| HV *doc = pmj_fresh(aTHX_ self, path, &rows); |
| 986 |
15 |
| AV *keep = newAV(); |
| 987 |
15 |
| SSize_t i, n = av_len(rows) + 1; |
| 988 |
65 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
50 |
15 |
65 |
|
| 989 |
50 |
| SV **e = av_fetch(rows, i, 0); |
| 990 |
|
| /* |
| 991 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 992 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 993 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 994 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 995 |
50 |
▶ | if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
Branch: 4 branches
| Branch | True | False | Total |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
50 |
0 |
50 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
50 |
0 |
50 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
50 |
0 |
50 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV |
50 |
0 |
50 |
|
| 996 |
50 |
▶ | && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) { |
Branch: 1 branch
| Branch | True | False | Total |
| && pmr_match(aTHX_ terms, (HV *)SvRV(*e))) { |
10 |
40 |
50 |
|
| 997 |
10 |
| gone++; |
| 998 |
10 |
| continue; |
| 999 |
|
| } |
| 1000 |
|
| /* |
| 1001 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 1002 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 1003 |
40 |
▶ | av_push(keep, e && *e ? newSVsv(*e) : newSV(0)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(keep, e && *e ? newSVsv(*e) : newSV(0)); |
40 |
0 |
40 |
| av_push(keep, e && *e ? newSVsv(*e) : newSV(0)); |
40 |
0 |
40 |
|
| 1004 |
|
| } |
| 1005 |
15 |
| (void)hv_store_ent(doc, pdbi_get(aTHX_ h, "table"), |
| 1006 |
|
| newRV_noinc((SV *)keep), 0); |
| 1007 |
15 |
▶ | if (gone) pmj_write(aTHX_ path, doc); |
Branch: 1 branch
| Branch | True | False | Total |
| if (gone) pmj_write(aTHX_ path, doc); |
10 |
5 |
15 |
|
| 1008 |
|
| } |
| 1009 |
|
| } |
| 1010 |
|
| } |
| 1011 |
15 |
| LEAVE; |
| 1012 |
15 |
| return gone; |
| 1013 |
|
| } |
| 1014 |
|
| |
| 1015 |
|
| /* ---- Punk::Model::Markdown ---------------------------------------------------- |
| 1016 |
|
| * |
| 1017 |
|
| * The pages of a `markdown` mount, as rows: what $app->markdown_pages gives, |
| 1018 |
|
| * read straight from the mount's page table. The files are the pages, so the |
| 1019 |
|
| * backend does not write. */ |
| 1020 |
|
| |
| 1021 |
|
| #define PMM "Punk::Model::Markdown" |
| 1022 |
|
| |
| 1023 |
|
| /* The capture of the markdown mount at `prefix` (trailing slash ignored), or |
| 1024 |
|
| * a croak naming why: not compiled yet, or no such mount (listing the ones |
| 1025 |
|
| * there are). `who` prefixes the croak. Borrowed. */ |
| 1026 |
29 |
| static AV *pmd_mount_cap(pTHX_ SV *app, SV *prefix, const char *who) { |
| 1027 |
29 |
| HV *h = app_hv(aTHX_ app); |
| 1028 |
29 |
▶ | SV *mp = h ? app_get(aTHX_ h, K_MOUNTS_C) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *mp = h ? app_get(aTHX_ h, K_MOUNTS_C) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
29 |
0 |
29 |
|
| 1029 |
29 |
| SV *pf = sv_2mortal(app_strip_slash(aTHX_ prefix)); |
| 1030 |
29 |
| SV *have = sv_2mortal(newSVpvs("")); |
| 1031 |
|
| AV *mounts; |
| 1032 |
|
| SSize_t i, n; |
| 1033 |
|
| /* |
| 1034 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 1035 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 1036 |
29 |
▶ | if (!(mp && SvROK(mp) && SvTYPE(SvRV(mp)) == SVt_PVAV)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(mp && SvROK(mp) && SvTYPE(SvRV(mp)) == SVt_PVAV)) |
28 |
1 |
29 |
| if (!(mp && SvROK(mp) && SvTYPE(SvRV(mp)) == SVt_PVAV)) |
28 |
0 |
28 |
| if (!(mp && SvROK(mp) && SvTYPE(SvRV(mp)) == SVt_PVAV)) |
0 |
28 |
28 |
|
| 1037 |
1 |
| croak("%s: the application has not been compiled yet (call it from " |
| 1038 |
|
| "a route, or after to_app)", who); |
| 1039 |
28 |
| mounts = (AV *)SvRV(mp); |
| 1040 |
28 |
| n = av_len(mounts) + 1; |
| 1041 |
35 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
31 |
4 |
35 |
|
| 1042 |
31 |
| SV **e = av_fetch(mounts, i, 0); |
| 1043 |
|
| HV *m; |
| 1044 |
|
| SV **flag, **mpf, **mapp; |
| 1045 |
|
| AV *cap; |
| 1046 |
|
| /* |
| 1047 |
|
| # uncoverable branch true |
| 1048 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 1049 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 1050 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 1051 |
31 |
▶ | if (!e || !*e || !SvROK(*e)) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!e || !*e || !SvROK(*e)) continue; |
31 |
0 |
31 |
| if (!e || !*e || !SvROK(*e)) continue; |
31 |
0 |
31 |
| if (!e || !*e || !SvROK(*e)) continue; |
0 |
31 |
31 |
|
| 1052 |
31 |
| m = (HV *)SvRV(*e); |
| 1053 |
31 |
| flag = hv_fetchs(m, K_MD_MOUNT, 0); |
| 1054 |
|
| /* |
| 1055 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 1056 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 1057 |
31 |
▶ | if (!(flag && *flag && SvTRUE(*flag))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(flag && *flag && SvTRUE(*flag))) continue; |
29 |
2 |
31 |
| if (!(flag && *flag && SvTRUE(*flag))) continue; |
29 |
0 |
29 |
| if (!(flag && *flag && SvTRUE(*flag))) continue; |
0 |
29 |
29 |
|
| 1058 |
29 |
| mpf = hv_fetchs(m, K_PREFIX, 0); |
| 1059 |
|
| /* |
| 1060 |
|
| # uncoverable branch true |
| 1061 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 1062 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 1063 |
29 |
▶ | if (!(mpf && *mpf)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(mpf && *mpf)) continue; |
29 |
0 |
29 |
| if (!(mpf && *mpf)) continue; |
0 |
29 |
29 |
|
| 1064 |
29 |
▶ | if (sv_cmp(*mpf, pf) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_cmp(*mpf, pf) != 0) { |
5 |
24 |
29 |
|
| 1065 |
5 |
▶ | if (SvCUR(have)) sv_catpvs(have, ", "); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvCUR(have)) sv_catpvs(have, ", "); |
2 |
3 |
5 |
|
| 1066 |
5 |
▶ | sv_catsv(have, SvCUR(*mpf) ? *mpf : sv_2mortal(newSVpvs("/"))); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catsv(have, SvCUR(*mpf) ? *mpf : sv_2mortal(newSVpvs("/"))); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
5 |
0 |
5 |
|
| 1067 |
5 |
| continue; |
| 1068 |
|
| } |
| 1069 |
24 |
| mapp = hv_fetchs(m, K_APP, 0); |
| 1070 |
24 |
▶ | cap = (mapp && *mapp && SvROK(*mapp) && SvTYPE(SvRV(*mapp)) == SVt_PVCV) |
Branch: 3 branches
| Branch | True | False | Total |
| cap = (mapp && *mapp && SvROK(*mapp) && SvTYPE(SvRV(*mapp)) == SVt_PVCV) |
24 |
0 |
24 |
| cap = (mapp && *mapp && SvROK(*mapp) && SvTYPE(SvRV(*mapp)) == SVt_PVCV) |
24 |
0 |
24 |
| cap = (mapp && *mapp && SvROK(*mapp) && SvTYPE(SvRV(*mapp)) == SVt_PVCV) |
24 |
0 |
24 |
|
| 1071 |
48 |
▶ | ? punk_clos_cap(aTHX_ (CV *)SvRV(*mapp)) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? punk_clos_cap(aTHX_ (CV *)SvRV(*mapp)) : NULL; |
24 |
0 |
24 |
|
| 1072 |
|
| /* |
| 1073 |
|
| # uncoverable branch true |
| 1074 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 1075 |
24 |
▶ | if (!cap) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cap) |
0 |
24 |
24 |
|
| 1076 |
0 |
| croak("%s: the mount at '%s' was not built", who, SvPV_nolen(*mpf)); /* # uncoverable statement */ |
| 1077 |
24 |
| return cap; |
| 1078 |
|
| } |
| 1079 |
8 |
▶ | croak("%s: no markdown mount at '%s' (%s%s)", who, |
Branch: 2 branches
| Branch | True | False | Total |
| croak("%s: no markdown mount at '%s' (%s%s)", who, |
2 |
2 |
4 |
| croak("%s: no markdown mount at '%s' (%s%s)", who, |
4 |
0 |
4 |
|
| 1080 |
|
| SvCUR(pf) ? SvPV_nolen(pf) : "/", /* # uncoverable condition right count:1 class:ignore_covered_err */ |
| 1081 |
|
| SvCUR(have) ? "markdown mounts: " : "there are none", |
| 1082 |
|
| SvPV_nolen(have)); |
| 1083 |
|
| return NULL; /* not reached */ |
| 1084 |
|
| } |
| 1085 |
|
| |
| 1086 |
|
| /* The mount's pages as rows. Mortal AV. */ |
| 1087 |
13 |
| static AV *pmm_rows(pTHX_ SV *self) { |
| 1088 |
13 |
| HV *h = pmr_self(aTHX_ self, PMM); |
| 1089 |
13 |
| SV *app = pdbi_get(aTHX_ h, "app"); |
| 1090 |
13 |
| SV *o = pdbi_get(aTHX_ h, "opts"); |
| 1091 |
|
| /* |
| 1092 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 1093 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 1094 |
13 |
▶ | SV *prefix = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "prefix") : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *prefix = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "prefix") : NULL; |
13 |
0 |
13 |
| SV *prefix = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "prefix") : NULL; |
13 |
0 |
13 |
|
| 1095 |
|
| /* |
| 1096 |
|
| # uncoverable branch true |
| 1097 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 1098 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 1099 |
13 |
▶ | if (!(app && SvROK(app))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(app && SvROK(app))) |
13 |
0 |
13 |
| if (!(app && SvROK(app))) |
0 |
13 |
13 |
|
| 1100 |
0 |
| croak(PMM ": the application has gone away"); /* # uncoverable statement */ |
| 1101 |
13 |
| return (AV *)sv_2mortal((SV *)pmd_pages_av(aTHX_ |
| 1102 |
|
| pmd_mount_cap(aTHX_ app, prefix, PMM))); |
| 1103 |
|
| } |
| 1104 |
|
| |
| 1105 |
|
| #endif /* PUNK_MROWS_H */ |