Redis/Server/Connection.pm

filter: Statementstmt 29.5% 26 / 88 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 25.0% 8 / 32 Podpod 4.7% 1 / 21 totaltotal 20.3% 35 / 172 CC 14 SCAR 21.5
CC
14
Cov
23%
configure
42.0
info
6.0
database_index
6.0
CRAP 8.6
« Redis/Cluster.pm ↑ Summary Redis/Subscription/Message.pm »
1 package Net::Async::Redis::Server::Connection;
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  
6 1 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '6.006'; # VERSION
9  
10 =head1 NAME
11  
12 Net::Async::Redis::Server::Connection - represents a single connection to a server
13  
14 =head1 DESCRIPTION
15  
16 Best to wait until the 2.000 release for this one.
17  
18 =cut
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Net::Async::Redis::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Net::Async::Redis::Server::Database;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 0 ▶sub info {
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my ($self) = @_;
31 0 my $h = $self->stream->read_handle;
32 return {
33 0 ▶ id => $self->id,
Condition0%0/2
$self->multi_count // -1
l!l
00
MC/DC0%0/1
$self->multi_count // -1
$self->multi_count
Truth table0%0/2
A
A= $self->multi_count
Aresult
11
00
34 addr => join(':', $h->sockhost, $h->sockport),
35 fd => $h->fileno,
36 name => $self->name,
37 age => int($self->age / 1000),
38 idle => int($self->idle_time / 1000),
39 flags => 'N',
40 db => $self->database_index,
41 sub => $self->subscription_count,
42 psub => $self->psubscription_count,
43 multi => $self->multi_count // -1,
44 qbuf => 0,
45 'qbuf-free' => 32768,
46 obl => 0,
47 oll => 0,
48 omem => 0,
49 events => 'rw',
50 cmd => $self->last_command,
51 }
52 }
53  
54 0 ▶sub age {
Subroutine age: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my ($self) = @_;
56 0 $self->server->time - $self->created_at
57 }
58  
59 0 ▶sub idle_time {
Subroutine idle_time: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ($self) = @_;
61 0 $self->server->time - $self->last_command_at
62 }
63  
64 0 ▶sub created_at { shift->{created_at} }
Subroutine created_at: not called CC=1 SCAR=6.9
Pod undocumented
65 0 ▶sub last_command_at { shift->{last_command_at} }
Subroutine last_command_at: not called CC=1 SCAR=6.9
Pod undocumented
66 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
67 0 ▶sub name { shift->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
68 0 ▶sub database_index { shift->{database_index} //= 0 }
Subroutine database_index: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
(shift())->{"database_index"} //= 0
l!l
00
MC/DC0%0/1
(shift())->{"database_index"} //= 0
(shift())->{"database_index"}
Truth table0%0/2
A
A= (shift())->{"database_index"}
Aresult
11
00
69 0 ▶sub subscription_count { shift->{subscription_count} }
Subroutine subscription_count: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶sub psubscription_count { shift->{psubscription_count} }
Subroutine psubscription_count: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub multi_count { shift->{multi_count} }
Subroutine multi_count: not called CC=1 SCAR=6.9
Pod undocumented
72 0 ▶sub last_command { shift->{last_command} // '' }
Subroutine last_command: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
(shift())->{"last_command"} // ""
l!l
00
MC/DC0%0/1
(shift())->{"last_command"} // ""
(shift())->{"last_command"}
Truth table0%0/2
A
A= (shift())->{"last_command"}
Aresult
11
00
73  
74 0 ▶sub request { }
Subroutine request: not called CC=1 SCAR=0.0
Pod undocumented
75  
76 0 ▶sub stream { shift->{stream} }
Subroutine stream: not called CC=1 SCAR=6.9
Pod undocumented
77  
78 0 ▶sub on_close {
Subroutine on_close: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my ($self) = @_;
80 0 $log->tracef('Connection to server closing');
81 0 $self->server->client_disconnect($self);
82 }
83  
84 0 ▶sub protocol {
Subroutine protocol: not called CC=2 SCAR=17.9
Pod undocumented
85 0 my ($self) = @_;
86 0 ▶ $self->{protocol} ||= do {
Condition0%0/3
$$self{"protocol"} ||= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self{"protocol"} ||= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message) }
$$self{"protocol"} do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message) }
Truth table0%0/3
A ||= B
A= $$self{"protocol"}B= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message) }
ABresult
1X1
011
000
87 0 require Net::Async::Redis::Protocol;
88 0 Net::Async::Redis::Protocol->new(
89 handler => $self->curry::weak::on_message
90 )
91 };
92 }
93  
94 0 ▶sub on_read {
Subroutine on_read: not called CC=2 SCAR=17.9
Pod undocumented
95 0 my ($self, $stream, $buffref, $eof) = @_;
96 0 ▶ $log->tracef('Read %d bytes of data, EOF = %d', length($$buffref), $eof ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$eof ? : 0 0 0
97 0 $self->protocol->decode($buffref);
98 0 0
99 }
100  
101 0 ▶sub on_message {
Subroutine on_message: not called CC=2 SCAR=17.9
Pod undocumented
102 0 my ($self, $msg) = @_;
103 0 $log->debugf('Had message %s', $msg);
104 0 my ($command, @data) = @$msg;
105 0 my $db = $self->db;
106 0 my $code = $db->can(lc $command);
107 0 $self->{last_command} = $command;
108 0 $self->{last_command_at} = $self->server->time;
109 0 $log->tracef('Database method: %s', $code);
110 $self->adopt_future(
111 (
112 $code
113 ? $code->($db, @data)
114 : Future->done(qq{ERR unknown command '$command'})
115 0 ▶ )->then(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 my $data = shift;
117 0 $self->stream->write(
118 $self->protocol->encode($data)
119 )
120 0 ▶ }, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 my $err = shift;
122 0 $self->stream->write(
123 $self->protocol->encode(
124 qq{ERR failed to process '$command' - $err}
125 )
126 );
127 })
128 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 0 0 0
129 }
130  
131 0 ▶sub db {
Subroutine db: not called CC=2 SCAR=17.9
Pod undocumented
132 0 my ($self) = @_;
133 0 ▶ $self->{db} //= Net::Async::Redis::Server::Database->new(
Condition0%0/3
$$self{"db"} //= "Net::Async::Redis::Server::Database"->new("server", $self->server)
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self{"db"} //= "Net::Async::Redis::Server::Database"->new("server", $self->server)
$$self{"db"} "Net::Async::Redis::Server::Database"->new("server", $self->server)
Truth table0%0/3
A //= B
A= $$self{"db"}B= "Net::Async::Redis::Server::Database"->new("server", $self->server)
ABresult
1X1
011
000
134 server => $self->server
135 )
136 }
137  
138 0 ▶sub server { shift->{server} }
Subroutine server: not called CC=1 SCAR=6.9
Pod undocumented
139  
140 0 ▶sub configure {
Subroutine configure: not called CC=6 SCAR=37.4
Pod documented
141 0 my ($self, %args) = @_;
142 0 ▶ if(exists $args{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"stream"}) 0 0 0
143 0 my $stream = delete $args{stream};
144 0 $self->add_child($stream);
145 0 Scalar::Util::weaken($self->{stream} = $stream);
146 0 $stream->configure(
147 on_closed => $self->curry::weak::on_close,
148 on_read => $self->curry::weak::on_read,
149 );
150 }
151 0 for (qw(server)) {
152 0 ▶ Scalar::Util::weaken($self->{$_} = delete $args{$_}) if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
153 }
154 0 for (qw(protocol id created_at)) {
155 0 ▶ $self->{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
156 }
157 0 return $self->next::method(%args);
158 }
159  
160 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
161 0 my ($self, @args) = @_;
162 0 my ($method) = our $AUTOLOAD =~ /::([^:]+)$/;
163 0 my $cmd = uc $method;
164 0 ▶ if(Net::Async::Redis::Commands->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Net::Async::Redis::Commands"->can($method)) 0 0 0
165 0 $cmd =~ tr/_/ /;
166 0 return $self->request->reply(ERR => 'Unimplemented command ' . $cmd);
167 }
168 0 return $self->request->reply(ERR => 'Unknown command ' . $cmd);
169 }
170  
171 1 1;
172  
173 =head1 AUTHOR
174  
175 Tom Molesworth C<< <TEAM@cpan.org> >> plus contributors as mentioned in
176 L<Net::Async::Redis/CONTRIBUTORS>.
177  
178 =head1 LICENSE
179  
180 Copyright Tom Molesworth 2015-2024. Licensed under the same terms as Perl itself.
181  
« Redis/Cluster.pm ↑ Summary Redis/Subscription/Message.pm »