What does the keyword 'unit' do before the package name?

In the following code:

unit module Fancy::Calculator;

what does the “unit” actually do? I know that the module definition area becomes the file in which it is declared, unlike;

module Fancy::Calculator {
    # module definition statements here
}

where the scope is defined by cursors, but I don’t see anything in the documentation that finally states that this is all that it does, and I would be a little surprised if all that he did. Secondly, after creating such an declaration, you can declare unit class Whatever(class, module, whatever) halfway down and cause the end of the previous definition of the area?

+4
source share
1 answer

( ), , , . - - ;

===SORRY!=== Error while compiling /home/user/Fancy/Calculator.pm6
Too late for unit-scoped module definition;
Please use the block form.

... , , , , , - Fancy:: Calculator . , :

unit module Fancy::Calculator;

# The following available to the module user as Fancy::Calculator::Adder
class Adder {
    method add { "Hi... I am a method who can add" }
}

# Starting definition of new module but its within Fancy::Calculator namespace
module Minus {

    # Following available to the module user as Fancy::Calculator::Minus::Subber
    class Subber {
        method subtract { "Hi... I am a method who can subtract" }
    }

    # unless you add "is export" in which case its available by its short name
    class Multiplyer is export {
        method times { "Hi... I am a method who can multiply" }
    }

    sub divide() is export { "Hi... I am a sub who can divide" }
}

:

# In main
use Fancy::Calculator;

my $fca = Fancy::Calculator::Adder.new;
say $fca.add;              # Hi... I am a method who can add
my $fcms = Fancy::Calculator::Minus::Subber.new;
say $fcms.subtract;        # Hi... I am a method who can subtract
my $mul = Multiplyer.new;
say $mul.times;            # Hi... I am a sub who can multiply
say divide();              # Hi... I am a sub who can divide
+2

All Articles