Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embedded perl5 modules

12 views
Skip to first unread message

Richard Hainsworth

unread,
Oct 20, 2006, 7:03:12 AM10/20/06
to perl6...@perl.org
Upgraded to pugs 6.13 after seeing "comprehensive support for
interoperability with Perl 5 modules".

I want to test gui modules and I am trying the Gtk2 and Wx modules.

The following program works under perl5:
use strict;
use Wx;
my $app = Wx::SimpleApp->new;
my $frame=Wx::Frame->new(undef, -1, 'Hello world!');
$frame->Show;
$app->MainLoop;

The program places a window on the desktop with "Hello world!" as the title.

I naively modified to perl6 (wxtest.p6) as follows:
use perl5:Wx;
my $app = Wx::SimpleApp.new;
my $frame=Wx::Frame.new(undef, -1, 'Hello world!');
$frame.Show;
$app.MainLoop;

The following is the result:
$pugs wxtest.p6
*** No compatible subroutine found: "&Wx::SimpleApp"
at wxtest.p6 line 2, column 1-28

Is the perl6 wrong?

I have also tested
use perl5:Wx <SimpleApp>;

Richard

Steffen Schwigon

unread,
Oct 20, 2006, 7:38:16 AM10/20/06
to perl6...@perl.org
Richard Hainsworth <ric...@rusrating.ru> writes:
> use perl5:Wx;
> my $app = Wx::SimpleApp.new;
> my $frame=Wx::Frame.new(undef, -1, 'Hello world!');
> $frame.Show;
> $app.MainLoop;
>
> The following is the result:
> $pugs wxtest.p6
> *** No compatible subroutine found: "&Wx::SimpleApp"
> at wxtest.p6 line 2, column 1-28
>
> Is the perl6 wrong?
>
> I have also tested
> use perl5:Wx <SimpleApp>;

Maybe an additional

use perl5:Wx::SimpleApp;

? I'm just guessing...

Steffen
--
Steffen Schwigon <schw...@webit.de>
Dresden Perl Mongers <http://dresden-pm.org/>

Steffen Schwigon

unread,
Oct 22, 2006, 3:16:39 PM10/22/06
to perl6...@perl.org
Steffen Schwigon <schw...@webit.de> writes:
> Richard Hainsworth <ric...@rusrating.ru> writes:
>> use perl5:Wx;
>> my $app = Wx::SimpleApp.new;
>> my $frame=Wx::Frame.new(undef, -1, 'Hello world!');
>> $frame.Show;
>> $app.MainLoop;
>>
>> The following is the result:
>> $pugs wxtest.p6
>> *** No compatible subroutine found: "&Wx::SimpleApp"
>> at wxtest.p6 line 2, column 1-28
>>
>> Is the perl6 wrong?
>>
>> I have also tested
>> use perl5:Wx <SimpleApp>;
>
> Maybe an additional
>
> use perl5:Wx::SimpleApp;
>
> ? I'm just guessing...

Hm. Generally I have much more success using Perl5 modules with Pugs
6.2.13. But maybe Wx is a bit harder. I tried to trick it with an
additional Perl5 helper to not use the indirect namespaces, like this:

WxHelper.pm (Perl5):

package WxHelper;
use Wx;
sub new_SimpleApp {
return Wx::SimpleApp->new(@_);
}
sub new_Frame {
return Wx::Frame->new(@_);
}
1;


This adapted to your little program (Perl6):

#! /usr/bin/pugs
use perl5:Wx;
use perl5:WxHelper;
my $app = WxHelper.new_SimpleApp;
my $frame = WxHelper.new_Frame(undef, -1, 'Hello world!');
$frame.Show;
$app.MainLoop;

But now I get

sub must be a CODE reference at /usr/local/lib/perl/5.8.7/Wx/App.pm line 36.


I don't know Wx, maybe you have an idea for this, e.g. another way to
start a mini application.

BTW, I tried it on Linux with GTK bindings.

GreetinX

Richard Hainsworth

unread,
Oct 22, 2006, 10:09:26 AM10/22/06
to perl6...@perl.org
>Steffen said:
>Maybe an additional

> use perl5:Wx::SimpleApp;

> ? I'm just guessing...

> Steffen
>--
>Steffen Schwigon <schwi...
<http://groups.google.com/groups/unlock?msg=5db1a47bed78a20d&_done=/group/perl.perl6.users/browse_frm/thread/4c85d7fedf76dd11/6ec62de446f6ea38%3F>@webit.de>

>Dresden Perl Mongers <http://dresden-pm.org/>

Tried it. Doesnt work. Just gives the following error:
*Error eval perl5: "require Wx::SimpleApp; 'Wx::SimpleApp'"
*** Can't locate Wx/SimpleApp.pm in @INC (@INC contains: /etc/perl <rest
snipped>

*However, surely a perl6 program using a perl5 module should not require
a more complex calling structure/approach than the equivalent perl5 module.

Hence if
use Wx;
is sufficient for a perl5 program to find Wx::SimpleApp and Wx::Frame
packages (namespaces), then
use perl5:Wx;
should be sufficient for a perl6 program.

No??

Richard

Steffen Schwigon

unread,
Oct 23, 2006, 3:30:34 AM10/23/06
to perl6...@perl.org
Richard Hainsworth <ric...@hainsworth.ru> writes:
>>Steffen said:
>>Maybe an additional
>> use perl5:Wx::SimpleApp;
> Tried it. Doesnt work.

In the meantime I tried my guess and also had to learn that. See also
my experiments in my other answer.


> *However, surely a perl6 program using a perl5 module should not
> require a more complex calling structure/approach than the
> equivalent perl5 module.
>
> Hence if
> use Wx;
> is sufficient for a perl5 program to find Wx::SimpleApp and Wx::Frame
> packages (namespaces), then
> use perl5:Wx;
> should be sufficient for a perl6 program.
>
> No??

Of course you are right ... in a finished perfect world. But currently
we have not yet arrived. Therefore I deduced my guess from the known
issues with using Perl5-from-Perl6 regarding export/import.

And when you write "use Wx;" and get all other packages "en passant",
then Wx does some of that Exporter stuff. So Wx is a maybe a rather
hard test for Perl5 integration.

Did you have success using other Perl5 modules?

I'm not sure about your target. If you want to learn Perl5
integration, maybe try something easier first.

If you explicitly just need it with Wx, then maybe you still have to
wait some time or find someone from the Pugs coders who might help.

Maybe we should write a little test in the Pugs repository for that
behaviour. Without Wx but with that indirect package export/import
that Wx does. I'm just not sure where it belongs. Maybe near
t/perl5/import.t --> go for it, if you dare. :-)


Steffen
--
Steffen Schwigon <schw...@webit.de>

Richard Hainsworth

unread,
Oct 25, 2006, 1:27:14 AM10/25/06
to perl6...@perl.org
Tried
use perl5:Wx::SimpleApp;
but the compiler complained it could not find SimpleApp.pm

GUI packages, which are wrappers around C classes, seem to use all the
techniques of perl5. I dont understand them to find out what is going
on, or to isolate what the error so as to put it into a test.

In general, it seems to me that for there to be "full" use of perl5
modules in perl6, the useage in perl6 should be the same as in perl5
(bar the minor changes in syntax). Thus if
use Wx;
is sufficient in perl5 for Wx::SimpleApp to be a recognised namespace in
the program and for the compiler to know where to go to get
Wx::SimpleApp->new, then in perl6 the same should be true, viz.,
use perl5:Wx;
Wx::SimpleApp.new

Regards,

Richard

Steffen Schwigon

unread,
Oct 25, 2006, 2:39:05 AM10/25/06
to perl6...@perl.org
Richard Hainsworth <ric...@rusrating.ru> writes:
> Tried
> use perl5:Wx::SimpleApp;
> but the compiler complained it could not find SimpleApp.pm

Did you see my other suggestion with an intermediate "WxHelper"
(http://www.nntp.perl.org/group/perl.perl6.users/546)?

It also doesn't really work but at least it gets you a step
further. Try it and maybe you have the next idea as you maybe
know Wx better than I do.

Steffen
--
Steffen Schwigon <schw...@webit.de>
Dresden Perl Mongers <http://dresden-pm.org/>

Deutscher Perl-Workshop <http://www.perl-workshop.de/>

Richard Hainsworth

unread,
Oct 28, 2006, 4:04:08 PM10/28/06
to perl6...@perl.org
Steffen: Sorry, Didnt see all correspondence immediately, and hence
responded twice.

But here is an effort using Gtk2. It works.
Can anyone explain why the lines with .can, whilst the other syntaxes
dont work?

<file Gtk2Helper.pm>
package Gtk2Helper;
use Gtk2;
sub new_Window {
return Gtk2::Window->new(@_);
};
sub new_Button {
return Gtk2::Button->new(@_);
};
1;
<end file>
<file Gtk2_test.p6>
use perl5:Gtk2;
use perl5:Gtk2Helper;

Gtk2.init;

#This does not work
#my $window = Gtk2Helper.new_Window('toplevel');
#This does not work
#my $window = Gtk2Helper::new_Window('toplevel');

# The following works
my &nw := Gtk2Helper.can('new_Window');
my $window = nw('toplevel');

my &nb := Gtk2Helper.can('new_Button');
my $button = nb('Quit this dull mortal world');
$button.signal_connect('clicked', sub { Gtk2.main_quit });
$window.add($button);
$window.show_all;
Gtk2.main;

Richard

0 new messages