EV/TransactionContext.pm

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