Module/Build/Service/Fork.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 31.2% 5 / 16 Podpod 100% 2 / 2 totaltotal 37.8% 31 / 82 CC 6 SCAR 18.8
CC
6
Cov
38%
__ANON__
20.0
_build_bin
12.0
_build_executable
2.0
CRAP 6.5
« Module/Build/Service/postgresql.pm ↑ Summary Module/Build/Service/slapd.pm »
1 package Module::Build::Service::Fork;
2 {
3 1 $Module::Build::Service::Fork::VERSION = '0.91';
4 }
5 # ABSTRACT: Role for process handling in service implementations
6  
7 1 ▶use File::Spec qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use IPC::Run qw{start};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::Any qw{$log};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 requires '_build_command';
14  
15  
16 1 has 'bin' => (is => 'lazy');
17  
18 # Search the list of directories specified in ->path for the
19 # executable specified in ->executable.
20 0 ▶sub _build_bin {
Subroutine _build_bin: not called CC=3 SCAR=24.8
21 0 my ($self) = @_;
22 0 for my $location (@{$self->path}) {
23 0 my $executable = File::Spec->catfile ($location, $self->executable);
24 0 ▶ -x $executable and return $executable;
Branch: 1 branch
BranchTrueFalseTotal
-x $executable and return $executable 0 0 0
25 }
26 0 die "Couldn't locate " . $self->executable . " binary";
27 }
28  
29  
30 has 'command' => (is => 'lazy',
31 0 ▶ isa => sub {ref $_[0] eq "ARRAY"});
Subroutine __ANON__: not called CC=1 SCAR=1.2
32  
33  
34 1 has 'executable' => (is => 'lazy');
35  
36 0 ▶sub _build_executable {
Subroutine _build_executable: not called CC=1 SCAR=6.9
37 0 my ($self) = @_;
38 0 $self->service_name
39 }
40  
41  
42 has 'path' => (is => 'lazy',
43 0 ▶ isa => sub {ref $_[0] eq "ARRAY"});
Subroutine __ANON__: not called CC=1 SCAR=1.2
44  
45 # Specify our default list of directories to search
46 0 ▶sub _build_path {
Subroutine _build_path: not called CC=1 SCAR=6.9
47 0 ['/usr/sbin', '/usr/local/sbin'];
48 }
49  
50 1 has 'handle' => (is => 'rwp');
51  
52  
53 0 ▶sub start_service {
Subroutine start_service: not called CC=1 SCAR=6.9
Pod documented
54 0 my ($self) = @_;
55 0 $log->tracef ("%s service starting", $self->service_name);
56 0 ▶ try {
Subroutine __ANON__: not called CC=4 SCAR=30.0
57 0 my @output = (\undef);
58 0 ▶ if (my $logfile = $self->log) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $logfile = $self->log) 0 0 0
59 0 $log->tracef ("%s base logfile is %s", $self->service_name, $logfile);
60 0 ▶ $logfile = File::Spec->catfile ($self->_builder->mbs_log_dir, $self->log) unless substr $logfile, 0, 1 eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless 0 0 0
61 0 push @output, '>>', $logfile, '2>', $logfile;
62 }
63 0 $log->tracef ("%s output is %s", $self->service_name, \@output);
64 0 ▶ my $handle = start $self->command, @output or die $?;
Branch: 1 branch
BranchTrueFalseTotal
my $handle = start($self->command, @output) or die $? 0 0 0
65 0 $self->_set_handle ($handle);
66 0 $log->tracef ("%s service started", $self->service_name);
67 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 $log->criticalf ("%s service failed: %s", $self->service_name, $_);
69 0 die $_;
70 0 };
71 }
72  
73  
74 0 ▶sub stop_service {
Subroutine stop_service: not called CC=1 SCAR=6.9
Pod documented
75 0 my ($self) = @_;
76 0 $log->tracef ("%s service stopping", $self->service_name);
77 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 $self->handle->kill_kill;
79 0 $log->tracef ("%s service stopped", $self->service_name);
80 0 1;
81 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 0;
83 0 };
84 }
85  
86 1 1;
87  
88 __END__
« Module/Build/Service/postgresql.pm ↑ Summary Module/Build/Service/slapd.pm »