| 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() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | if ($address =~ m!^unix:(.+)!) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 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 =~ /:/
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 =~ /:/
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 {
}
MC/DC0%0/2
$param{'err_cb'} || sub {
}
$param{'err_cb'}
sub {
}
Truth table33%1/3
A || B
A= $param{'err_cb'}B= sub {
}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 69 | 21 | ▶ | $exit = $exit_status | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | ? "Exited with error $exit_status" | ||||||||||||||||||||
| 71 | : "Exited successfuly"; | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 27 | ▶ | $sig = "Received signal $signal" if POSIX::WIFSIGNALED($status); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 27 | return join " - ", grep { $_ } ($exit, $sig); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 8 | 1; | |||||||||||||||||||