Skip to content

Instantly share code, notes, and snippets.

@barcharcraz
Last active October 10, 2018 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barcharcraz/0e0ba8f64b86544856e156ee1573fe1c to your computer and use it in GitHub Desktop.
Save barcharcraz/0e0ba8f64b86544856e156ee1573fe1c to your computer and use it in GitHub Desktop.
# file Base.pm6
use v6;
unit module Base;
use Base::Test;
# file Base/Test.pm6
use v6;
unit module Base;
our sub foo { say "foo"; }
# repl
> use Base;
> Base::foo;
Could not find symbol '&foo'
@b2gills
Copy link

b2gills commented Oct 10, 2018

Those are two separate modules with the same name.

Perl 6 does not have the same simple namespace that Perl 5 has.

Example/A.pm6

unit module Example;
sub foo () { say 'Alpha' }

Example/B.pm6

unit module Example;
sub foo () { say 'Beta' }
{
  use Example::A;
  Example::foo();
}
{
  use Example::B;
  Example::foo();
}

That prints:

Alpha
Beta

You can do the following though:

Base.pm6

use v6;
unit module Base;
use Base::Test;

our &foo = &Base::Test::foo;

Base/Test.pm6

use v6;
unit module Base::Test;

our sub foo { say "foo"; }

REPL

> use Base;
> Base::foo;
foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment