Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a module subroutine using a fully qualified name

Tags:

module

raku

I created a simple test module ./mods/My/Module.pm6:

unit module My::Module;
use v6;

sub hello () is export {
    say "Hello";
}

Then, I have a test script ./p.p6:

#! /usr/bin/env perl6

use v6;
use My::Module;

My::Module::hello();

Then I set PERL6LIB to include the folder ./mods, and then run the script:

$ ./p.p6 
Could not find symbol '&hello'
  in block <unit> at ./p.p6 line 7

However, if I replace the line My::Module::hello() in the script with hello() it works fine. What am I missing here?

like image 696
Håkon Hægland Avatar asked Nov 09 '17 08:11

Håkon Hægland


1 Answers

If you export hello you can simply use it

use v6;
use lib <lib>; # hint: no need to tinker with the environment
use My::Module;

hello();

If you really WANT to use a fully qualified name, you have to use the our keyword.

our sub hello () is export {
    say "Hello";
}
like image 86
Holli Avatar answered Oct 13 '22 08:10

Holli