holli has asked for the wisdom of the Perl Monks concerning the following question:

I want to write a wxWidgets application in Perl 6. So I have a minimal Perl5 example that works and try to convert that to Perl 6
Perl5
package YTDL::App; use YTDL::Frame; use base qw(Wx::App); use strict; sub OnInit { say "***"; return 1; } 1;
Perl 6
use Wx:from<Perl5>; use Wx::App:from<Perl5>; class YTDL::App is Wx::App { sub OnInit { say "***"; return True; } }
It sure looks right. However, the Perl 6 version complains about OnInit not returning true and the method OnInit is not called.
I don't know how to fix this.


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re: [Perl6] Problem using Inline::Perl5
by raiph (Deacon) on Dec 18, 2016 at 02:40 UTC
    the method OnInit is not called

    Try changing the declarator `sub` to `method`:

    class YTDL::App is Wx::App { method OnInit { say "***"; return True; } }

    If that doesn't fix things, or if you have other questions, the freenode #perl6 IRC channel is currently by far the best place to go for talking through any problems you're having while working with anything to do with Perl 6.

      I tried that already. No dice.


      holli

      You can lead your users to water, but alas, you cannot drown them.
Re: [Perl6] Problem using Inline::Perl5 (Wx)
by beech (Parson) on Dec 17, 2016 at 22:56 UTC

    Hi,

    So the perl6 version is loading the perl5 module?

    How does perl6 tell perl5 about classes created in perl6 ?

    Try this , it makes no classes ;)

    use Wx qw/ :allclasses /; my $app=Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef,-1,"Sand!" ); $frame->Show; $app->MainLoop;

      Perl 6 has Perl5::Inline, so you can run Perl 5 code under Perl 6 and get full inheritance both ways. Or so nine's talk says.

      I tried that too
      use Wx:from<Perl5>; my $app = Wx::SimpleApp.new; my $frame = Wx::Frame.new( Nil, -1, 'Hello, world!' ); $frame.Show; $app.MainLoop;
      fails complaining about the symbol "SimpleApp" not being known.


      holli

      You can lead your users to water, but alas, you cannot drown them.

        Hi,

        Does the perl5 program run from perl5?

        If so, then it sounds like a bug in Inline::Perl5 to me :)

        Also, the two programs arent exactly equivalent, missing  Wx.import(':allclasses'); or some such

        update: odd, saw no docs the other day at https://github.com/niner/Inline-Perl5 , this would be equivalent  use Wx:from<Perl5> <:allclasses>; so the new program

        use Wx:from<Perl5> <:allclasses>; use Wx::SimpleApp:from<Perl5>; use Wx::Frame:from<Perl5>; my $app = Wx::SimpleApp.new; my $frame = Wx::Frame.new( Nil, -1, 'Hello, world!' ); $frame.Show; $app.MainLoop;