Footprintless/Service.pm

filter: Statementstmt 100% 69 / 69 Branchbran 80.0% 16 / 20 Conditioncond 45.4% 5 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 18 / 18 Podpod 100% 5 / 5 totaltotal 88.3% 114 / 129 CC 15 SCAR 19.0
CC
15
Cov
90%
_command
14.5
execute
3.0
BEGIN
1.0
CRAP 6.7
« Footprintless/App/DocumentationUtil.pm ↑ Summary Footprintless/InvalidEntityException.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::Service;
5 2 $Footprintless::Service::VERSION = '1.29';
6 # ABSTRACT: Performs an action on a service.
7 # PODNAME: Footprintless::Service
8  
9 2 ▶use parent qw(Footprintless::MixableBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Footprintless::Command qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 batch_command
14 command
15 2 );
16 2 ▶use Footprintless::CommandOptionsFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Footprintless::InvalidEntityException;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Footprintless::Localhost;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Footprintless::Mixins qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 _command_options
21 _entity
22 _run_or_die
23 2 );
24 2 ▶use Footprintless::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
25 invalid_entity
26 2 );
27 2 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 my $logger = Log::Any->get_logger();
30  
31 5 ▶sub kill {
Subroutine kill: called CC=1 SCAR=0.0
Pod documented
32 5 my ( $self, %options ) = @_;
33 5 $self->execute( 'kill', %options );
34 }
35  
36 26 ▶sub _command {
Subroutine _command: called CC=13 SCAR=26.8
37 26 my ( $self, $action ) = @_;
38 26 my $command = $self->{spec}{command};
39 26 my $actions_spec = $self->{spec}{actions}{$action};
40 26 ▶ if ($actions_spec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($actions_spec) 13 13 26
41 13 ▶ if ( $actions_spec->{command} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($actions_spec->{'command'}) { } 5 8 13
elsif ($actions_spec->{'command_args'}) { } 4 4 8
elsif ($actions_spec->{'use_pid'}) { } 4 0 4
42 5 return $actions_spec->{command};
43 }
44 elsif ( $actions_spec->{command_args} ) {
45 4 $action = $actions_spec->{command_args};
46 }
47 elsif ( $actions_spec->{use_pid} ) {
48 invalid_entity( $self->{coordinate},
49 "pid_file or pid_command required for [$action]" )
50 4 ▶ unless ( $self->{spec}{pid_file} || $self->{spec}{pid_command} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"spec"}{"pid_file"} or $self->{"spec"}{"pid_command"} 0 4 4
Condition33%1/3
$self->{"spec"}{"pid_file"} or $self->{"spec"}{"pid_command"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$self->{"spec"}{"pid_file"} or $self->{"spec"}{"pid_command"}
$self->{"spec"}{"pid_file"} $self->{"spec"}{"pid_command"}
Truth table33%1/3
A or B
A= $self->{"spec"}{"pid_file"}B= $self->{"spec"}{"pid_command"}
ABresult
1X1
011
000
51  
52 4 my $pid_file = $self->{spec}{pid_file};
53 my $pid_command =
54 $pid_file
55 ? command(
56 "cat $pid_file",
57 $self->{command_options}->clone(
58 hostname => undef,
59 ssh => undef,
60 ssh_username => undef,
61 )
62 )
63 4 ▶ : $self->{spec}{pid_command};
Branch: 1 branch
BranchTrueFalseTotal
$pid_file ? : 4 0 4
64 4 ▶ if ( $action eq 'kill' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($action eq 'kill') { } 1 3 4
elsif ($action eq 'status') { } 1 2 3
65 1 return "kill -KILL \$($pid_command)";
66 }
67 elsif ( $action eq 'status' ) {
68 1 ▶ my $command_name = $actions_spec->{command_name} || $command || 'command';
Condition40%2/5
$actions_spec->{'command_name'} || $command || 'command'
l!l
10
$actions_spec->{"command_name"} or $command
l!l&&r!l&&!r
010
MC/DC0%0/2
$actions_spec->{'command_name'} || $command || 'command'
$actions_spec->{"command_name"} $command
Truth table33%1/3
A or B
A= $actions_spec->{"command_name"}B= $command
ABresult
1X1
011
000
69 1 return command( "kill -0 \$($pid_command) 2> /dev/null "
70 . "&& echo '$command_name is running' "
71 . "|| echo '$command_name is stopped'" );
72 }
73 else {
74 2 invalid_entity( $self->{coordinate}, "use_pid not supported for [$action]" );
75 }
76 }
77 }
78  
79 17 ▶ invalid_entity( $self->{coordinate}, "no command specified for [$action]" )
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 17 17
80 unless ($command);
81 17 return "$command $action";
82 }
83  
84 26 ▶sub execute {
Subroutine execute: called CC=3 SCAR=11.0
Pod documented
85 26 my ( $self, $action, %options ) = @_;
86  
87 my $runner_options =
88 %options && $options{runner_options}
89 ? $options{runner_options}
90 26 ▶ : { out_handle => \*STDOUT };
Branch: 1 branch
BranchTrueFalseTotal
%options && $options{'runner_options'} ? : 1 25 26
Condition66%2/3
%options and $options{"runner_options"}
!ll&&!rl&&r
2501
MC/DC50%1/2
%options and $options{"runner_options"}
%options $options{"runner_options"}
Truth table66%2/3
A and B
A= %optionsB= $options{"runner_options"}
ABresult
0X0
100
111
91  
92 26 $self->_run_or_die( command( $self->_command($action), $self->{command_options} ),
93 $runner_options );
94 }
95  
96 10 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
97 10 my ( $self, %options ) = @_;
98  
99 10 $self->{entity} = $self->{factory}->entities();
100 10 $self->{spec} = $self->_entity( $self->{coordinate}, 1 );
101 10 $self->{command_options} = $self->_command_options();
102  
103 10 return $self;
104 }
105  
106 6 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
107 6 my ( $self, %options ) = @_;
108 6 $self->execute( 'start', %options );
109 }
110  
111 5 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
112 5 my ( $self, %options ) = @_;
113 5 $self->execute( 'status', %options );
114 }
115  
116 5 ▶sub stop {
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
117 5 my ( $self, %options ) = @_;
118 5 $self->execute( 'stop', %options );
119 }
120  
121 2 1;
122  
123 __END__
« Footprintless/App/DocumentationUtil.pm ↑ Summary Footprintless/InvalidEntityException.pm »