lib/Rex/TaskList.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 92.7% 64 / 69 CC 7 SCAR 9.3
CC
7
Cov
95%
run
5.0
create
3.0
BEGIN
1.0
CRAP 2.5
« lib/Rex/Test/Base/has_file.pm ↑ Summary lib/Rex/Cloud/Base.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::TaskList;
6  
7 110 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 110 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 105 our $VERSION = '1.16.1'; # VERSION
11  
12 105 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 105 ▶use Rex::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 105 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 105 ▶use Rex::Interface::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 105 ▶use vars qw(%tasks);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # will be set from Rex::Transaction::transaction()
20 105 our $task_list = {};
21  
22 568 ▶sub create {
Subroutine create: called CC=3 SCAR=11.0
Pod undocumented
23 568 my ($class) = @_;
24  
25 # create only one object
26 568 ▶ if ( ref($task_list) =~ m/^Rex::TaskList::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Rex::TaskList::task_list) =~ /^Rex::TaskList::/u) 507 61 568
27 507 Rex::Logger::debug(
28 "Returning existing distribution class of type: " . ref($task_list) );
29 507 return $task_list;
30 }
31  
32 61 my $type = Rex::Config->get_distributor;
33 61 Rex::Logger::debug("Creating new distribution class of type: $type");
34  
35 61 my $class_name = "Rex::TaskList::$type";
36  
37 56 ▶ eval "use $class_name";
Subroutine BEGIN: called CC=1 SCAR=0.0
38 61 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 61 61
39 0 die("TaskList module not found: $@");
40 }
41  
42 61 $task_list = $class_name->new;
43  
44 61 Rex::Logger::debug(
45 "new distribution class of type " . ref($task_list) . " created." );
46  
47 61 return $task_list;
48 }
49  
50 118 ▶sub run {
Subroutine run: called CC=5 SCAR=16.1
Pod undocumented
51 118 my ( $class, $task_name, %option ) = @_;
52  
53 118 ▶ $class = ref $class ? $class : $class->create;
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 0 118 118
54  
55 118 ▶ my $task = ref $task_name ? $task_name : $class->get_task($task_name);
Branch: 1 branch
BranchTrueFalseTotal
ref $task_name ? : 71 47 118
56  
57 118 my $old_task = $class->{__current_task__};
58 118 $class->{__current_task__} = $task;
59  
60 118 $_->($task) for @{ $task->{before_task_start} };
61 118 $class->run( $task, %option );
62 92 $_->($task) for @{ $task->{after_task_finished} };
63  
64 92 $class->{__current_task__} = $old_task;
65 }
« lib/Rex/Test/Base/has_file.pm ↑ Summary lib/Rex/Cloud/Base.pm »