Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could be the reason that `require` doesn't work in some places?

Tags:

require

raku

Loading a module (ABC) with require works in one module of a distribution while it fails in another module of the distribution. What could be the reason that loading ABC with require fails in one place?

require Name::ABC;
my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC)

perl6 -v
This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.

The the required module: App::DBBrowser::Subqueries

App::DBBrowser::Union, line 80: OK *

App::DBBrowser::Join, lines 66 and 191: OK *

App::DBBrowser::Table::Extensions, line 49: OK *

App::DBBrowser, line 690: You cannot create an instance of this type (Subqueries) *

App::DBBrowser::CreateTable, line 112: You cannot create an instance of this type (Subqueries) *

* version 0.0.1

like image 398
sid_com Avatar asked May 11 '19 10:05

sid_com


1 Answers

$ cat XXX.pm6
unit class XXX;

$ cat ZZZ.pm6
module ZZZ {
    require XXX;
    XXX.new;
    say "OK";
}

$ perl6 -I. -e 'use ZZZ;'
===SORRY!===
You cannot create an instance of this type (XXX)

From the documentation:

require loads a compunit and imports definite symbols at runtime.

You are doing a runtime load of a module while also expecting the symbols for that module to exist at compile time. Instead you should use indirect name lookup (as shown at the bottom of the documentation page linked earlier):

$ cat XXX.pm6
unit class XXX;

$ cat ZZZ.pm6
module ZZZ {
    require XXX;
    ::("XXX").new;
    say "OK";
}

$ perl6 -I. -e 'use ZZZ;'
OK
like image 173
ugexe Avatar answered Oct 02 '22 14:10

ugexe