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   1334 use v5.12.5;
  107         382  
8 107     102   695 use warnings;
  102         178  
  102         4250  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 102     102   22087 use Data::Dumper;
  102         235269  
  102         5488  
13 102     102   31279 use Rex::Config;
  102         292  
  102         471  
14 102     102   670 use Rex::Logger;
  102         367  
  102         507  
15 102     102   30177 use Rex::Interface::Executor;
  102         227  
  102         1145  
16              
17 102     102   3186 use vars qw(%tasks);
  102         210  
  102         38568  
18              
19             # will be set from Rex::Transaction::transaction()
20             our $task_list = {};
21              
22             sub create {
23 568     568 0 56420 my ($class) = @_;
24              
25             # create only one object
26 568 100       6312 if ( ref($task_list) =~ m/^Rex::TaskList::/ ) {
27 507         3586 Rex::Logger::debug(
28             "Returning existing distribution class of type: " . ref($task_list) );
29 507         3123 return $task_list;
30             }
31              
32 61         708 my $type = Rex::Config->get_distributor;
33 61         468 Rex::Logger::debug("Creating new distribution class of type: $type");
34              
35 61         216 my $class_name = "Rex::TaskList::$type";
36              
37 56     56   779 eval "use $class_name";
  56         298  
  56         689  
  61         4936  
38 61 50       1531 if ($@) {
39 0         0 die("TaskList module not found: $@");
40             }
41              
42 61         424 $task_list = $class_name->new;
43              
44 61         635 Rex::Logger::debug(
45             "new distribution class of type " . ref($task_list) . " created." );
46              
47 61         393 return $task_list;
48             }
49              
50             sub run {
51 118     118 0 168059 my ( $class, $task_name, %option ) = @_;
52              
53 118 50       1468 $class = ref $class ? $class : $class->create;
54              
55 118 100       1137 my $task = ref $task_name ? $task_name : $class->get_task($task_name);
56              
57 118         547 my $old_task = $class->{__current_task__};
58 118         533 $class->{__current_task__} = $task;
59              
60 118         397 $_->($task) for @{ $task->{before_task_start} };
  118         704  
61 118         3203 $class->run( $task, %option );
62 92         802 $_->($task) for @{ $task->{after_task_finished} };
  92         2054  
63              
64 92         3249 $class->{__current_task__} = $old_task;
65             }