Search code examples
metaprogrammingraku

Is it possible to append subroutines to a Raku module at runtime?


I would like to be able to add a sub to a module Foo at runtime.

In Perl, I would do something like:

*{'My::Module::foo'} = \sub { 'FOO!' };

I know Raku doesn't have TypeGlobbing like Perl. Ideally it would be something like:

use MONKEY;

module Foo {};

Foo.^add-sub('foo', sub { 'FOO!' });

Is this possible?


Solution

  • module Foo {}
    Foo::<&added-sub> = sub { 99 }
    say Foo::added-sub; # 99
    

    See also: