Skip to content

Commit 48c737b

Browse files
committed
fix #1066 - use Task::run() method to call the task code.
1 parent c6ba2f8 commit 48c737b

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

lib/Rex/Commands.pm

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
22
# (c) Jan Gehring <jan.gehring@gmail.com>
33
#
44
# vim: set ts=2 sw=2 tw=0:
@@ -1011,16 +1011,22 @@ sub needs {
10111011
}
10121012

10131013
if ( $self eq "main" ) {
1014-
$self = "Rex::CLI";
1014+
$self = ""; # Tasks in main namespace are really registered in Rex::CLI
10151015
}
10161016

1017-
no strict 'refs';
1018-
my @maybe_tasks_to_run = @{"${self}::tasks"};
1019-
use strict;
1017+
my $tl = Rex::TaskList->create();
1018+
my @maybe_tasks_to_run;
1019+
if($self) {
1020+
@maybe_tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$});
1021+
}
1022+
else {
1023+
@maybe_tasks_to_run = $tl->get_all_tasks(qr{^[A-Za-z0-9_\-]+$});
1024+
}
10201025

10211026
if ( !@args && !@maybe_tasks_to_run ) {
10221027
@args = ($self);
10231028
($self) = caller;
1029+
$self = "" if($self =~ m/^(Rex::CLI|main)$/);
10241030
}
10251031

10261032
if ( ref( $args[0] ) eq "ARRAY" ) {
@@ -1029,24 +1035,36 @@ sub needs {
10291035

10301036
Rex::Logger::debug("need to call tasks from $self");
10311037

1032-
no strict 'refs';
1033-
my @tasks_to_run = @{"${self}::tasks"};
1034-
use strict;
1038+
my @tasks_to_run;
1039+
if($self) {
1040+
@tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$});
1041+
}
1042+
else {
1043+
@tasks_to_run = $tl->get_all_tasks(qr{^[A-Za-z0-9_\-]+$});
1044+
}
10351045

10361046
my $run_list = Rex::RunList->instance;
10371047
my $current_task = $run_list->current_task;
10381048
my %task_opts = $current_task->get_opts;
10391049
my @task_args = $current_task->get_args;
10401050

1051+
if($self) {
1052+
my $suffix = $self;
1053+
$suffix =~ s/::/:/g;
1054+
@args = map { $_ = "$suffix:$_" } @args;
1055+
}
1056+
10411057
for my $task (@tasks_to_run) {
1042-
my $task_name = $task->{"name"};
1043-
if ( @args && grep ( /^$task_name$/, @args ) ) {
1044-
Rex::Logger::debug( "Calling " . $task->{"name"} );
1045-
$task->{"code"}->( \%task_opts, \@task_args );
1058+
my $task_o = $tl->get_task($task);
1059+
my $task_name = $task_o->name;
1060+
my $suffix = $self . ":";
1061+
if ( @args && grep ( /^\Q$task_name\E$/, @args ) ) {
1062+
Rex::Logger::debug( "Calling " . $task_o->name );
1063+
$task_o->run( "<func>", params => \@task_args, args => \%task_opts );
10461064
}
10471065
elsif ( !@args ) {
1048-
Rex::Logger::debug( "Calling " . $task->{"name"} );
1049-
$task->{"code"}->( \%task_opts, \@task_args );
1066+
Rex::Logger::debug( "Calling " . $task_o->name );
1067+
$task_o->run( "<func>", params => \@task_args, args => \%task_opts );
10501068
}
10511069
}
10521070

0 commit comments

Comments
 (0)