xs/txn.xs

filter: Statementstmt 100% 26 / 26 Branchbran 86.3% 19 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.7% 45 / 48 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/history.xs ↑ Summary xs/checkpoint.xs »
1 # Transactions.
2  
3 MODULE = State::Store PACKAGE = State::Store
4  
5 # txn($code): runs $code with the store, in the caller's context, and
6 # returns what it returns. A die inside puts the store back as it was and
7 # goes on up.
8 void
9 txn(self, code)
10 SV *self
11 SV *code
12 PREINIT:
13 store *s;
14 SV *hold, *err, *one;
15 AV *many;
16 store_saved saved;
17 I32 n, gimme, i;
18 PPCODE:
19 4055 s = store_handle(aTHX_ self, "State::Store::txn");
20 4055 SvGETMAGIC(code);
21 4055 ▶ if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 4053 2 4055
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 2 4051 4053
22 4 croak("State::Store::txn: not a code reference");
23 4051 store_check_mutable(aTHX_ s, "State::Store::txn");
24 4050 hold = sv_2mortal(newSVsv(self));
25 4050 gimme = GIMME_V;
26 4050 store_txn_begin(aTHX_ s, &saved, "State::Store::txn");
27  
28 4050 many = (AV *)sv_2mortal((SV *)newAV());
29 4050 PUTBACK;
30 4050 err = store_call(aTHX_ code, &hold, 1, gimme, &one, many);
31 4050 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 2010 2040 4050
32 2010 store_txn_restore(aTHX_ s, &saved);
33 2010 store_rethrow(aTHX_ err);
34 }
35 2040 ▶ if (s->txn_depth > 1) store_txn_forget(aTHX_ s, &saved);
Branch: 1 branch
BranchTrueFalseTotal
if (s->txn_depth > 1) store_txn_forget(aTHX_ s, &saved); 3 2037 2040
36 else {
37 2037 store_txn_commit(aTHX_ s, &saved, "State::Store::txn");
38 2037 store_deliver(aTHX_ s, hold);
39 }
40 2039 SPAGAIN;
41 2039 ▶ if (gimme == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme == G_SCALAR) { 5 2034 2039
42 5 ▶ XPUSHs(one);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(one); 0 5 5
43 }
44 2034 ▶ else if (gimme == G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
else if (gimme == G_LIST) { 3 2031 2034
45 3 n = av_len(many) + 1;
46 3 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 3 0 3
EXTEND(SP, n); 0 3 3
47 8 ▶ for (i = 0; i < n; i++) PUSHs(*av_fetch(many, i, 0));
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) PUSHs(*av_fetch(many, i, 0)); 5 3 8
48 }
49  
50 void
51 in_txn(self)
52 SV *self
53 CODE:
54 16 ▶ ST(0) = boolSV(store_handle(aTHX_ self, "State::Store::in_txn")->txn_depth > 0);
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = boolSV(store_handle(aTHX_ self, "State::Store::in_txn")->txn_depth > 0); 1 15 16
55 16 XSRETURN(1);
« xs/history.xs ↑ Summary xs/checkpoint.xs »