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

more on perl5 modules

7 views
Skip to first unread message

Richard Hainsworth

unread,
Sep 17, 2006, 8:03:39 AM9/17/06
to perl6...@perl.org
The .can workaround doesnt seem to work for more complex modules.

Here is a working perl5 program that puts up a message with two buttons.

use strict;
use Gtk2 -init;
use Gtk2::Ex::Dialogs(destroy_with_parent=>-1, modal=>-1, no_separator
=> 0);
my $window = Gtk2::Window->new('toplevel');
Gtk2::Ex::Dialogs->set_parent_window( $window );
my $r = Gtk2::Ex::Dialogs::Question->ask( "Is Perl only hackers glue?");
if ($r) {print "yes\n";} else {print "no\n";};

Here is an attempt to do the same in perl6

use v6;
use perl5:Gtk2 -init;
say "called Gtk3 init";
my $window = initialise();
say "window initialised";
use perl5:Gtk2::Ex::Dialogs(destroy_with_parent=>-1, modal=>-1,
no_separator => 0);
our &gsetparent := Gtk2::Ex::Dialogs.can('set_parent_window');
say "Now trying to use the window";
gsetparent( $window );
our &ask := Gtk2::Ex::Dialogs::Question.can('ask');
my $r = ask( "Is Perl only hackers glue?");
if ($r) {say "yes";} else {say "no";};

sub initialise () {
# I took this eval(uation) of perl5 by pugs from one of the examples in
the pugs distribution
eval (q!
my $win = Gtk2::Window->new('toplevel');
$win;
!,:lang<perl5>);
};


Here is the output
$ pugs ./gtk2_test.p6
called Gtk3 init
window initialised
Now trying to use the window
Undefined subroutine &main:: called.

I tried a variety of coding techniques. None seems to work.
eg.,
our &gwin := Gtk2::Window.can('new');
our &gwin := Gtk2.can('Window->new');
our &gwin := Gtk2.can('Window.new');

The problem seems to be that Gtk2::Window does not exist as a separate
module, viz., there is no Window.pm in the Gtk2 directory space.

Any ideas?

A. Pagaltzis

unread,
Sep 17, 2006, 5:57:55 PM9/17/06
to perl6...@perl.org
* Richard Hainsworth <ric...@hainsworth.ru> [2006-09-17 18:05]:

> The .can workaround doesnt seem to work for more complex
> modules.

Err, the .can workaround is a way to get past missing sub
exports. Methods are never exported. Why are you using the
workaround for sub exports on methods.

> Here is a working perl5 program that puts up a message with two
> buttons.
>
> use strict;
> use Gtk2 -init;
> use Gtk2::Ex::Dialogs(destroy_with_parent=>-1, modal=>-1, no_separator => 0);
> my $window = Gtk2::Window->new('toplevel');
> Gtk2::Ex::Dialogs->set_parent_window( $window );
> my $r = Gtk2::Ex::Dialogs::Question->ask( "Is Perl only hackers glue?");
> if ($r) {print "yes\n";} else {print "no\n";};

Should be simply:

use perl5:Gtk2 '-init';
use perl5:Gtk2::Ex::Dialogs :destroy_with_parent( -1 ) :modal( -1 ) :!no_separator;
my $window = Gtk2::Window.new( 'toplevel' );
Gtk2::Ex::Dialogs.set_parent_window( $window );
my $r = Gtk2::Ex::Dialogs::Question.ask( "Is Perl only hackers glue?" );
say $r ?? 'yes' !! 'no';

Regards,
--
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;

Richard Hainsworth

unread,
Sep 18, 2006, 9:18:33 AM9/18/06
to A. Pagaltzis, perl6...@perl.org
I copied your neat program into a file, called it gtk2test.p6 and got
pugs gtk2_test.p6
***
unexpected ":"
expecting term postfix, operator, ";" or end of input
at gtk2_test.p6 line 2, column 56

However, I am using pugs from the debian package and not directly from
the repository. So perhaps, the problem is I am not using the latest
version of pugs.

Regards,
Richard

Juerd

unread,
Sep 18, 2006, 9:20:56 AM9/18/06
to perl6...@perl.org
Richard Hainsworth skribis 2006-09-18 17:18 (+0400):

> However, I am using pugs from the debian package and not directly from
> the repository. So perhaps, the problem is I am not using the latest
> version of pugs.

That version is rather old in our universe :)
--
korajn salutojn,

juerd waalboer: perl hacker <ju...@juerd.nl> <http://juerd.nl/sig>
convolution: ict solutions and consultancy <sa...@convolution.nl>

A. Pagaltzis

unread,
Sep 18, 2006, 9:24:17 AM9/18/06
to perl6...@perl.org
* Richard Hainsworth <ric...@rusrating.ru> [2006-09-18 15:20]:

> I copied your neat program into a file, called it gtk2test.p6
> and got
> pugs gtk2_test.p6
> ***
> unexpected ":"
> expecting term postfix, operator, ";" or end of input
> at gtk2_test.p6 line 2, column 56

Note my translation was purely based on what I picked up, and
completely untested. Debug as needed to fix it.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

0 new messages