From 913a47a1d9b602872942dff28fd7f27b4de0a8db Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 16 Apr 2015 12:10:42 +0200 Subject: [PATCH] Prevent inherited Any methods from interfering with calls to P5 methods 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. --- lib/Inline/Perl5.pm6 | 9 +++++++++ t/invoke.t | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 t/invoke.t diff --git a/lib/Inline/Perl5.pm6 b/lib/Inline/Perl5.pm6 index fae040a..bedabc8 100644 --- a/lib/Inline/Perl5.pm6 +++ b/lib/Inline/Perl5.pm6 @@ -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 { diff --git a/t/invoke.t b/t/invoke.t new file mode 100644 index 0000000..2122af8 --- /dev/null +++ b/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;