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