Cinnamon/CLI.pm

filter: Statementstmt 94.3% 50 / 53 Branchbran 92.8% 13 / 14 Conditioncond 82.3% 14 / 17 MC/DCmcdc 70.0% 7 / 10 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 86.9% 93 / 107 CC 15 SCAR 23.4
CC
15
Cov
92%
run
15.3
BEGIN
1.0
BEGIN
1.0
CRAP 10.4
« Cinnamon/Remote.pm ↑ Summary Cinnamon/Local.pm »
1 package Cinnamon::CLI;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Cinnamon::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant { SUCCESS => 0, ERROR => 1 };
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 12 my $class = shift;
12 12 bless { }, $class;
13 }
14  
15 12 ▶sub run {
Subroutine run: called CC=15 SCAR=27.3
Pod undocumented
16 12 my ($self, @args) = @_;
17  
18 12 local @ARGV = @args;
19 12 my $p = Getopt::Long::Parser->new(
20 config => ["no_ignore_case", "pass_through"],
21 );
22 $p->getoptions(
23 "h|help" => \$self->{help},
24 "i|info" => \$self->{info},
25 "c|config=s" => \$self->{config},
26 "s|set=s%" => \$self->{override_settings},
27 "I|ignore-errors" => \$self->{ignore_errors},
28 12 );
29  
30 # --help option
31 12 ▶ if ($self->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"help"}) 1 11 12
32 1 $self->usage;
33 1 return SUCCESS;
34 }
35  
36 # check config exists
37 11 ▶ $self->{config} ||= 'config/deploy.pl';
Condition100%2/2
$self->{"config"} ||= "config/deploy.pl"
l!l
29
MC/DC100%1/1
$self->{"config"} ||= "config/deploy.pl"
$self->{"config"}
Truth table100%2/2
A
A= $self->{"config"}
Aresult
11
00
38 11 ▶ if (!-e $self->{config}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->{"config"}) 1 10 11
39 1 $self->print("cannot find config file for deploy : $self->{config}\n");
40 1 $self->usage;
41 1 return ERROR;
42 }
43  
44 # check role and task exists
45 10 my $role = shift @ARGV;
46 10 my @tasks = @ARGV;
47 10 ▶ if (!$self->{info} && (!$role || scalar @tasks == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"info"} and !$role || scalar @tasks == 0) 0 10 10
Condition50%3/6
not $self->{"info"} and !$role || scalar @tasks == 0
!ll&&!rl&&r
190
not $role or scalar @tasks == 0
l!l&&r!l&&!r
009
MC/DC0%0/3
not $self->{"info"} and !$role || scalar @tasks == 0
not $self->{"info"} not $role scalar @tasks == 0
Truth table50%2/4
not(A) and not(B) or C
A= not $self->{"info"}B= not $roleC= scalar @tasks == 0
ABCresult
0XX0
1000
11X1
1011
48 0 $self->print("please specify role and task\n");
49 0 $self->usage;
50 0 return ERROR;
51 }
52  
53 10 ▶ @tasks = (undef) if (@tasks == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @tasks == 0 1 9 10
54 10 my $error_occured = 0;
55 10 my $context = Cinnamon::Context->new;
56 10 local $Cinnamon::Context::CTX = $context;
57 10 for my $task (@tasks) {
58 my ($success, $error) = $context->run(
59 $role,
60 $task,
61 config => $self->{config},
62 override_settings => $self->{override_settings},
63 info => $self->{info},
64 14 );
65 14 ▶ last if ($self->{info});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"info"} 1 13 14
66  
67 # check execution error
68 13 ▶ $error_occured ||= ! defined $success;
Condition100%3/3
$error_occured ||= !defined($success)
l!l&&r!l&&!r
328
MC/DC100%2/2
$error_occured ||= !defined($success)
$error_occured !defined($success)
Truth table100%3/3
A ||= not(B)
A= $error_occuredB= !defined($success)
ABresult
1X1
011
000
69 13 ▶ $error_occured ||= scalar @$error > 0;
Condition100%3/3
$error_occured ||= scalar @$error > 0
l!l&&r!l&&!r
526
MC/DC100%2/2
$error_occured ||= scalar @$error > 0
$error_occured scalar @$error > 0
Truth table100%3/3
A ||= B
A= $error_occuredB= scalar @$error > 0
ABresult
1X1
011
000
70  
71 13 ▶ last if ($error_occured && !$self->{ignore_errors});
Branch: 1 branch
BranchTrueFalseTotal
if $error_occured and not $self->{"ignore_errors"} 2 11 13
Condition100%3/3
$error_occured and not $self->{"ignore_errors"}
!ll&&!rl&&r
652
MC/DC100%2/2
$error_occured and not $self->{"ignore_errors"}
$error_occured not $self->{"ignore_errors"}
Truth table100%3/3
A and not(B)
A= $error_occuredB= not $self->{"ignore_errors"}
ABresult
0X0
100
111
72 11 print "\n";
73 }
74  
75 10 ▶ return $error_occured ? ERROR : SUCCESS;
Branch: 1 branch
BranchTrueFalseTotal
$error_occured ? : 4 6 10
76 }
77  
78 2 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
79 2 my $self = shift;
80 2 my $msg = <<"HELP";
81 Usage: cinnamon [--config=<path>] [--set=<parameter>] [--ignore-errors] [--help] [--info] <role> <task ...>
82 HELP
83 2 $self->print($msg);
84 }
85  
86 3 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod undocumented
87 3 my ($self, $msg) = @_;
88 3 print STDERR $msg;
89 }
90  
91 2 !!1;
« Cinnamon/Remote.pm ↑ Summary Cinnamon/Local.pm »