Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create proxy functions for all functions in an imported P5 module.
This allows for calling package functions using their fully qualified name:
use Test::More:from<Perl5>;
Test::More::ok(1);
Test::More::done_testing;

Method call syntax now does real package method calls:
use Data::Dumper:from<Perl5>;
Data::Dumper.Dump([1]);
  • Loading branch information
niner committed Jan 5, 2015
1 parent 652c83c commit 28b966d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/Inline/Perl5.pm6
Expand Up @@ -520,7 +520,7 @@ class Perl5Package {
}

method FALLBACK($name, *@args) {
%perl5_for_imported_packages{self.perl.Str}.call("{self.perl.Str}::$name", @args.list);
%perl5_for_imported_packages{self.perl.Str}.invoke(self.perl.Str, $name, @args.list);
}
}

Expand All @@ -535,6 +535,12 @@ method require(Str $module) {
self.invoke($module, 'import', @args.list);
return EnumMap.new();
};
my $symbols = self.run('[ grep { *{"' ~ $module ~ '::$_"}{CODE} } keys %' ~ $module ~ ':: ]');
for @$symbols -> $name {
::($module).WHO{"&$name"} := sub (*@args) {
self.call("{$module}::$name", @args.list);
}
}

%perl5_for_imported_packages{$module} = self;
}
Expand Down
2 changes: 1 addition & 1 deletion t/from.t
Expand Up @@ -5,6 +5,6 @@ use Inline::Perl5;

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

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

# vim: ft=perl6
9 changes: 5 additions & 4 deletions t/use.t
Expand Up @@ -6,16 +6,17 @@ use Inline::Perl5;
my $p5;
BEGIN {
$p5 = Inline::Perl5.new();
$p5.use('Test::More', 'tests', 3);
$p5.call('Test::More::ok', 1);
$p5.use('Test::More', 'tests', 4);
$p5.call('Test::More::ok', 1, 'use loaded the module');
}

BEGIN {
Test::More.ok(1);
Test::More::ok(1, 'package functions work');
$p5.use('Data::Dumper');
}

my $dumper = Data::Dumper.new([1, 2]);
Test::More.is($dumper.Dump.Str, "\$VAR1 = 1;\n \$VAR2 = 2;\n");
Test::More::is($dumper.Dump.Str, "\$VAR1 = 1;\n \$VAR2 = 2;\n", 'constructor works');
Test::More::is(Data::Dumper.Dump([1, 2]).Str, "\$VAR1 = 1;\n \$VAR2 = 2;\n", 'package methods work');

# vim: ft=perl6

0 comments on commit 28b966d

Please sign in to comment.