| 1 |
|
| MODULE = Punk PACKAGE = Punk::Model::DBIx::Loop |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # The async model backend, in C (punk_dbil.h). The same six-method contract |
| 6 |
|
| # as Punk::Model::DBI, but every method returns a Punk::Future: the statement |
| 7 |
|
| # runs on DBIx::Loop over the worker's own loop, reached through its C ABI, |
| 8 |
|
| # and one C continuation settles the future when the rows land. |
| 9 |
|
| # Punk::Model::DBIx::Loop.pm is the documentation. |
| 10 |
|
| |
| 11 |
|
| SV * |
| 12 |
|
| new(class, ...) |
| 13 |
|
| SV *class |
| 14 |
|
| CODE: |
| 15 |
13 |
| RETVAL = pdbi_build_self(aTHX_ class, &ST(0), items, PDL_CLS); |
| 16 |
|
| OUTPUT: |
| 17 |
|
| RETVAL |
| 18 |
|
| |
| 19 |
|
| # The per-worker DBIx::Loop connection for this backend's dsn, built on the |
| 20 |
|
| # first statement and shared with every other backend on the same one. |
| 21 |
|
| SV * |
| 22 |
|
| db(self) |
| 23 |
|
| SV *self |
| 24 |
|
| CODE: |
| 25 |
|
| { |
| 26 |
9 |
| SV *v = pdbi_get(aTHX_ pdl_handle(aTHX_ self), "db"); |
| 27 |
9 |
▶ | RETVAL = v ? newSVsv(v) : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = v ? newSVsv(v) : newSV(0); |
9 |
0 |
9 |
|
| 28 |
|
| } |
| 29 |
|
| OUTPUT: |
| 30 |
|
| RETVAL |
| 31 |
|
| |
| 32 |
|
| # The parent DBI handle (DBIx::Loop's own), for parity with the DBI |
| 33 |
|
| # backend's reach-through; statements do NOT run on it. |
| 34 |
|
| SV * |
| 35 |
|
| dbh(self) |
| 36 |
|
| SV *self |
| 37 |
|
| CODE: |
| 38 |
|
| { |
| 39 |
5 |
| SV *v = pdbi_get(aTHX_ pdl_handle(aTHX_ self), "dbh"); |
| 40 |
5 |
▶ | RETVAL = v ? newSVsv(v) : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = v ? newSVsv(v) : newSV(0); |
5 |
0 |
5 |
|
| 41 |
|
| } |
| 42 |
|
| OUTPUT: |
| 43 |
|
| RETVAL |
| 44 |
|
| |
| 45 |
|
| # The DBIx::Loop loop adapter this connection runs on. |
| 46 |
|
| SV * |
| 47 |
|
| adapter(self) |
| 48 |
|
| SV *self |
| 49 |
|
| CODE: |
| 50 |
|
| { |
| 51 |
0 |
| SV *v = pdbi_get(aTHX_ pdl_handle(aTHX_ self), "adapter"); |
| 52 |
0 |
▶ | RETVAL = v ? newSVsv(v) : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = v ? newSVsv(v) : newSV(0); |
0 |
0 |
0 |
|
| 53 |
|
| } |
| 54 |
|
| OUTPUT: |
| 55 |
|
| RETVAL |
| 56 |
|
| |
| 57 |
|
| IV |
| 58 |
|
| _returning(self) |
| 59 |
|
| SV *self |
| 60 |
|
| CODE: |
| 61 |
|
| { |
| 62 |
0 |
| SV *r = pdbi_get(aTHX_ pdl_handle(aTHX_ self), "returning"); |
| 63 |
0 |
▶ | RETVAL = r ? SvIV(r) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = r ? SvIV(r) : 0; |
0 |
0 |
0 |
| RETVAL = r ? SvIV(r) : 0; |
0 |
0 |
0 |
|
| 64 |
|
| } |
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |
| 67 |
|
| |
| 68 |
|
| # Is DBIx::Loop's C ABI resolvable and new enough? The guard test's probe. |
| 69 |
|
| IV |
| 70 |
|
| _abi_ok(class) |
| 71 |
|
| SV *class |
| 72 |
|
| CODE: |
| 73 |
|
| PERL_UNUSED_VAR(class); |
| 74 |
2 |
▶ | RETVAL = punk_dbil_try(aTHX) ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = punk_dbil_try(aTHX) ? 1 : 0; |
0 |
2 |
2 |
|
| 75 |
|
| OUTPUT: |
| 76 |
|
| RETVAL |
| 77 |
|
| |
| 78 |
|
| # ---- the contract: everything returns a Punk::Future ------------------------ |
| 79 |
|
| |
| 80 |
|
| SV * |
| 81 |
|
| get(self, ...) |
| 82 |
|
| SV *self |
| 83 |
|
| CODE: |
| 84 |
15 |
| RETVAL = pdl_get(aTHX_ self, &ST(0), items); |
| 85 |
|
| OUTPUT: |
| 86 |
|
| RETVAL |
| 87 |
|
| |
| 88 |
|
| SV * |
| 89 |
|
| search(self, filter = &PL_sv_undef, opts = &PL_sv_undef) |
| 90 |
|
| SV *self |
| 91 |
|
| SV *filter |
| 92 |
|
| SV *opts |
| 93 |
|
| CODE: |
| 94 |
136 |
| RETVAL = pdl_search(aTHX_ self, filter, opts); |
| 95 |
|
| OUTPUT: |
| 96 |
|
| RETVAL |
| 97 |
|
| |
| 98 |
|
| SV * |
| 99 |
|
| count(self, filter = &PL_sv_undef) |
| 100 |
|
| SV *self |
| 101 |
|
| SV *filter |
| 102 |
|
| CODE: |
| 103 |
17 |
| RETVAL = pdl_count(aTHX_ self, filter); |
| 104 |
|
| OUTPUT: |
| 105 |
|
| RETVAL |
| 106 |
|
| |
| 107 |
|
| SV * |
| 108 |
|
| all(self) |
| 109 |
|
| SV *self |
| 110 |
|
| CODE: |
| 111 |
0 |
| RETVAL = pdl_search(aTHX_ self, &PL_sv_undef, &PL_sv_undef); |
| 112 |
|
| OUTPUT: |
| 113 |
|
| RETVAL |
| 114 |
|
| |
| 115 |
|
| SV * |
| 116 |
|
| create(self, data) |
| 117 |
|
| SV *self |
| 118 |
|
| SV *data |
| 119 |
|
| CODE: |
| 120 |
26 |
| RETVAL = pdl_create(aTHX_ self, data); |
| 121 |
|
| OUTPUT: |
| 122 |
|
| RETVAL |
| 123 |
|
| |
| 124 |
|
| SV * |
| 125 |
|
| update(self, data) |
| 126 |
|
| SV *self |
| 127 |
|
| SV *data |
| 128 |
|
| CODE: |
| 129 |
3 |
| RETVAL = pdl_update(aTHX_ self, data); |
| 130 |
|
| OUTPUT: |
| 131 |
|
| RETVAL |
| 132 |
|
| |
| 133 |
|
| SV * |
| 134 |
|
| delete(self, ...) |
| 135 |
|
| SV *self |
| 136 |
|
| CODE: |
| 137 |
4 |
| RETVAL = pdl_delete(aTHX_ self, &ST(0), items); |
| 138 |
|
| OUTPUT: |
| 139 |
|
| RETVAL |
| 140 |
|
| |
| 141 |
|
| # future($dbil_future): bridge a raw DBIx::Loop::Future - from a custom |
| 142 |
|
| # query on $backend->db - into a Punk::Future carrying the same values. |
| 143 |
|
| SV * |
| 144 |
|
| future(self, f) |
| 145 |
|
| SV *self |
| 146 |
|
| SV *f |
| 147 |
|
| CODE: |
| 148 |
0 |
| RETVAL = pdl_wrap(aTHX_ self, f); |
| 149 |
|
| OUTPUT: |
| 150 |
|
| RETVAL |
| 151 |
|
| |
| 152 |
|
| # await($future): resolve one of this backend's futures outside a worker, by |
| 153 |
|
| # pumping the adapter's own loop. Inside a worker $c->await already does this |
| 154 |
|
| # against the worker's loop. Returns the settled values (croaks on failure), |
| 155 |
|
| # exactly as Punk::Future->get does. |
| 156 |
|
| void |
| 157 |
|
| await(self, f) |
| 158 |
|
| SV *self |
| 159 |
|
| SV *f |
| 160 |
|
| PPCODE: |
| 161 |
|
| { |
| 162 |
4 |
| pdl_await(aTHX_ self, f); |
| 163 |
|
| /* The loop has just run arbitrary callbacks, and any of them may |
| 164 |
|
| * have grown the value stack - which moves it. SP is where the stack |
| 165 |
|
| * WAS when this XSUB was entered, so it is worked out again from the |
| 166 |
|
| * base: the slot below this call's first argument, which is where |
| 167 |
|
| * PPCODE left it and where get's values have to land. */ |
| 168 |
4 |
| SP = PL_stack_base + ax - 1; |
| 169 |
4 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
4 |
4 |
|
| 170 |
4 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
4 |
4 |
|
| 171 |
4 |
| PUSHs(f); |
| 172 |
4 |
| PUTBACK; |
| 173 |
4 |
| call_method("get", GIMME_V); |
| 174 |
4 |
| SPAGAIN; |
| 175 |
4 |
| return; /* the values get() left on the stack */ |
| 176 |
|
| } |
| 177 |
|
| |
| 178 |
|
| # ---- the opaque keyset token (the SHARED codec - see punk_dbi.h) ----------- |
| 179 |
|
| |
| 180 |
|
| SV * |
| 181 |
|
| _encode_token(self, val) |
| 182 |
|
| SV *self |
| 183 |
|
| SV *val |
| 184 |
|
| CODE: |
| 185 |
|
| PERL_UNUSED_VAR(self); |
| 186 |
1 |
| RETVAL = pdbi_encode_token(aTHX_ val); |
| 187 |
|
| OUTPUT: |
| 188 |
|
| RETVAL |
| 189 |
|
| |
| 190 |
|
| SV * |
| 191 |
|
| _decode_token(self, tok) |
| 192 |
|
| SV *self |
| 193 |
|
| SV *tok |
| 194 |
|
| CODE: |
| 195 |
|
| PERL_UNUSED_VAR(self); |
| 196 |
1 |
| RETVAL = pdbi_decode_token(aTHX_ tok, PDL_CLS); |
| 197 |
|
| OUTPUT: |
| 198 |
|
| RETVAL |