Async/TransactionContext.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran n/a Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.8% 23 / 24 Podpod 21.0% 4 / 19 totaltotal 78.5% 77 / 98 CC 3 SCAR 2.7
CC
3
Cov
94%
new
3.3
storage
2.0
BEGIN
1.0
CRAP 1.3
« Async/Pool.pm ↑ Summary Async.pm »
1 package DBIO::MySQL::Async::TransactionContext;
2 # ABSTRACT: Pinned connection context for an async MySQL/MariaDB transaction
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Future ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 1 ▶ my ($class, %args) = @_;
Subroutine new: called CC=3 SCAR=12.0
Pod undocumented
11 return bless {
12 storage => $args{storage} // die('storage required'),
13 1 ▶ mdb => $args{mdb} // die('mdb required'),
Condition50%2/4
$args{"storage"} // die("storage required")
l!l
10
$args{"mdb"} // die("mdb required")
l!l
10
MC/DC0%0/1
$args{"storage"} // die("storage required")
$args{"storage"}
MC/DC0%0/1
$args{"mdb"} // die("mdb required")
$args{"mdb"}
Truth table50%1/2
A
A= $args{"storage"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"mdb"}
Aresult
11
00
14 }, $class;
15 }
16  
17  
18 0 ▶sub storage { $_[0]->{storage} }
Subroutine storage: not called CC=1 SCAR=6.9
Pod documented
19  
20  
21 1 ▶sub txn_mdb { $_[0]->{mdb} }
Subroutine txn_mdb: called CC=1 SCAR=0.0
Pod documented
22  
23  
24 1 ▶sub pool { $_[0]->{storage}->pool }
Subroutine pool: called CC=1 SCAR=0.0
Pod documented
25  
26  
27 2 ▶sub in_txn { 1 }
Subroutine in_txn: called CC=1 SCAR=0.0
Pod documented
28  
29  
30 sub _query_async {
31 1 ▶ my ($self, $sql, $bind) = @_;
Subroutine _query_async: called CC=1 SCAR=0.0
32 1 return $self->{storage}->_query_async_pinned($self->{mdb}, $sql, $bind);
33 }
34  
35 # Explicit delegation of the public API. The autoloaded version was
36 # fragile: it silently forwarded typos, bypassing can() and method
37 # checks. Each method below is the contract a txn_do_async callback
38 # is allowed to call on the context.
39 #
40 # CRUD inside a transaction MUST run on the pinned connection that
41 # BEGIN/COMMIT ran on, not a fresh pooled one. Each CRUD method routes
42 # through the storage's shared CRUD builder with the pinned connection
43 # (txn_mdb), so SQL generation (insert + LAST_INSERT_ID, select_single
44 # first-row) is not duplicated. Forwarding to $storage->select_async etc.
45 # would acquire a separate pool connection and run the query OUTSIDE the
46 # transaction.
47  
48 2 ▶sub select_async { my $s = shift; $s->{storage}->_run_crud_pinned('select', $s->{mdb}, @_) }
Subroutine select_async: called CC=1 SCAR=0.0
Pod undocumented
49 2 ▶sub select_single_async { my $s = shift; $s->{storage}->_run_crud_pinned('select_single', $s->{mdb}, @_) }
Subroutine select_single_async: called CC=1 SCAR=0.0
Pod undocumented
50 2 ▶sub insert_async { my $s = shift; $s->{storage}->_run_crud_pinned('insert', $s->{mdb}, @_) }
Subroutine insert_async: called CC=1 SCAR=0.0
Pod undocumented
51 2 ▶sub update_async { my $s = shift; $s->{storage}->_run_crud_pinned('update', $s->{mdb}, @_) }
Subroutine update_async: called CC=1 SCAR=0.0
Pod undocumented
52 2 ▶sub delete_async { my $s = shift; $s->{storage}->_run_crud_pinned('delete', $s->{mdb}, @_) }
Subroutine delete_async: called CC=1 SCAR=0.0
Pod undocumented
53 1 ▶sub select { my $s = shift; $s->select_async(@_)->get }
Subroutine select: called CC=1 SCAR=0.0
Pod undocumented
54 1 ▶sub select_single { my $s = shift; $s->select_single_async(@_)->get }
Subroutine select_single: called CC=1 SCAR=0.0
Pod undocumented
55 1 ▶sub insert { my $s = shift; $s->insert_async(@_)->get }
Subroutine insert: called CC=1 SCAR=0.0
Pod undocumented
56 1 ▶sub update { my $s = shift; $s->update_async(@_)->get }
Subroutine update: called CC=1 SCAR=0.0
Pod undocumented
57 1 ▶sub delete { my $s = shift; $s->delete_async(@_)->get }
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
58 1 ▶sub sql_maker { my $s = shift; $s->{storage}->sql_maker(@_) }
Subroutine sql_maker: called CC=1 SCAR=0.0
Pod undocumented
59 1 ▶sub debug { my $s = shift; $s->{storage}->debug(@_) }
Subroutine debug: called CC=1 SCAR=0.0
Pod undocumented
60 1 ▶sub pipeline { my $s = shift; $s->{storage}->pipeline(@_) }
Subroutine pipeline: called CC=1 SCAR=0.0
Pod undocumented
61 1 ▶sub txn_do_async { my $s = shift; $s->{storage}->txn_do_async(@_) }
Subroutine txn_do_async: called CC=1 SCAR=0.0
Pod undocumented
62  
63 1 1;
64  
65 __END__
66  
67 =pod
68  
69 =encoding UTF-8
70  
71 =head1 NAME
72  
73 DBIO::MySQL::Async::TransactionContext - Pinned connection context for an async MySQL/MariaDB transaction
74  
75 =head1 VERSION
76  
77 version 0.900000
78  
79 =head1 ATTRIBUTES
80  
81 =head2 storage
82  
83 The parent L<DBIO::MySQL::Async::Storage> instance.
84  
85 =head2 txn_mdb
86  
87 The pinned L<EV::MariaDB> connection handle for the duration of this transaction.
88  
89 =head2 pool
90  
91 Shortcut to C<< $self->storage->pool >>.
92  
93 =head2 in_txn
94  
95 Always true — indicates we are inside a transaction.
96  
97 =head1 METHODS
98  
99 =head2 _query_async
100  
101 Forwards query execution to the underlying storage using the pinned
102 transaction connection (C<txn_mdb>) via
103 L<DBIO::MySQL::Async::Storage/_query_async_pinned> (no release).
104  
105 =head1 AUTHOR
106  
107 DBIO Authors
108  
109 =head1 COPYRIGHT AND LICENSE
110  
111 Copyright (C) 2026 DBIO Authors
112  
113 This is free software; you can redistribute it and/or modify it under
114 the same terms as the Perl 5 programming language system itself.
115  
116 =cut
« Async/Pool.pm ↑ Summary Async.pm »