lib/Rex/RunList.pm

filter: Statementstmt 93.5% 72 / 77 Branchbran 87.5% 21 / 24 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 12 totaltotal 80.1% 117 / 146 CC 21 SCAR 14.4
CC
21
Cov
89%
parse_opts
8.0
pre_1_4_parse_opts
7.0
add_task
3.0
CRAP 4.2
« lib/Rex/FS/File.pm ↑ Summary lib/Rex/Interface/Fs/HTTP.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::RunList;
6  
7 105 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 105 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 105 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 105 ▶use Rex::TaskList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 105 our $VERSION = '1.16.1'; # VERSION
14  
15 105 my $INSTANCE;
16  
17 28 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
18 28 my ( $class, %args ) = @_;
19 28 return bless \%args, $class;
20 }
21  
22 # returns a singleton
23 40 ▶sub instance {
Subroutine instance: called CC=2 SCAR=6.9
Pod undocumented
24 40 my $class = shift;
25 40 ▶ return $INSTANCE if $INSTANCE;
Branch: 1 branch
BranchTrueFalseTotal
if $INSTANCE 12 28 40
26 28 $INSTANCE = $class->new(@_);
27 }
28  
29 101 ▶sub add_task {
Subroutine add_task: called CC=3 SCAR=11.1
Pod undocumented
30 101 my ( $self, $task_name, $task_args, $task_opts ) = @_;
31 101 ▶ $task_args ||= [];
Condition50%1/2
$task_args ||= []
l!l
1010
MC/DC0%0/1
$task_args ||= []
$task_args
Truth table50%1/2
A
A= $task_args
Aresult
11
00
32 101 ▶ $task_opts ||= {};
Condition50%1/2
$task_opts ||= {}
l!l
1010
MC/DC0%0/1
$task_opts ||= {}
$task_opts
Truth table50%1/2
A
A= $task_opts
Aresult
11
00
33 101 my $task = $self->task_list->get_task($task_name);
34 101 $task->set_args(@$task_args);
35 101 $task->set_opts(%$task_opts);
36 101 push @{ $self->{tasks} }, $task;
37 }
38  
39 5 ▶sub current_index {
Subroutine current_index: called CC=2 SCAR=6.9
Pod undocumented
40 5 my ($self) = @_;
41 5 ▶ return $self->{current_index} || 0;
Condition100%2/2
$self->{'current_index'} || 0
l!l
41
MC/DC100%1/1
$self->{'current_index'} || 0
$self->{'current_index'}
Truth table100%2/2
A
A= $self->{'current_index'}
Aresult
11
00
42 }
43  
44 70 ▶sub increment_current_index {
Subroutine increment_current_index: called CC=1 SCAR=0.0
Pod undocumented
45 70 my ($self) = @_;
46 70 return $self->{current_index} += 1;
47 }
48  
49 5 ▶sub current_task {
Subroutine current_task: called CC=1 SCAR=0.0
Pod undocumented
50 5 my $self = shift;
51 5 my $i = $self->current_index;
52 5 $self->{tasks}->[$i];
53 }
54  
55 39 ▶sub tasks { @{ shift->{tasks} || [] } }
Subroutine tasks: called CC=2 SCAR=7.2
Pod undocumented
Condition50%1/2
+(shift())->{'tasks'} || []
l!l
390
MC/DC0%0/1
+(shift())->{'tasks'} || []
+(shift())->{'tasks'}
Truth table50%1/2
A
A= +(shift())->{'tasks'}
Aresult
11
00
56  
57 290 ▶sub task_list {
Subroutine task_list: called CC=2 SCAR=6.9
Pod undocumented
58 290 my $self = shift;
59 290 ▶ return $self->{task_list} if $self->{task_list};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"task_list"} 262 28 290
60 28 $self->{task_list} = Rex::TaskList->create;
61 }
62  
63 29 ▶sub run_tasks {
Subroutine run_tasks: called CC=2 SCAR=6.9
Pod undocumented
64 29 my ($self) = @_;
65  
66 29 for my $task ( $self->tasks ) {
67 71 Rex::TaskList->run($task);
68 55 $self->increment_current_index;
69 }
70 }
71  
72 # Parse @ARGV to get tasks, task args, and task opts. Use these values to
73 # generate a list of tasks the user wants to run.
74 35 ▶sub parse_opts {
Subroutine parse_opts: called CC=8 SCAR=20.8
Pod undocumented
75 35 my ( $self, @params ) = @_;
76  
77 35 ▶ return $self->pre_1_4_parse_opts(@params)
Branch: 1 branch
BranchTrueFalseTotal
unless "Rex::Config"->get_task_chaining_cmdline_args 24 11 35
78 unless Rex::Config->get_task_chaining_cmdline_args;
79  
80 11 ▶ while ( my $task_name = shift @params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $task_name = shift @params) 33 11 44
81 33 ▶ $self->exit_rex($task_name) unless $self->task_list->is_task($task_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->task_list->is_task($task_name) 0 33 33
82  
83 33 my @args;
84 my %opts;
85  
86 33 ▶ while ( my $param = shift @params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift @params) 88 11 99
87 88 ▶ if ( $self->task_list->is_task($param) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->task_list->is_task($param)) 22 66 88
88 22 unshift @params, $param;
89 22 last;
90 }
91  
92 66 ▶ if ( $param =~ /^--/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ /^--/u) { } 33 33 66
93 33 my ( $key, $val ) = split /=/, $param, 2;
94 33 $key =~ s/^--//;
95  
96 33 ▶ $opts{$key} = defined $val ? $val : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 33 0 33
97 }
98 else {
99 33 push @args, $param;
100 }
101 }
102  
103 33 $self->add_task( $task_name, \@args, \%opts );
104 }
105  
106 11 return $self;
107 }
108  
109 # this function is to parse the task parameters in a pre 1.4 fashion.
110 # this is used if the feature flag 'no_task_chaining_cmdline_args' or
111 # '< 1.4' is enabled.
112 24 ▶sub pre_1_4_parse_opts {
Subroutine pre_1_4_parse_opts: called CC=7 SCAR=19.5
Pod undocumented
113 24 my ( $self, @params ) = @_;
114  
115 #### parse task options
116 24 my %task_opts;
117  
118 24 for my $p (@params) {
119 104 my ( $key, $val ) = split( /=/, $p, 2 );
120  
121 104 $key =~ s/^--//;
122  
123 104 ▶ if ( defined $val ) { $task_opts{$key} = $val; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 36 68 104
124 68 $task_opts{$key} = 1;
125 }
126  
127 24 for my $task_name (@params) {
128 104 ▶ next if $task_name =~ m/^\-\-/ || $task_name =~ m/=/;
Branch: 1 branch
BranchTrueFalseTotal
if $task_name =~ /^\-\-/u or $task_name =~ /=/u 36 68 104
Condition66%2/3
$task_name =~ /^\-\-/u or $task_name =~ /=/u
l!l&&r!l&&!r
36068
MC/DC50%1/2
$task_name =~ /^\-\-/u or $task_name =~ /=/u
$task_name =~ /^\-\-/u $task_name =~ /=/u
Truth table66%2/3
A or B
A= $task_name =~ /^\-\-/uB= $task_name =~ /=/u
ABresult
1X1
011
000
129 68 ▶ $self->exit_rex($task_name) unless $self->task_list->is_task($task_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->task_list->is_task($task_name) 0 68 68
130 68 $self->add_task( $task_name, [], \%task_opts );
131 }
132 }
133  
134 0 ▶sub exit_rex {
Subroutine exit_rex: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my ( $self, $task_name ) = @_;
136 0 my $msg = "Task names are case sensitive ";
137 0 $msg .= "and the module delimiter is a single colon.";
138 0 Rex::Logger::info( "No task named '$task_name' found. $msg", 'error' );
139 0 Rex::CLI::exit_rex(1);
140 }
141  
142 105 1;
« lib/Rex/FS/File.pm ↑ Summary lib/Rex/Interface/Fs/HTTP.pm »