Skip to content

Commit

Permalink
Create lexical stub package for nested required module.
Browse files Browse the repository at this point in the history
require Foo::Bar; will now create a lexically scoped package "Foo" containing
the nested stub package "Bar" to be replaced by the loaded module's package
at runtime.
With this, "require Foo::Bar; Foo::Bar::baz();" works again.
  • Loading branch information
niner committed Mar 6, 2017
1 parent 3e86d0f commit 5b98caa
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/Perl6/Actions.nqp
Expand Up @@ -1928,16 +1928,27 @@ class Perl6::Actions is HLL::Actions does STDActions {
$compunit_past,
),'require');
if $target_package && !$longname.contains_indirect_lookup() {
my $stub := $*W.pkg_create_mo($/, %*HOW<package>, :name($longname.name));
$*W.pkg_compose($/, $stub);
my $stubvar := QAST::Var.new(
:name($longname.name),
:scope('lexical'),
:decl('var'),
);
$lexpad[0].unshift($stubvar);
$lexpad.symbol($longname.name, :scope('lexical'), :value($stub));
$require_past.push($target_package);
my $first := 1;
my $current;
for $longname.components -> $component {
my $stub := $*W.pkg_create_mo($/, %*HOW<package>, :name($component));
$*W.pkg_compose($/, $stub);
if $first {
my $stubvar := QAST::Var.new(
:name($component),
:scope('lexical'),
:decl('var'),
);
$lexpad[0].unshift($stubvar);
$lexpad.symbol($component, :scope('lexical'), :value($stub));
$require_past.push(QAST::SVal.new(:value($component)));
$first := 0;
}
else {
nqp::who($current){$component} := $stub;
}
$current := $stub;
}
}
else {
$require_past.push($*W.symbol_lookup(['Any'], $/));
Expand Down

0 comments on commit 5b98caa

Please sign in to comment.