File Coverage

lib/Rex/TaskList.pm
Criterion Covered Total %
statement 46 47 97.8
branch 6 8 75.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 62 67 92.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::TaskList;
6              
7 107     107   1398 use v5.12.5;
  107         383  
8 107     102   702 use warnings;
  102         196  
  102         4421  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 102     102   24176 use Data::Dumper;
  102         252745  
  102         5849  
13 102     102   30811 use Rex::Config;
  102         299  
  102         493  
14 102     102   816 use Rex::Logger;
  102         368  
  102         643  
15 102     102   32185 use Rex::Interface::Executor;
  102         273  
  102         1259  
16              
17 102     102   3361 use vars qw(%tasks);
  102         215  
  102         38923  
18              
19             # will be set from Rex::Transaction::transaction()
20             our $task_list = {};
21              
22             sub create {
23 568     568 0 61803 my ($class) = @_;
24              
25             # create only one object
26 568 100       8910 if ( ref($task_list) =~ m/^Rex::TaskList::/ ) {
27 507         5122 Rex::Logger::debug(
28             "Returning existing distribution class of type: " . ref($task_list) );
29 507         3686 return $task_list;
30             }
31              
32 61         542 my $type = Rex::Config->get_distributor;
33 61         499 Rex::Logger::debug("Creating new distribution class of type: $type");
34              
35 61         264 my $class_name = "Rex::TaskList::$type";
36              
37 56     56   737 eval "use $class_name";
  56         237  
  56         786  
  61         4913  
38 61 50       1366 if ($@) {
39 0         0 die("TaskList module not found: $@");
40             }
41              
42 61         476 $task_list = $class_name->new;
43              
44 61         542 Rex::Logger::debug(
45             "new distribution class of type " . ref($task_list) . " created." );
46              
47 61         460 return $task_list;
48             }
49              
50             sub run {
51 118     118 0 230229 my ( $class, $task_name, %option ) = @_;
52              
53 118 50       1714 $class = ref $class ? $class : $class->create;
54              
55 118 100       1629 my $task = ref $task_name ? $task_name : $class->get_task($task_name);
56              
57 118         451 my $old_task = $class->{__current_task__};
58 118         502 $class->{__current_task__} = $task;
59              
60 118         324 $_->($task) for @{ $task->{before_task_start} };
  118         651  
61 118         3899 $class->run( $task, %option );
62 92         821 $_->($task) for @{ $task->{after_task_finished} };
  92         2103  
63              
64 92         4053 $class->{__current_task__} = $old_task;
65             }