| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 54 | |||||||||||
| 55 | 118 | ▶ | my $task = ref $task_name ? $task_name : $class->get_task($task_name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | } | ||||||||||