say $?PACKAGE;
class Foo {
say $?PACKAGE;
class Bar {
say $?PACKAGE;
my package P {say $?PACKAGE;}
}
}
This code prints:
(GLOBAL)
(Foo)
(Bar)
(P)
Wanted:
(GLOBAL)
(GLOBAL::Foo)
(GLOBAL::Foo::Bar)
(GLOBAL::Foo::Bar::P)
In Raku module can also refer to a type of package declared with the module keyword (see Module Packages and the examples below) but here we mostly mean "module" as a set of source files in a namespace. zef is the application used for installing modules in Raku.
(See use lib pragma, -I command line switch, or RAKULIB env variable, to include a path to your module source while developing it, so you don't have to install it at all). Uploading a module to CPAN is the preferred way of distributing Raku modules. A prerequisite for this is a PAUSE user account.
The only requirement is that you know how to be nice to all kinds of people (and butterflies). Go to #raku (irc.libera.chat) and someone will be glad to help you get started . Jump in! Rakudo is a compiler for Raku code. Install it and you're all set to run Raku programs! More…
It is used to describe the module in the Raku ecosystem. The depends, build-depends, and test-depends sections include different modules that are used in those phases of the of installation. All are optional, but they must obviously contain the modules that are going to be needed in those particular phases.
For the benefit of others who may have the same question, I'll expand on the correct answer you already got in a comment from @ugexe:
You can get print the full package path by printing the debug representation of $*PACKAGE
with the .raku method or (on Rakudo only), with the dd routine.
Thus, your code could be modified to have the output shown below:
dd $?PACKAGE; # OUTPUT: «GLOBAL»
class Foo {
dd $?PACKAGE; # OUTPUT: «Foo»
class Bar {
dd $?PACKAGE; # OUTPUT: «Foo::Bar»
my package P {say $?PACKAGE;} # OUTPUT: «Foo::Bar::P»
}
}
Note that GLOBAL
is implicit and thus isn't printed unless it is the only item in the path.
When you call say
you get .gist
of the argument.
The .gist
is intended to give a human just enough information to figure out what is going on.
If you actually want the name of the package, ask for it.
Or more specifically, ask the metamodel to give it to you with .^name
.
say $?PACKAGE.^name; # GLOBAL
class Foo {
say $?PACKAGE.^name; # Foo
class Bar {
say $?PACKAGE.^name; # Foo::Bar
my package P {
say $?PACKAGE.^name; # Foo::Bar::P
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With