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/Node.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 = '2.004_001'; # TRIAL 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 sub info {
30 0 ▶ my ($self) = @_;
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
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 sub age {
55 0 ▶ my ($self) = @_;
Subroutine age: not called CC=1 SCAR=6.9
Pod undocumented
56 0 $self->server->time - $self->created_at
57 }
58  
59 sub idle_time {
60 0 ▶ my ($self) = @_;
Subroutine idle_time: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶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 sub on_close {
79 0 ▶ my ($self) = @_;
Subroutine on_close: not called CC=1 SCAR=6.9
Pod undocumented
80 0 $log->infof('Closing server connection');
81 0 $self->server->client_disconnect($self);
82 }
83  
84 sub protocol {
85 0 ▶ my ($self) = @_;
Subroutine protocol: not called CC=2 SCAR=17.9
Pod undocumented
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 sub on_read {
95 0 ▶ my ($self, $stream, $buffref, $eof) = @_;
Subroutine on_read: not called CC=2 SCAR=17.9
Pod undocumented
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 sub on_message {
102 0 ▶ my ($self, $msg) = @_;
Subroutine on_message: not called CC=2 SCAR=17.9
Pod undocumented
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 (
111 $code
112 ? $code->($db, @data)
113 : Future->done(qq{ERR unknown command '$command'})
114 )->then(sub {
115 0 ▶ my $data = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 $self->stream->write(
117 $self->protocol->encode($data)
118 )
119 }, sub {
120 0 ▶ my $err = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 $self->stream->write(
122 $self->protocol->encode(
123 qq{ERR failed to process '$command' - $err}
124 )
125 );
126 0 ▶ })->retain;
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 0 0 0
127 }
128  
129 sub db {
130 0 ▶ my ($self) = @_;
Subroutine db: not called CC=2 SCAR=17.9
Pod undocumented
131 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
132 server => $self->server
133 )
134 }
135  
136 0 ▶sub server { shift->{server} }
Subroutine server: not called CC=1 SCAR=6.9
Pod undocumented
137  
138 sub configure {
139 0 ▶ my ($self, %args) = @_;
Subroutine configure: not called CC=6 SCAR=37.4
Pod documented
140 0 ▶ if(exists $args{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"stream"}) 0 0 0
141 0 my $stream = delete $args{stream};
142 0 $self->add_child($stream);
143 0 Scalar::Util::weaken($self->{stream} = $stream);
144 0 $stream->configure(
145 on_closed => $self->curry::weak::on_close,
146 on_read => $self->curry::weak::on_read,
147 );
148 }
149 0 for (qw(server)) {
150 0 ▶ Scalar::Util::weaken($self->{$_} = delete $args{$_}) if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
151 }
152 0 for (qw(protocol id created_at)) {
153 0 ▶ $self->{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
154 }
155 0 return $self->next::method(%args);
156 }
157  
158 sub AUTOLOAD {
159 0 ▶ my ($self, @args) = @_;
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
160 0 my ($method) = our $AUTOLOAD =~ /::([^:]+)$/;
161 0 my $cmd = uc $method;
162 0 ▶ if(Net::Async::Redis::Commands->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Net::Async::Redis::Commands"->can($method)) 0 0 0
163 0 $cmd =~ tr/_/ /;
164 0 return $self->request->reply(ERR => 'Unimplemented command ' . $cmd);
165 }
166 0 return $self->request->reply(ERR => 'Unknown command ' . $cmd);
167 }
168  
169 1 1;
170  
171 =head1 AUTHOR
172  
173 Tom Molesworth C<< <TEAM@cpan.org> >> plus contributors as mentioned in
174 L<Net::Async::Redis/CONTRIBUTORS>.
175  
176 =head1 LICENSE
177  
178 Copyright Tom Molesworth 2015-2020. Licensed under the same terms as Perl itself.
179  
« Redis/Cluster/Node.pm ↑ Summary Redis/Subscription/Message.pm »