| 1 | package IO::Async::Pg::PubSub; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use parent 'IO::Async::Notifier'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use IO::Async::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | my $self = bless { | ||||||||||||||||||||||||||||
| 14 | conn => undef, | ||||||||||||||||||||||||||||
| 15 | pool => $args{pool}, | ||||||||||||||||||||||||||||
| 16 | 2 | channels => {}, # channel => [callbacks] | |||||||||||||||||||||||||||
| 17 | connected => 0, | ||||||||||||||||||||||||||||
| 18 | _handle => undef, | ||||||||||||||||||||||||||||
| 19 | }, $class; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Accessors | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub is_connected { shift->{connected} } | ||||||||||||||||||||||||||
|
Subroutine
is_connected: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub subscribed_channels { scalar keys %{shift->{channels}} } | ||||||||||||||||||||||||||
|
Subroutine
subscribed_channels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Validate channel name to prevent injection | ||||||||||||||||||||||||||||
| 29 | 7 | ▶ | sub _validate_channel { | ||||||||||||||||||||||||||
|
Subroutine
_validate_channel: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 30 | 7 | my ($self, $channel) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 7 | ▶ | return 0 unless defined $channel && length $channel; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $channel and length $channel
MC/DC50%1/2
defined $channel and length $channel
defined $channel
length $channel
Truth table66%2/3
A and B
A= defined $channelB= length $channel
| |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return 0 if $channel =~ /[\s;'"\\]/; # No whitespace, semicolon, quotes, backslash | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | return 0 if $channel =~ /[\x00-\x1f]/; # No control characters | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3 | return 1; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Connect to the database for listening | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | async sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return if $self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $pool = $self->{pool} or die "No pool configured"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Get a dedicated connection for listening | ||||||||||||||||||||||||||||
| 47 | 0 | $self->{conn} = await $pool->connection; | |||||||||||||||||||||||||||
| 48 | 0 | $self->{connected} = 1; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Set up socket watching | ||||||||||||||||||||||||||||
| 51 | 0 | $self->_setup_socket_watcher; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | return $self; | |||||||||||||||||||||||||||
| 54 | 1 | } | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Subscribe to a channel | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | async sub subscribe { | ||||||||||||||||||||||||||
|
Subroutine
subscribe: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my ($self, $channel, $callback) = @_; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | die "Invalid channel name: $channel" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | unless $self->_validate_channel($channel); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Ensure connected | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | await $self->connect unless $self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Add callback to list | ||||||||||||||||||||||||||||
| 67 | 0 | push @{$self->{channels}{$channel}}, $callback; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # If first subscription to this channel, send LISTEN | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (@{$self->{channels}{$channel}} == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | await $self->{conn}->query("LISTEN $channel"); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | return $self; | |||||||||||||||||||||||||||
| 75 | 1 | } | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Unsubscribe from a channel | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | async sub unsubscribe { | ||||||||||||||||||||||||||
|
Subroutine
unsubscribe: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my ($self, $channel, $callback) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return unless exists $self->{channels}{$channel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | # Remove specific callback | ||||||||||||||||||||||||||||
| 85 | 0 | @{$self->{channels}{$channel}} = | |||||||||||||||||||||||||||
| 86 | 0 | grep { $_ != $callback } @{$self->{channels}{$channel}}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||
| 89 | # Remove all callbacks | ||||||||||||||||||||||||||||
| 90 | 0 | $self->{channels}{$channel} = []; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # If no more callbacks, send UNLISTEN | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (!@{$self->{channels}{$channel}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | delete $self->{channels}{$channel}; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($self->{conn}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | await $self->{conn}->query("UNLISTEN $channel"); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | return $self; | |||||||||||||||||||||||||||
| 102 | 1 | } | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Unsubscribe from all channels | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | async sub unsubscribe_all { | ||||||||||||||||||||||||||
|
Subroutine
unsubscribe_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | $self->{channels} = {}; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($self->{conn}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | await $self->{conn}->query("UNLISTEN *"); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return $self; | |||||||||||||||||||||||||||
| 115 | 1 | } | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # Publish/notify a channel | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | async sub notify { | ||||||||||||||||||||||||||
|
Subroutine
notify: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | my ($self, $channel, $payload) = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | die "Invalid channel name: $channel" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | unless $self->_validate_channel($channel); | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # We can use any connection for NOTIFY | ||||||||||||||||||||||||||||
| 125 | 0 | my $pool = $self->{pool}; | |||||||||||||||||||||||||||
| 126 | 0 | my $conn = $self->{conn}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if (!$conn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | # Get a temporary connection | ||||||||||||||||||||||||||||
| 130 | 0 | $conn = await $pool->connection; | |||||||||||||||||||||||||||
| 131 | 0 | eval { | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | if (defined $payload) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | await $conn->query("NOTIFY $channel, \$1", $payload); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||
| 136 | 0 | await $conn->query("NOTIFY $channel"); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||
| 139 | 0 | my $err = $@; | |||||||||||||||||||||||||||
| 140 | 0 | $conn->release; | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | die $err if $err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (defined $payload) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | await $conn->query("NOTIFY $channel, \$1", $payload); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | 0 | await $conn->query("NOTIFY $channel"); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | return $self; | |||||||||||||||||||||||||||
| 153 | 1 | } | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # Set up socket watcher for incoming notifications | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub _setup_socket_watcher { | ||||||||||||||||||||||||||
|
Subroutine
_setup_socket_watcher: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 157 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $conn = $self->{conn} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $dbh = $conn->dbh or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | my $socket_fd = $dbh->{pg_socket}; | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | return unless defined $socket_fd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my $handle; | |||||||||||||||||||||||||||
| 166 | $handle = IO::Async::Handle->new( | ||||||||||||||||||||||||||||
| 167 | read_fileno => $socket_fd, | ||||||||||||||||||||||||||||
| 168 | want_readready => 1, | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | on_read_ready => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 170 | 0 | $self->_process_notifications; | |||||||||||||||||||||||||||
| 171 | }, | ||||||||||||||||||||||||||||
| 172 | 0 | ); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | $self->{_handle} = $handle; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if (my $loop = $self->loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | $loop->add($handle); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # Process incoming notifications | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub _process_notifications { | ||||||||||||||||||||||||||
|
Subroutine
_process_notifications: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 183 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $conn = $self->{conn} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $dbh = $conn->dbh or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # Check for notifications | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | while (my $notification = $dbh->pg_notifies) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | my ($channel, $pid, $payload) = @$notification; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # Call all registered callbacks for this channel | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if (my $callbacks = $self->{channels}{$channel}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | for my $cb (@$callbacks) { | |||||||||||||||||||||||||||
| 195 | 0 | eval { $cb->($channel, $payload, $pid) }; | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | warn "PubSub callback error for $channel: $@"; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # Override to add handle to loop | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub _add_to_loop { | ||||||||||||||||||||||||||
|
Subroutine
_add_to_loop: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 206 | 0 | my ($self, $loop) = @_; | |||||||||||||||||||||||||||
| 207 | 0 | $self->SUPER::_add_to_loop($loop); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if (my $handle = $self->{_handle}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | $loop->add($handle) unless $handle->loop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # Override to remove handle from loop | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub _remove_from_loop { | ||||||||||||||||||||||||||
|
Subroutine
_remove_from_loop: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 216 | 0 | my ($self, $loop) = @_; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (my $handle = $self->{_handle}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $loop->remove($handle) if $handle->loop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | $self->SUPER::_remove_from_loop($loop); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # Disconnect and cleanup | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | async sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return unless $self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # Remove socket watcher | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (my $handle = $self->{_handle}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (my $loop = $handle->loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | $loop->remove($handle); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 0 | $self->{_handle} = undef; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # UNLISTEN all | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($self->{conn}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | eval { await $self->{conn}->query("UNLISTEN *") }; | |||||||||||||||||||||||||||
| 242 | 0 | $self->{conn}->release; | |||||||||||||||||||||||||||
| 243 | 0 | $self->{conn} = undef; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | $self->{channels} = {}; | |||||||||||||||||||||||||||
| 247 | 0 | $self->{connected} = 0; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | return $self; | |||||||||||||||||||||||||||
| 250 | 1 | } | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=5 SCAR=21.7
| |||||||||||||||||||||||||||||
| 253 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 2 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | # Synchronous cleanup only | ||||||||||||||||||||||||||||
| 258 | 2 | ▶ | if (my $handle = $self->{_handle}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if (my $loop = $handle->loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | $loop->remove($handle); | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 2 | ▶ | if (my $conn = $self->{conn}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | $conn->release; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 1 | 1; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | __END__ | ||||||||||||||||||||||||||||