Skip to content

Commit

Permalink
added needs to build dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Apr 15, 2011
1 parent 0c22987 commit 95d3e91
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Rex/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ use base qw(Exporter);
exit
evaluate_hostname
logging
needs
);

sub task {
my($class, $file, @tmp) = caller;
my $task_name = shift;
my $task_name_save = $task_name;

if($class ne "main") {
$task_name = $class . ":" . $task_name;
}
Expand All @@ -44,6 +47,10 @@ sub task {
push(@_, "");
}

no strict 'refs';
push (@{"${class}::tasks"}, { name => $task_name_save, code => $_[-2] } );
use strict;

Rex::Task->create_task($task_name, @_);
}

Expand Down Expand Up @@ -163,5 +170,22 @@ sub logging {
}
}

sub needs {
my ($self, @args) = @_;

no strict 'refs';
my @tasks_to_run = @{"${self}::tasks"};
use strict;

for my $task (@tasks_to_run) {
if(@args && $task->{"name"} ~~ @args) {
&{ $task->{"code"} };
}
elsif(! @args) {
&{ $task->{"code"} };
}
}

}

1;

0 comments on commit 95d3e91

Please sign in to comment.