Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading a package funcion to detect no arguments have been used

Tags:

raku

rakudo

I am trying to overload a function to detect no arguments have been passed:

package Documentable::CLI {

        sub RUN-MAIN(|c) is export {
            my %*SUB-MAIN-OPTS = :named-anywhere;
            CORE::<&RUN-MAIN>(|c)
        }

        our proto MAIN(|) is export { * }

        multi MAIN (
            Bool :V(:$version)
        ) {}

        multi MAIN () {
            say 'Execute "documentable --help" for more information'
        }

    }

    # no output
    Documentable::CLI::MAIN();

If you try to use multi main (*@args) {} it will not work either. BUT if you delete the first multi MAIN definition everything will work smoothly. Any idea how to solve it?

like image 240
Antonio Gamiz Delgado Avatar asked May 26 '20 18:05

Antonio Gamiz Delgado


1 Answers

The signature :(Bool :V(:$version)) accepts no argument, because the argument version is optional, and it is more specific than the signature :(). You could make the argument version mandatory

multi MAIN (
    Bool :V( :$version )!
) {}
like image 166
wamba Avatar answered Nov 14 '22 15:11

wamba