lib/ControlFreak/Util.pm

filter: Statementstmt 70.0% 35 / 50 Branchbran 31.2% 5 / 16 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 4 totaltotal 52.1% 49 / 94 CC 12 SCAR 26.6
CC
12
Cov
55%
parse_unix
42.0
get_sock_from_addr
12.0
exit_reason
4.0
CRAP 14.3
« lib/ControlFreak.pm ↑ Summary lib/ControlFreak/Socket.pm »
1 package ControlFreak::Util;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use IO::Socket::UNIX();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use IO::Socket::INET();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use POSIX();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Socket qw(SOCK_STREAM);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub parse_unix {
Subroutine parse_unix: not called CC=6 SCAR=37.4
Pod undocumented
11 0 ▶ my $address = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12  
13 0 ▶ if ($address =~ m!^unix:(.+)!) {
Branch: 3 branches
BranchTrueFalseTotal
if ($address =~ /^unix:(.+)/) { } 0 0 0
elsif ($address =~ m[^/]) { } 0 0 0
elsif ($address =~ m[^\w.*/] and not $address =~ /:/) { } 0 0 0
14 0 return $1;
15 }
16 elsif ($address =~ m!^/!) {
17 0 return $address;
18 }
19 ## relative path to a socket. This is bad, maybe I'd better ignore it?
20 ▶ elsif ($address =~ m!^\w.*/! && $address !~ m!:!) {
Condition0%0/3
$address =~ m[^\w.*/] and not $address =~ /:/
!ll&&!rl&&r
000
MC/DC0%0/2
$address =~ m[^\w.*/] and not $address =~ /:/
$address =~ m[^\w.*/] not $address =~ /:/
Truth table0%0/3
A and not(B)
A= $address =~ m[^\w.*/]B= not $address =~ /:/
ABresult
0X0
100
111
21 0 return $address;
22 }
23 0 return;
24 }
25  
26 0 ▶sub get_sock_from_addr {
Subroutine get_sock_from_addr: not called CC=3 SCAR=24.8
Pod undocumented
27 0 my $address = shift;
28  
29 0 my $unix = parse_unix($address);
30  
31 0 ▶ if ($unix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unix) 0 0 0
32 0 return IO::Socket::UNIX->new(
33 Type => SOCK_STREAM,
34 Peer => $unix,
35 );
36 }
37  
38 0 $address =~ s{/+$}{};
39 0 my $sock = IO::Socket::INET->new(
40 PeerAddr => $address,
41 Proto => 'tcp',
42 );
43 0 ▶ return unless $sock;
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 0 0
44 0 $sock->autoflush(1);
45 0 return $sock;
46 }
47  
48 ## conveniently, log to the "log" priority,
49 ## and call the error callback if one is specified.
50 3 ▶sub error {
Subroutine error: called CC=2 SCAR=7.1
Pod undocumented
51 3 my $object = shift;
52 3 my $err_msg = pop;
53 3 my %param = @_;
54  
55 3 my $log = $object->{ctrl}->log;
56 3 $log->error($err_msg);
57 3 ▶ my $err_cb = $param{err_cb} || sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$param{'err_cb'} || sub { }
l!l&&r!l&&!r
300
MC/DC0%0/2
$param{'err_cb'} || sub { }
$param{'err_cb'} sub { }
Truth table33%1/3
A || B
A= $param{'err_cb'}B= sub { }
ABresult
1X1
011
000
58 3 return $err_cb->($err_msg);
59 }
60  
61 27 ▶sub exit_reason {
Subroutine exit_reason: called CC=4 SCAR=13.9
Pod undocumented
62 27 my $status = shift;
63  
64 27 my $exit_status = POSIX::WEXITSTATUS($status);
65 27 my $signal = POSIX::WTERMSIG($status);
66  
67 27 my ($exit, $sig);
68 27 ▶ if (POSIX::WIFEXITED($status)) {
Branch: 1 branch
BranchTrueFalseTotal
if (POSIX::WIFEXITED($status)) 21 6 27
69 21 ▶ $exit = $exit_status
Branch: 1 branch
BranchTrueFalseTotal
$exit_status ? : 21 0 21
70 ? "Exited with error $exit_status"
71 : "Exited successfuly";
72 }
73  
74 27 ▶ $sig = "Received signal $signal" if POSIX::WIFSIGNALED($status);
Branch: 1 branch
BranchTrueFalseTotal
if POSIX::WIFSIGNALED($status) 6 21 27
75 27 return join " - ", grep { $_ } ($exit, $sig);
76 }
77  
78 8 1;
« lib/ControlFreak.pm ↑ Summary lib/ControlFreak/Socket.pm »