RedisTop/Redis.pm

filter: Statementstmt 14.9% 10 / 67 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 7 totaltotal 11.2% 13 / 116 CC 19 SCAR 32.9
CC
19
Cov
10%
new
42.0
command
42.0
row_parser
30.0
CRAP 26.9
↑ Summary RedisTop/PerformStat.pm »
1 package App::RedisTop::Redis;
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 IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
8 0 my $class = shift;
9 0 my (%args) = @_;
10  
11 0 ▶ my $host = $args{host} || '127.0.0.1';
Condition0%0/2
$args{'host'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
$args{'host'} || '127.0.0.1'
$args{'host'}
Truth table0%0/2
A
A= $args{'host'}
Aresult
11
00
12 0 ▶ my $port = $args{port} || '6379';
Condition0%0/2
$args{'port'} || '6379'
l!l
00
MC/DC0%0/1
$args{'port'} || '6379'
$args{'port'}
Truth table0%0/2
A
A= $args{'port'}
Aresult
11
00
13 0 my $pass = $args{pass};
14  
15 0 my $server = "$host:$port";
16 0 ▶ my $s = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
my $s = "IO::Socket::INET"->new("PeerAddr", $server, "Proto", "tcp") or die "[$server] socket connect error: $!" 0 0 0
17 PeerAddr => $server,
18 Proto => 'tcp',
19 ) or die "[$server] socket connect error: $!";
20  
21 # auth
22 0 ▶ if ($pass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass) 0 0 0
23 0 $s->print("AUTH $pass \r\n");
24 0 ▶ <$s> || die "[$server] socket auth error: $!";
Branch: 1 branch
BranchTrueFalseTotal
readline $s or die "[$server] socket auth error: $!" 0 0 0
25 }
26  
27 0 my $self = bless {
28 socket => $s,
29 }, $class;
30 0 $self;
31 }
32  
33 0 ▶sub info {
Subroutine info: not called CC=4 SCAR=30.0
Pod undocumented
34 0 my ($self) = @_;
35  
36 0 my $buf = $self->command('INFO');
37  
38 0 my $stats = {};
39 0 for my $row (split(/\r\n/, $buf)) {
40 0 ▶ next if $row =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $row =~ /^#/ 0 0 0
41 0 ▶ next if $row =~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if $row =~ /^$/ 0 0 0
42 0 my ($key, $val) = split(/:/, $row);
43 0 $stats->{$key} = $val;
44 }
45  
46 0 return $stats;
47 }
48  
49 0 ▶sub config {
Subroutine config: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my ($self) = @_;
51 0 return $self->command("CONFIG", "GET", "*");
52 }
53  
54 0 ▶sub slowlog {
Subroutine slowlog: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my ($self) = @_;
56 0 return $self->command("SLOWLOG", "LEN");
57 }
58  
59 0 ▶sub command {
Subroutine command: not called CC=6 SCAR=37.4
Pod undocumented
60 0 my ($self, @command) = @_;
61  
62 0 my $s = $self->{socket};
63 0 my $req = $self->request(@command);
64  
65 0 $s->send($req);
66  
67 0 my $ret = $s->recv( my $buffer, 131072 );
68 0 my @lines = split(/\r\n/, $buffer);
69 0 my $header = $self->row_parser($lines[0]);
70 0 ▶ return $buffer if $header->{type} eq 'itemlen';
Branch: 1 branch
BranchTrueFalseTotal
if $header->{"type"} eq "itemlen" 0 0 0
71 0 ▶ return $header->{value} if $header->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $header->{"type"} eq "number" 0 0 0
72  
73 0 my %stats = ();
74 0 my $key;
75  
76 0 for my $line (@lines) {
77 0 my $row = $self->row_parser($line);
78 0 ▶ if($row->{type} eq 'line') {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"type"} eq "line") 0 0 0
79 0 ▶ unless($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 0 0 0
80 0 $key = $row->{value};
81 } else {
82 0 $stats{$key} = $row->{value};
83 0 $key = undef;
84 }
85 }
86 }
87  
88 0 return \%stats;
89 }
90  
91 0 ▶sub row_parser {
Subroutine row_parser: not called CC=5 SCAR=34.0
Pod undocumented
92 0 my ($self, $row) = @_;
93  
94 0 ▶ if($row =~ /^(\*|\$|\:)+(\w+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ /^(\*|\$|\:)+(\w+)/) 0 0 0
95 0 ▶ if($1 eq '*') { # header
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq '*') { } 0 0 0
elsif ($1 eq '$') { } 0 0 0
elsif ($1 eq ':') { } 0 0 0
96 return {
97 0 type => 'rowlen',
98 value => $2,
99 };
100 } elsif($1 eq '$') { # next length
101 return {
102 0 type => 'itemlen',
103 value => $2,
104 };
105 } elsif($1 eq ':') { # number
106 return {
107 0 type => 'number',
108 value => $2,
109 };
110 }
111 }
112  
113 0 $row =~ s/\r\n//;
114 return {
115 0 type => 'line',
116 value => $row,
117 }
118 }
119  
120 0 ▶sub request {
Subroutine request: not called CC=2 SCAR=17.9
Pod undocumented
121 0 my ($self, @args) = @_;
122  
123 0 my $nl = "\015\012";
124 0 my $req = sprintf('*%d%s', scalar(@args), $nl);
125 0 $req .= sprintf('$%d%s%s%s', length($_), $nl, $_, $nl) for @args;
126 0 return $req;
127 }
128  
129 1 1;
↑ Summary RedisTop/PerformStat.pm »