I have issues understanding this Perl module, I am very new to Perl, where main logic is within the ExternalLibrary::registerJob and it is executed as listed below, the mentioned ExecutionBlock is a black box for me and all I do know I can list several unitFunc() within tasksequence.
tasksequence=>[
$ic->unitFunc('ExternalLibrary::registerJob', jobName=>'JOB1'),
$ic->unitFunc('ExternalLibrary::registerJob', jobName=>'JOB2'),
$ic->unitFunc('ExternalLibrary::registerJob', jobName=>'JOB3')
]
The module part, this is the template pattern we should use:
sub myFunc{
my %args=@_;
my $ic = $args{'initialcontext'};
my $basetasksequence = [
new ExecutionBlock(
initialcontext=>$ic,
tasksequence=>[
$ic->unitFunc('ExternalLibrary::registerJob')
]
)
];
my $runtasksequence = [
new ExecutionBlock(
initialcontext=>$ic,
tasksequence=>$basetasksequence
)
->errCallBack($ic->unitFunc('ExternalLibrary::logger', kind=>"J", status=>"F",RunTaskSequence=>$basetasksequence))
];
return { tasksequence=>$runtasksequence };
}
I want to modify that to so I can pass multiple jobNames there, the registerJob can accept jobName as parameter, this is a hint for me.
$ic->unitFunc('ExternalLibrary::registerJob', jobName=>$jobName)
I however do not know how to loop this properly or even how to name the problem so I could lookup the problem and read on the topic. Trying to understand the whereabouts are a bit harder to me.
I can get the jobName from a loop similar to this:
my @res= $ic->DBHandler::sql(sql=>$statementQuery);
foreach my $list(@res){
$jobName = $list->{'JOB_NAME'};
}
But I am not sure how to go about combining this together, whether I can run the loop within the array like this?
sub myFunc{
my %args=@_;
my $ic = $args{'initialcontext'};
my $basetasksequence = [
new ExecutionBlock(
initialcontext=>$ic,
tasksequence=>[
my @res= $ic->DBHandler::sql(sql=> $statementQuery);
foreach my $list(@res){
$jobName = $list->{'JOB_NAME'};
$ic->unitFunc('ExternalLibrary::registerJob', jobName=>$jobName)
}
]
)
];
my $runtasksequence = [
new ExecutionBlock(
initialcontext=>$ic,
tasksequence=>$basetasksequence
)
->errCallBack($ic->unitFunc('ExternalLibrary::logger', kind=>"J", status=>"F",RunTaskSequence=>$basetasksequence))
];
return { tasksequence=>$runtasksequence };
}
I think I would need another function to return the whole array and then assign it to tasksequence, but I do not know how to preserve the required form ($ic->unitFunc()) and pass it correctly.