| 1 | package DBIO::PostgreSQL::Async::Pool; | ||
| 2 | # ABSTRACT: EV::Pg connection pool for DBIO | ||
| 3 | |||
| 4 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 5 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 5 | ▶ | use base 'DBIO::Storage::PoolBase'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 5 | ▶ | use DBIO::PostgreSQL::Async::ConnectInfo 'conninfo_string'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | sub _create_connection { | ||
| 13 | 0 | ▶ | my ($self, $conninfo) = @_; |
|
Subroutine
_create_connection: not called CC=1 SCAR=6.9
| |||
| 14 | |||
| 15 | 0 | require EV::Pg; | |
| 16 | return EV::Pg->new( | ||
| 17 | conninfo => $conninfo, | ||
| 18 | ▶ | on_connect => sub {}, | |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||
| 19 | on_error => $self->{on_error}, | ||
| 20 | 0 | ); | |
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | 1 | ▶ | sub _shutdown_connection { $_[1]->finish } |
|
Subroutine
_shutdown_connection: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | |||
| 27 | 1 | ▶ | sub _transform_conninfo { conninfo_string($_[1]) } |
|
Subroutine
_transform_conninfo: called CC=1 SCAR=0.0
| |||
| 28 | |||
| 29 | 5 | 1; | |
| 30 | |||
| 31 | __END__ | ||
| 32 | |||
| 33 | =pod | ||
| 34 | |||
| 35 | =encoding UTF-8 | ||
| 36 | |||
| 37 | =head1 NAME | ||
| 38 | |||
| 39 | DBIO::PostgreSQL::Async::Pool - EV::Pg connection pool for DBIO | ||
| 40 | |||
| 41 | =head1 VERSION | ||
| 42 | |||
| 43 | version 0.900000 | ||
| 44 | |||
| 45 | =head1 SYNOPSIS | ||
| 46 | |||
| 47 | my $pool = DBIO::PostgreSQL::Async::Pool->new( | ||
| 48 | conninfo => 'dbname=myapp', | ||
| 49 | size => 10, | ||
| 50 | on_error => sub { warn $_[0] }, | ||
| 51 | ); | ||
| 52 | |||
| 53 | my $pg = $pool->acquire; # get idle connection | ||
| 54 | $pool->release($pg); # return to pool | ||
| 55 | my $pg = $pool->acquire_txn; # pinned for transaction | ||
| 56 | |||
| 57 | =head1 DESCRIPTION | ||
| 58 | |||
| 59 | Connection pool for L<DBIO::PostgreSQL::Async::Storage>. Manages a pool of | ||
| 60 | L<EV::Pg> connections, dispatching queries to available connections | ||
| 61 | and queuing when all are busy. | ||
| 62 | |||
| 63 | The acquire / release / capacity / shutdown mechanics are inherited from | ||
| 64 | L<DBIO::Storage::PoolBase>; this class supplies only the EV::Pg | ||
| 65 | seam — see L</_create_connection>, L</_shutdown_connection> and | ||
| 66 | L</_transform_conninfo>. | ||
| 67 | |||
| 68 | =head1 METHODS | ||
| 69 | |||
| 70 | =head2 _create_connection | ||
| 71 | |||
| 72 | Builds one L<EV::Pg> connection from the (already-transformed) | ||
| 73 | connect info. The pool tracks the returned connection — do not | ||
| 74 | push it onto L</_connections> yourself. | ||
| 75 | |||
| 76 | =head2 _shutdown_connection | ||
| 77 | |||
| 78 | Closes one L<EV::Pg> connection during L<DBIO::Storage::PoolBase/shutdown>. | ||
| 79 | Errors are swallowed by the caller. | ||
| 80 | |||
| 81 | =head2 _transform_conninfo | ||
| 82 | |||
| 83 | Renders the stored connect info as a libpq conninfo string via | ||
| 84 | L<DBIO::PostgreSQL::Async::ConnectInfo/conninfo_string>. Accepts a | ||
| 85 | hashref, arrayref, or string and returns a single conninfo string. | ||
| 86 | |||
| 87 | =head1 AUTHOR | ||
| 88 | |||
| 89 | DBIO Authors | ||
| 90 | |||
| 91 | =head1 COPYRIGHT AND LICENSE | ||
| 92 | |||
| 93 | Copyright (C) 2026 DBIO Authors | ||
| 94 | |||
| 95 | This is free software; you can redistribute it and/or modify it under | ||
| 96 | the same terms as the Perl 5 programming language system itself. | ||
| 97 | |||
| 98 | =cut | ||