Search code examples
rakurakudo

Overloading a package funcion to detect no arguments have been used


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?


Solution

  • 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 )!
    ) {}