EV.pm

filter: Statementstmt 100% 11 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 14 / 14 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« EV/TransactionContext.pm ↑ Summary
1 package DBIO::PostgreSQL::EV;
2 2 our $VERSION = '0.900001';
3 # ABSTRACT: Async PostgreSQL storage for DBIO via EV::Pg
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 2 1;
12  
13 __END__
14  
15 =pod
16  
17 =encoding UTF-8
18  
19 =head1 NAME
20  
21 DBIO::PostgreSQL::EV - Async PostgreSQL storage for DBIO via EV::Pg
22  
23 =head1 VERSION
24  
25 version 0.900001
26  
27 =head1 SYNOPSIS
28  
29 package MyApp::Schema;
30 use base 'DBIO::Schema';
31 __PACKAGE__->load_components(qw(PostgreSQL PostgreSQL::EV));
32  
33 package MyApp::Schema::Result::Artist;
34 use base 'DBIO::Core';
35 __PACKAGE__->load_components('PostgreSQL');
36 __PACKAGE__->table('artist');
37 __PACKAGE__->add_columns(qw( id name ));
38  
39 # Async is opt-in per connection
40 my $schema = MyApp::Schema->connect(
41 'dbi:Pg:dbname=myapp', $user, $pass,
42 { async => 'ev' },
43 );
44 my $storage = $schema->storage; # DBIO::PostgreSQL::Storage
45  
46 # Sync still works exactly as before
47 my @all = $schema->resultset('Artist')->all;
48  
49 # Storage-level async runs real non-blocking over EV::Pg
50 $storage->select_async($source, $select, $where, $attrs)->then(sub {
51 my @rows = @_;
52 ...
53 });
54  
55 # Pipeline mode, LISTEN/NOTIFY and COPY are async-only — not routed
56 # through the sync storage. Reach them on the embedded async backend
57 # via $storage->async (see DBIO::PostgreSQL::EV::Storage):
58 $storage->async->listen('changelog', sub { my ($chan, $payload) = @_; ... });
59 $storage->async->copy_in('artist', [qw( id name )], sub { my $put = shift; ... });
60  
61 =head1 DESCRIPTION
62  
63 Real async PostgreSQL for DBIO via L<EV::Pg>, a non-blocking client built on
64 libpq's async protocol. The async work itself lives in
65 L<DBIO::PostgreSQL::EV::Storage>.
66  
67 This module is an B<inert marker component>. Loading it via
68 C<< load_components('PostgreSQL::EV') >> does B<not> by itself switch the
69 storage to async: it only tags the schema so the L<DBIO::PostgreSQL::Storage>
70 MRO arm can resolve the C<ev> mode. Async is an explicit, per-connection
71 choice (ADR 0030); you opt in at C<connect> time with
72 C<< { async => 'ev' } >>:
73  
74 my $schema = MyApp::Schema->connect(
75 $dsn, $user, $pass,
76 { async => 'ev' },
77 );
78  
79 The C<ev> mode resolves to L<DBIO::PostgreSQL::EV::Storage> (this
80 distribution) and is registered by L<DBIO::PostgreSQL::Storage> (the sync
81 driver, in the L<DBIO::PostgreSQL> distribution). With C<{ async => 'ev' }>
82 on a schema that has loaded this component, C<< $rs->all >> still runs sync
83 over DBI/DBD::Pg, while the storage-level C<*_async> methods run B<real>
84 async over EV::Pg against the same connection info.
85  
86 Without the opt-in, the C<*_async> methods degrade to the universal forked
87 fallback (L<DBIO::Forked::Storage>, core ADR 0029); no compile-time dependency
88 on EV is added to the sync driver.
89  
90 =head1 EVENT LOOP COMPATIBILITY
91  
92 L<EV::Pg> uses the L<EV> event loop. This works with:
93  
94 =over 4
95  
96 =item * L<EV> directly
97  
98 =item * L<AnyEvent> (uses EV as backend when available)
99  
100 =item * L<IO::Async> via L<IO::Async::Loop::EV>
101  
102 =item * L<Mojolicious> via L<Mojo::Reactor::EV>
103  
104 =back
105  
106 =head1 AUTHOR
107  
108 DBIO Authors
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 Copyright (C) 2026 DBIO Authors
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
« EV/TransactionContext.pm ↑ Summary