Skip to content

Commit

Permalink
Much better sub dispatching thanks to jnthn++
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
patrickas authored and moritz committed Jun 11, 2010
1 parent d1aeb84 commit 9c0f9ec
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/core/MAIN.pm
Expand Up @@ -68,19 +68,17 @@ our sub MAIN_HELPER() {
return @positional-arguments, %named-arguments;
};

my $correct-main-found = False;
my @subs = $m ~~ Multi ?? $m.candidates !! ($m);
#TODO: We are calling the FIRST matching MAIN sub, we should be calling the BEST matching MAIN sub.
for @subs -> $main {
my @named-params = $main.signature.params.grep: {.named && .type ~~ Bool};
my %named-params = @named-params».name».substr(1) Z=> @named-params».type;
my @positional = $process-cmd-args(@*ARGS, %named-params);
my %named = @positional.pop;
try {
if Capture.new(|@positional, |%named) ~~ $main.signature {
$main(|@positional, |%named);
$correct-main-found = True;
return ;
}
return if $correct-main-found;
}

#We could not find the correct main to dispatch to! Let's try to run the user defined USAGE sub
Expand Down

0 comments on commit 9c0f9ec

Please sign in to comment.