| 1 | package DBIO::MySQL::Async::QueryExecutor; | ||||||||||||||||||||||||
| 2 | # ABSTRACT: Query execution wrapper for DBIO MySQL async storage | ||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||
| 7 | 1 | ▶ | use Future; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||
| 12 | 8 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||
| 13 | 8 | ▶ | croak 'pool is required' unless $args{pool}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||
| 15 | 8 | ▶ | my $debug = $args{debug} // $ENV{DBIO_TRACE} // 0; | ||||||||||||||||||||||
|
Condition40%2/5
($args{"debug"} // $ENV{"DBIO_TRACE"}) // 0
$args{"debug"} // $ENV{"DBIO_TRACE"}
MC/DC0%0/2
($args{"debug"} // $ENV{"DBIO_TRACE"}) // 0
$args{"debug"}
$ENV{"DBIO_TRACE"}
Truth table33%1/3
A // B
A= $args{"debug"}B= $ENV{"DBIO_TRACE"}
| |||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||
| 17 | bless { | ||||||||||||||||||||||||
| 18 | pool => $args{pool}, | ||||||||||||||||||||||||
| 19 | 8 | debug => $debug, | |||||||||||||||||||||||
| 20 | }, $class; | ||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||
| 24 | sub execute { | ||||||||||||||||||||||||
| 25 | 9 | ▶ | my ($self, $mdb, $sql, $bind) = @_; | ||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||
| 26 | 9 | ▶ | $bind //= []; | ||||||||||||||||||||||
|
Condition50%1/2
$bind //= []
MC/DC0%0/1
$bind //= []
$bind
Truth table50%1/2
A
A= $bind
| |||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 9 | ▶ | $self->_debug_query($sql, $bind) if $self->{debug}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||
| 30 | 9 | my $f = Future->new; | |||||||||||||||||||||||
| 31 | $mdb->query($sql, sub { | ||||||||||||||||||||||||
| 32 | 9 | ▶ | my ($rows, $err) = @_; | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||
| 33 | 9 | ▶ | if ($err) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 34 | 1 | $f->fail($err); | |||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||
| 36 | 8 | ▶ | $f->done(ref $rows eq 'ARRAY' ? @$rows : $rows); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||
| 38 | 9 | }); | |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 9 | return $f; | |||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | sub _debug_query { | ||||||||||||||||||||||||
| 44 | 0 | ▶ | my ($self, $sql, $bind) = @_; | ||||||||||||||||||||||
|
Subroutine
_debug_query: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 45 | 0 | ▶ | my $bind_str = join(', ', map { defined $_ ? "'$_'" : 'NULL' } @$bind); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 46 | 0 | warn "$sql: $bind_str\n"; | |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | 1 | 1; | |||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | =pod | ||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | =encoding UTF-8 | ||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | =head1 NAME | ||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||
| 59 | DBIO::MySQL::Async::QueryExecutor - Query execution wrapper for DBIO MySQL async storage | ||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||
| 61 | =head1 VERSION | ||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||
| 63 | version 0.900000 | ||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||
| 67 | Wraps a connection pool and provides a single C<execute($conn, $sql, $bind)> | ||||||||||||||||||||||||
| 68 | interface for query execution. Handles bind attribute policy and returns | ||||||||||||||||||||||||
| 69 | a L<Future> with the result rows. | ||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||
| 71 | Separated from Storage to allow independent testing of query execution | ||||||||||||||||||||||||
| 72 | logic from connection pooling and transaction orchestration. | ||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||
| 74 | =head1 METHODS | ||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||
| 76 | =head2 execute | ||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||
| 78 | my $future = $executor->execute($mdb, $sql, $bind); | ||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | Execute a query on a given L<EV::MariaDB> connection. Returns a L<Future> | ||||||||||||||||||||||||
| 81 | that resolves with the result rows (array or arrayref). | ||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||
| 83 | =head1 AUTHOR | ||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||
| 85 | DBIO Authors | ||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||
| 87 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||
| 89 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||
| 91 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||
| 92 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||