Protos

You have two options to write multi subs: either you start every candidate with multi sub ... or multi ..., or you declare once and for all that the compiler shall view every sub of a given name as a multi candidate. Do the latter by installing a proto routine:

    proto to-json($) { ... }       # literal ... here

    # automatically a multi
    sub to-json(Bool $d) { $d ?? 'true' !! 'false' }

Nearly all Perl 6 built-in functions and operators export a proto definition, which prevents accidental overriding of built-ins[6].



[6] One of the very rare exceptions is the smart match operator infix:<~~> which is not easily overloadable. Instead it redispatches to overloadable multi methods.