Skip to content

Commit

Permalink
Prevent inherited Any methods from interfering with calls to P5 methods
Browse files Browse the repository at this point in the history
Perl5Object inherits methods like "push" and "list" from Any. This
prevents the fallback that passes calls to such methods to the wrapped
P5 object from kicking in. Work around that by explicitly adding wrapper
methods.

Thanks to lizmat++ for giving the inspiration.
  • Loading branch information
niner committed Apr 16, 2015
1 parent e939cf1 commit 913a47a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Inline/Perl5.pm6
Expand Up @@ -736,6 +736,15 @@ BEGIN {
}
}
);
for Any.^methods>>.gist -> $name {
Perl5Object.^add_method(
$name,
method (|args) {
$.perl5.invoke($.ptr, $name, self, args.list, args.hash);
}
);
}
Perl5Object.^compose;
}

class Perl5ModuleLoader {
Expand Down
25 changes: 25 additions & 0 deletions t/invoke.t
@@ -0,0 +1,25 @@
#!/usr/bin/env perl6

use v6;
use Inline::Perl5;
use Test;

my $p5 = Inline::Perl5.new;

$p5.run: q:heredoc/PERL5/;
package Foo;
sub new {
return bless {};
}
sub push {
return 'pushed';
}
PERL5

my $foo = $p5.invoke('Foo', 'new');

is($foo.push, 'pushed');

done;

0 comments on commit 913a47a

Please sign in to comment.