I have been looking in Rakudo source for the implementation of require
, first out of curiosity and second because I wanted to know if it was returning something.
I looked up sub require
and it returned this hit, which actually seems to be the source for require, but it's called sub REQUIRE_IMPORT
. It returns Nil
and is declared as such, which pretty much answers my original question. But now my question is: Where's the mapping from that sub to require
? Is it really the implementation for that function? Are there some other functions that are declared that way?
require
is not a sub, but rather a statement control (so, in the same category of things like use
, if
, for
, etc.) It is parsed by the Perl 6 grammar and there are a few different cases that are accepted. It is compiled in the Perl 6 actions, which has quite a bit to handle.
Much of the work is delegated to the various CompUnit
objects, which are also involved with use
/need
. It also has to take care of stubbing symbols that the require
will bring in, since the set of symbols in a given lexical scope is fixed at compile time, and the REQUIRE_IMPORT
utility sub is involved with the runtime symbol import too.
The answer to your question as to what it will evaluate to comes at the end of the method:
$past.push($<module_name>
?? self.make_indirect_lookup($longname.components())
!! $<file>.ast);
Which means:
require Some::Module
then evaluate to a lookup of Some::Module
require $file
style case, evaluate to the filenameIf 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