Skip to content

Commit

Permalink
Support import lists when loading P5 modules via use Foo:from<Perl5>
Browse files Browse the repository at this point in the history
Allows for:
use Test::More:from<Perl5> <tests 1>;
  • Loading branch information
niner committed Jan 4, 2015
1 parent 3c10ff3 commit 652c83c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/Inline/Perl5.pm6
Expand Up @@ -524,16 +524,26 @@ class Perl5Package {
}
}

method use(Str $module, *@args) {
method require(Str $module) {
my $module_sv = self.p6_to_p5($module);
p5_use($!p5, $module_sv);
self.invoke($module, 'import', @args.list);

EVAL "class GLOBAL::$module is Perl5Package \{ \}";

::($module).WHO<EXPORT> := Metamodel::PackageHOW.new();
::($module).WHO<&EXPORT> := sub EXPORT(*@args) {
self.invoke($module, 'import', @args.list);
return EnumMap.new();
};

%perl5_for_imported_packages{$module} = self;
}

method use(Str $module, *@args) {
self.require($module);
self.invoke($module, 'import', @args.list);
}

submethod DESTROY {
p5_destruct_perl($!p5) if $!p5;
$!p5 = Perl5Interpreter;
Expand Down Expand Up @@ -628,7 +638,7 @@ BEGIN {
class Perl5ModuleLoader {
method load_module($module_name, %opts, *@GLOBALish, :$line, :$file) {
$default_perl5 //= Inline::Perl5.new();
$default_perl5.use($module_name);
$default_perl5.require($module_name);

return ::($module_name).WHO;
}
Expand Down
3 changes: 1 addition & 2 deletions t/from.t
Expand Up @@ -3,9 +3,8 @@
use v6;
use Inline::Perl5;

use Test::More:from<Perl5>;
use Test::More:from<Perl5> <tests 1>;

Test::More.ok(1);
Test::More.done_testing;

# vim: ft=perl6

0 comments on commit 652c83c

Please sign in to comment.