| 1 |
|
| MODULE = Punk PACKAGE = Punk::Model::JSONFile |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # A model backend over a JSON file (punk_mrows.h): the file is an object and |
| 6 |
|
| # the model's table names an array of rows in it. Reads are cached until the |
| 7 |
|
| # file changes; writes lock, re-read, and rename a new file into place. |
| 8 |
|
| # Punk::Model::JSONFile.pm is the documentation. |
| 9 |
|
| |
| 10 |
|
| SV * |
| 11 |
|
| new(class, ...) |
| 12 |
|
| SV *class |
| 13 |
|
| CODE: |
| 14 |
30 |
| RETVAL = pdbi_build_self(aTHX_ class, &ST(0), items, PMJ); |
| 15 |
30 |
| (void)pmj_file(aTHX_ (HV *)SvRV(RETVAL)); |
| 16 |
|
| OUTPUT: |
| 17 |
|
| RETVAL |
| 18 |
|
| |
| 19 |
|
| SV * |
| 20 |
|
| file(self) |
| 21 |
|
| SV *self |
| 22 |
|
| CODE: |
| 23 |
6 |
| RETVAL = newSVsv(pmj_file(aTHX_ pmr_self(aTHX_ self, PMJ))); |
| 24 |
|
| OUTPUT: |
| 25 |
|
| RETVAL |
| 26 |
|
| |
| 27 |
|
| # The whole decoded file, copied, or undef when there is no usable file: |
| 28 |
|
| # for values kept beside the tables. |
| 29 |
|
| SV * |
| 30 |
|
| document(self) |
| 31 |
|
| SV *self |
| 32 |
|
| CODE: |
| 33 |
|
| { |
| 34 |
20 |
| HV *doc = pmj_document(aTHX_ self); |
| 35 |
20 |
| RETVAL = doc ? pmr_deep(aTHX_ sv_2mortal(newRV_inc((SV *)doc))) |
| 36 |
20 |
▶ | : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| : newSV(0); |
15 |
5 |
20 |
|
| 37 |
|
| } |
| 38 |
|
| OUTPUT: |
| 39 |
|
| RETVAL |
| 40 |
|
| |
| 41 |
|
| SV * |
| 42 |
|
| get(self, ...) |
| 43 |
|
| SV *self |
| 44 |
|
| CODE: |
| 45 |
35 |
| RETVAL = pmr_get(aTHX_ self, pmj_rows(aTHX_ self), &ST(0), items, PMJ); |
| 46 |
|
| OUTPUT: |
| 47 |
|
| RETVAL |
| 48 |
|
| |
| 49 |
|
| SV * |
| 50 |
|
| search(self, filter = &PL_sv_undef, opts = &PL_sv_undef) |
| 51 |
|
| SV *self |
| 52 |
|
| SV *filter |
| 53 |
|
| SV *opts |
| 54 |
|
| CODE: |
| 55 |
212 |
| RETVAL = pmr_search(aTHX_ self, pmj_rows(aTHX_ self), filter, opts, PMJ); |
| 56 |
|
| OUTPUT: |
| 57 |
|
| RETVAL |
| 58 |
|
| |
| 59 |
|
| IV |
| 60 |
|
| count(self, filter = &PL_sv_undef) |
| 61 |
|
| SV *self |
| 62 |
|
| SV *filter |
| 63 |
|
| CODE: |
| 64 |
38 |
| RETVAL = pmr_count(aTHX_ self, pmj_rows(aTHX_ self), filter, PMJ); |
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |
| 67 |
|
| |
| 68 |
|
| SV * |
| 69 |
|
| # uncoverable statement |
| 70 |
|
| # uncoverable subroutine |
| 71 |
|
| all(self) |
| 72 |
|
| SV *self |
| 73 |
|
| CODE: |
| 74 |
0 |
| RETVAL = pmr_search(aTHX_ self, pmj_rows(aTHX_ self), NULL, NULL, PMJ); /* # uncoverable statement */ |
| 75 |
|
| OUTPUT: |
| 76 |
|
| RETVAL |
| 77 |
|
| |
| 78 |
|
| SV * |
| 79 |
|
| create(self, data) |
| 80 |
|
| SV *self |
| 81 |
|
| SV *data |
| 82 |
|
| CODE: |
| 83 |
141 |
| RETVAL = pmj_create(aTHX_ self, data); |
| 84 |
|
| OUTPUT: |
| 85 |
|
| RETVAL |
| 86 |
|
| |
| 87 |
|
| SV * |
| 88 |
|
| update(self, data) |
| 89 |
|
| SV *self |
| 90 |
|
| SV *data |
| 91 |
|
| CODE: |
| 92 |
21 |
| RETVAL = pmj_update(aTHX_ self, data); |
| 93 |
|
| OUTPUT: |
| 94 |
|
| RETVAL |
| 95 |
|
| |
| 96 |
|
| IV |
| 97 |
|
| delete(self, ...) |
| 98 |
|
| SV *self |
| 99 |
|
| CODE: |
| 100 |
15 |
| RETVAL = pmj_delete(aTHX_ self, &ST(0), items); |
| 101 |
|
| OUTPUT: |
| 102 |
|
| RETVAL |
| 103 |
|
| |
| 104 |
|
| MODULE = Punk PACKAGE = Punk::Model::Markdown |
| 105 |
|
| |
| 106 |
|
| PROTOTYPES: DISABLE |
| 107 |
|
| |
| 108 |
|
| # A read-only model backend over a `markdown` mount (punk_mrows.h): one row |
| 109 |
|
| # per page, as $app->markdown_pages gives them. Punk passes the application |
| 110 |
|
| # when it builds a backend; the mount is found by the database's prefix. |
| 111 |
|
| |
| 112 |
|
| SV * |
| 113 |
|
| new(class, ...) |
| 114 |
|
| SV *class |
| 115 |
|
| CODE: |
| 116 |
|
| { |
| 117 |
4 |
| SV *app = NULL, *o, *prefix; |
| 118 |
|
| HV *h; |
| 119 |
|
| I32 i; |
| 120 |
4 |
| RETVAL = pdbi_build_self(aTHX_ class, &ST(0), items, PMM); |
| 121 |
4 |
| h = (HV *)SvRV(RETVAL); |
| 122 |
21 |
▶ | for (i = 1; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i + 1 < items; i += 2) { |
17 |
4 |
21 |
|
| 123 |
17 |
| STRLEN kl; const char *k = SvPV_const(ST(i), kl); |
| 124 |
17 |
▶ | if (kl == 3 && memEQ(k, "app", 3)) app = ST(i + 1); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (kl == 3 && memEQ(k, "app", 3)) app = ST(i + 1); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
14 |
17 |
| if (kl == 3 && memEQ(k, "app", 3)) app = ST(i + 1); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
0 |
3 |
|
| 125 |
|
| } |
| 126 |
4 |
▶ | if (!(app && SvROK(app))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(app && SvROK(app))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
3 |
1 |
4 |
| if (!(app && SvROK(app))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
3 |
3 |
|
| 127 |
1 |
| SvREFCNT_dec(RETVAL); |
| 128 |
1 |
| croak(PMM ": needs the application - it is built by Punk::Model, " |
| 129 |
|
| "which passes it"); |
| 130 |
|
| } |
| 131 |
3 |
| o = pdbi_get(aTHX_ h, "opts"); |
| 132 |
3 |
▶ | # uncoverable condition right count:1 class:ignore_covered_err |
Branch: 2 branches
| Branch | True | False | Total |
| # uncoverable condition right count:1 class:ignore_covered_err |
3 |
0 |
3 |
| # uncoverable condition right count:1 class:ignore_covered_err |
3 |
0 |
3 |
|
| 133 |
3 |
▶ | # uncoverable condition right count:2 class:ignore_covered_err |
Branch: 3 branches
| Branch | True | False | Total |
| # uncoverable condition right count:2 class:ignore_covered_err |
2 |
1 |
3 |
| # uncoverable condition right count:2 class:ignore_covered_err |
2 |
0 |
2 |
| # uncoverable condition right count:2 class:ignore_covered_err |
0 |
2 |
2 |
|
| 134 |
1 |
| prefix = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "prefix") : NULL; |
| 135 |
1 |
| # uncoverable condition left count:2 class:ignore_covered_err |
| 136 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 137 |
|
| if (!(prefix && SvOK(prefix) && SvCUR(prefix))) { |
| 138 |
|
| SvREFCNT_dec(RETVAL); |
| 139 |
2 |
| croak(PMM ": the database needs a `prefix`, the markdown mount's " |
| 140 |
2 |
| "(database name => { backend => '" PMM "', prefix => '/blog' })"); |
| 141 |
2 |
| } |
| 142 |
|
| { /* weak: the application holds its models, which hold this */ |
| 143 |
|
| SV *w = newSVsv(app); |
| 144 |
|
| sv_rvweaken(w); |
| 145 |
|
| (void)hv_stores(h, "app", w); |
| 146 |
|
| } |
| 147 |
|
| } |
| 148 |
|
| OUTPUT: |
| 149 |
|
| RETVAL |
| 150 |
|
| |
| 151 |
|
| SV * |
| 152 |
|
| get(self, ...) |
| 153 |
|
| SV *self |
| 154 |
|
| CODE: |
| 155 |
6 |
| RETVAL = pmr_get(aTHX_ self, pmm_rows(aTHX_ self), &ST(0), items, PMM); |
| 156 |
|
| OUTPUT: |
| 157 |
|
| RETVAL |
| 158 |
|
| |
| 159 |
|
| SV * |
| 160 |
|
| search(self, filter = &PL_sv_undef, opts = &PL_sv_undef) |
| 161 |
|
| SV *self |
| 162 |
|
| SV *filter |
| 163 |
|
| SV *opts |
| 164 |
|
| CODE: |
| 165 |
5 |
| RETVAL = pmr_search(aTHX_ self, pmm_rows(aTHX_ self), filter, opts, PMM); |
| 166 |
|
| OUTPUT: |
| 167 |
|
| RETVAL |
| 168 |
|
| |
| 169 |
|
| IV |
| 170 |
|
| count(self, filter = &PL_sv_undef) |
| 171 |
|
| SV *self |
| 172 |
|
| SV *filter |
| 173 |
|
| CODE: |
| 174 |
2 |
| RETVAL = pmr_count(aTHX_ self, pmm_rows(aTHX_ self), filter, PMM); |
| 175 |
|
| OUTPUT: |
| 176 |
|
| RETVAL |
| 177 |
|
| |
| 178 |
|
| SV * |
| 179 |
|
| # uncoverable statement |
| 180 |
|
| # uncoverable subroutine |
| 181 |
|
| all(self) |
| 182 |
|
| SV *self |
| 183 |
|
| CODE: |
| 184 |
0 |
| RETVAL = pmr_search(aTHX_ self, pmm_rows(aTHX_ self), NULL, NULL, PMM); /* # uncoverable statement */ |
| 185 |
|
| OUTPUT: |
| 186 |
|
| RETVAL |
| 187 |
|
| |
| 188 |
|
| void |
| 189 |
|
| create(self, ...) |
| 190 |
|
| SV *self |
| 191 |
|
| ALIAS: |
| 192 |
|
| update = 1 |
| 193 |
|
| delete = 2 |
| 194 |
|
| CODE: |
| 195 |
|
| { |
| 196 |
|
| static const char *const what[] = { "create", "update", "delete" }; |
| 197 |
3 |
| HV *h = pmr_self(aTHX_ self, PMM); |
| 198 |
3 |
| SV *o = pdbi_get(aTHX_ h, "opts"); |
| 199 |
3 |
▶ | # uncoverable condition right count:1 class:ignore_covered_err |
Branch: 2 branches
| Branch | True | False | Total |
| # uncoverable condition right count:1 class:ignore_covered_err |
3 |
0 |
3 |
| # uncoverable condition right count:1 class:ignore_covered_err |
3 |
0 |
3 |
|
| 200 |
6 |
▶ | # uncoverable condition right count:2 class:ignore_covered_err |
Branch: 1 branch
| Branch | True | False | Total |
| # uncoverable condition right count:2 class:ignore_covered_err |
3 |
0 |
3 |
|
| 201 |
|
| SV *prefix = (o && SvROK(o)) ? pdbi_get(aTHX_ (HV *)SvRV(o), "prefix") : NULL; |
| 202 |
|
| croak(PMM ": %s - the pages at %s are the markdown files, which this " /* # uncoverable statement class:ignore_covered_err */ |
| 203 |
|
| "backend reads and does not write", what[ix], |
| 204 |
|
| prefix ? SvPV_nolen(prefix) : "?"); |
| 205 |
|
| } |