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   1380 use v5.12.5;
  107         381  
8 107     102   731 use warnings;
  102         223  
  102         4402  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 102     102   23884 use Data::Dumper;
  102         250870  
  102         5708  
13 102     102   31166 use Rex::Config;
  102         336  
  102         488  
14 102     102   790 use Rex::Logger;
  102         436  
  102         541  
15 102     102   31721 use Rex::Interface::Executor;
  102         242  
  102         1229  
16              
17 102     102   3501 use vars qw(%tasks);
  102         241  
  102         38507  
18              
19             # will be set from Rex::Transaction::transaction()
20             our $task_list = {};
21              
22             sub create {
23 568     568 0 57312 my ($class) = @_;
24              
25             # create only one object
26 568 100       6685 if ( ref($task_list) =~ m/^Rex::TaskList::/ ) {
27 507         4426 Rex::Logger::debug(
28             "Returning existing distribution class of type: " . ref($task_list) );
29 507         3935 return $task_list;
30             }
31              
32 61         561 my $type = Rex::Config->get_distributor;
33 61         566 Rex::Logger::debug("Creating new distribution class of type: $type");
34              
35 61         239 my $class_name = "Rex::TaskList::$type";
36              
37 56     56   706 eval "use $class_name";
  56         240  
  56         682  
  61         5208  
38 61 50       1469 if ($@) {
39 0         0 die("TaskList module not found: $@");
40             }
41              
42 61         409 $task_list = $class_name->new;
43              
44 61         596 Rex::Logger::debug(
45             "new distribution class of type " . ref($task_list) . " created." );
46              
47 61         439 return $task_list;
48             }
49              
50             sub run {
51 118     118 0 203686 my ( $class, $task_name, %option ) = @_;
52              
53 118 50       1319 $class = ref $class ? $class : $class->create;
54              
55 118 100       1206 my $task = ref $task_name ? $task_name : $class->get_task($task_name);
56              
57 118         381 my $old_task = $class->{__current_task__};
58 118         296 $class->{__current_task__} = $task;
59              
60 118         285 $_->($task) for @{ $task->{before_task_start} };
  118         753  
61 118         3178 $class->run( $task, %option );
62 92         604 $_->($task) for @{ $task->{after_task_finished} };
  92         1748  
63              
64 92         2736 $class->{__current_task__} = $old_task;
65             }