lib/Ubic/Ping/Service.pm

filter: Statementstmt 80.0% 40 / 50 Branchbran 16.6% 1 / 6 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 12 / 14 Podpod 100% 1 / 1 totaltotal 68.2% 56 / 82 SCAR 21.5
CC
7
Cov
68%
__ANON__
17.3
new
5.4
__ANON__
2.0
CRAP 8.6
« lib/Ubic/Daemon/OS/Linux.pm ↑ Summary lib/Ubic/Service/Common.pm »
1 package Ubic::Ping::Service;
2 29 $Ubic::Ping::Service::VERSION = '1.59';
3 # ABSTRACT: ubic.ping service
4  
5 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 29 ▶use Ubic::Service::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Ubic::Daemon qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Ubic::Result qw(result);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 29 ▶use Ubic::UA;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Time::HiRes qw(sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 29 ▶use Ubic::Settings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 29 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub new {
20 35 ▶ my $port = $ENV{UBIC_SERVICE_PING_PORT} || 12345;
Subroutine new: called CC=3 SCAR=16.9
Pod documented
Condition50%1/2
$ENV{'UBIC_SERVICE_PING_PORT'} || 12345
l!l
035
MC/DC0%0/1
$ENV{'UBIC_SERVICE_PING_PORT'} || 12345
$ENV{'UBIC_SERVICE_PING_PORT'}
Truth table50%1/2
A
A= $ENV{'UBIC_SERVICE_PING_PORT'}
Aresult
11
00
21 35 my $pidfile = Ubic::Settings->data_dir."/ubic-ping.pid";
22 35 ▶ my $log = $ENV{UBIC_SERVICE_PING_LOG} || '/dev/null';
Condition50%1/2
$ENV{'UBIC_SERVICE_PING_LOG'} || '/dev/null'
l!l
035
MC/DC0%0/1
$ENV{'UBIC_SERVICE_PING_LOG'} || '/dev/null'
$ENV{'UBIC_SERVICE_PING_LOG'}
Truth table50%1/2
A
A= $ENV{'UBIC_SERVICE_PING_LOG'}
Aresult
11
00
23  
24 35 my $perl = $Config{perlpath};
25  
26 Ubic::Service::Common->new({
27 start => sub {
28 0 ▶ my $pid;
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 start_daemon({
30 bin => qq{$perl -MUbic::Ping -e 'Ubic::Ping->new($port)->run;'},
31 name => 'ubic.ping',
32 pidfile => $pidfile,
33 stdout => $log,
34 stderr => $log,
35 ubic_log => $log,
36 });
37 },
38 stop => sub {
39 0 ▶ stop_daemon($pidfile);
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 },
41 status => sub {
42 2 ▶ my $daemon = check_daemon($pidfile);
Subroutine __ANON__: called CC=5 SCAR=28.5
43 2 ▶ unless ($daemon) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($daemon) 2 0 2
44 2 return 'not running';
45 }
46 0 my $ua = Ubic::UA->new(timeout => 1);
47 0 my $response = $ua->get("http://127.0.0.1:$port/ping");
48 0 ▶ if ($response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"error"}) 0 0 0
49 0 return result('broken', $response->{error});
50 }
51 0 ▶ if ($response->{body} =~ /^ok$/ and $response->{code} == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{'body'} =~ /^ok$/ and $response->{'code'} == 200) { } 0 0 0
Condition0%0/3
$response->{"body"} =~ /^ok$/ and $response->{"code"} == 200
!ll&&!rl&&r
000
MC/DC0%0/2
$response->{"body"} =~ /^ok$/ and $response->{"code"} == 200
$response->{"body"} =~ /^ok$/ $response->{"code"} == 200
Truth table0%0/3
A and B
A= $response->{"body"} =~ /^ok$/B= $response->{"code"} == 200
ABresult
0X0
100
111
52 0 return result('running', "pid ".$daemon->pid);
53 }
54 else {
55 0 return result('broken', $response->{body});
56 }
57 },
58 35 port => $port,
59 timeout_options => { start => { step => 0.1, trials => 8 }},
60 });
61 }
62  
63  
64 29 1;
65  
66 __END__
« lib/Ubic/Daemon/OS/Linux.pm ↑ Summary lib/Ubic/Service/Common.pm »