xs/txn.xs

filter: Statementstmt 91.6% 11 / 12 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 79.1% 19 / 24 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_mpstream.h ↑ Summary include/punk/punk_state.h »
1 MODULE = Punk PACKAGE = Punk::Txn
2  
3 PROTOTYPES: DISABLE
4  
5 # The transaction object the $c->txn block receives (punk_txn.h).
6 # lib/Punk/Txn.pm is documentation only.
7  
8 # model($name): the registered model, bound to this transaction.
9 SV *
10 model(self, name)
11 SV *self
12 SV *name
13 CODE:
14 27 RETVAL = ptx_model(aTHX_ self, name);
15 OUTPUT:
16 RETVAL
17  
18 # handle: the DBI $dbh on Punk::Model::DBI, the DBIx::Loop::Txn on
19 # Punk::Model::DBIx::Loop - for the raw statement that has no model.
20 SV *
21 handle(self)
22 SV *self
23 ALIAS:
24 name = 1
25 backend = 2
26 CODE:
27 {
28 static const char *const k[] = { "handle", "name", "class" };
29 17 SV *v = pdbi_get(aTHX_ ptx_hv(aTHX_ self), k[ix]);
30 17 ▶ RETVAL = v ? newSVsv(v) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : newSV(0); 17 0 17
31 }
32 OUTPUT:
33 RETVAL
34  
35 IV
36 is_active(self)
37 SV *self
38 CODE:
39 {
40 7 SV *v = pdbi_get(aTHX_ ptx_hv(aTHX_ self), "active");
41 7 ▶ RETVAL = (v && SvTRUE(v)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = (v && SvTRUE(v)) ? 1 : 0; 7 0 7
RETVAL = (v && SvTRUE(v)) ? 1 : 0; 5 2 7
RETVAL = (v && SvTRUE(v)) ? 1 : 0; 0 7 7
42 }
43 OUTPUT:
44 RETVAL
45  
46 MODULE = Punk PACKAGE = Punk::Model::DBI
47  
48 # _txn(\%opts, $code, $tx): begin_work, the block, commit - or rollback and
49 # rethrow. Returns the block's value.
50 SV *
51 _txn(class, opts, code, tx)
52 SV *class
53 SV *opts
54 SV *code
55 SV *tx
56 CODE:
57 PERL_UNUSED_VAR(class);
58 11 RETVAL = ptx_dbi_run(aTHX_ opts, code, tx);
59 OUTPUT:
60 RETVAL
61  
62 MODULE = Punk PACKAGE = Punk::Model::DBIx::Loop
63  
64 # _txn(\%opts, $code, $tx): $db->txn with the bridge. Returns a Punk::Future
65 # of the block's value, resolved after COMMIT.
66 SV *
67 _txn(class, opts, code, tx)
68 SV *class
69 SV *opts
70 SV *code
71 SV *tx
72 CODE:
73 PERL_UNUSED_VAR(class);
74 7 RETVAL = ptx_loop_run(aTHX_ opts, code, tx);
75 OUTPUT:
76 RETVAL
77  
78 MODULE = Punk PACKAGE = Punk::Context
79  
80 # txn($code) / txn($name => $code): a transaction on the named (or default)
81 # database; see Punk::Txn.
82 SV *
83 txn(self, ...)
84 SV *self
85 CODE:
86 {
87 20 SV *name = &PL_sv_undef, *code = &PL_sv_undef;
88 20 ▶ if (items == 2) code = ST(1);
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) code = ST(1); 17 3 20
89 3 ▶ else if (items == 3) { name = ST(1); code = ST(2); }
Branch: 1 branch
BranchTrueFalseTotal
else if (items == 3) { name = ST(1); code = ST(2); } 3 0 3
90 0 else croak("Punk::Txn: txn takes a coderef, or a database name and a "
91 "coderef");
92 20 RETVAL = ptx_context_txn(aTHX_ self, name, code);
93 }
94 OUTPUT:
95 RETVAL
« include/punk/punk_mpstream.h ↑ Summary include/punk/punk_state.h »